# Tabelles

Canonical URL: https://developers.iagenify.com/pt/sdk/ref/connected-storage/run/tables/
Language: pt

`storage.run({ action: "tables" })`

Cada tabèla in una base di dati relazionale, con le sue colonne, i loro tipi, e qual è la chiave.

Status: relational database · free · no row counts

```javascript
await storage.run({ action: "tables" });
// [
//   { name: "users", columns: [
//       { name: "id",    type: "INTEGER", primaryKey: true },
//       { name: "email", type: "TEXT" },
//       { name: "created_at", type: "TEXT" } ] }
// ]
```

## Nessuna conta di fila, deliberat {#counts}

> **A COUNT è cobrata dalla fila a alguns prestatori**
>
> Contando ogni tabù per mostrar quanta grandetèt puè costar mès de la consulta che stavi per executare. Se necessites un conte, pede per la tabùla que te importa.

```javascript
await storage.run({ action: "execute", sql: "SELECT COUNT(*) AS n FROM users" });
```

## Tavole internes sono oltra {#internal}

Le tabèle contabilizion del provider sono filtrate, quindi il chen retorna è quello che create. Una tabèla che fate e non veds significa che si connexe a una base di dadi diferente.

## Scrivendo una dichiarazione da essa {#use}

```javascript
const tables = await storage.run({ action: "tables" });

const users = tables.find((t) => t.name === "users");
const key = users.columns.find((c) => c.primaryKey)?.name ?? "rowid";
const cols = users.columns.map((c) => c.name).join(", ");

await storage.run({ action: "execute",
  sql: `SELECT ${cols} FROM users ORDER BY ${key} DESC LIMIT 20` });
```

Conoscendo le materie chiave al dispersò: una tabelà sin una non puère ser updated fila per fila con ningun confidència, dalquan ningun nomi di una fila.

- [executar](/pt/sdk/ref/connected-storage/run/execute): Executor una instruzione.
- [Panorama general](/pt/sdk/ref/connected-storage/run/overview): Les tables plus une ligne d'exemple, en un appel.
- [run()](/pt/sdk/ref/connected-storage/run): Tutes les actions, les garde-fous et ce que chaque coute.

```python
storage.run(action="tables")
# [
#   {"name": "users", "columns": [
#       {"name": "id",    "type": "INTEGER", "primaryKey": True},
#       {"name": "email", "type": "TEXT"},
#       {"name": "created_at", "type": "TEXT"}]}
# ]
```

```python
storage.run(action="execute", sql="SELECT COUNT(*) AS n FROM users")
```

```python
tables = storage.run(action="tables")

users = next(t for t in tables if t["name"] == "users")
key = next((c["name"] for c in users["columns"] if c.get("primaryKey")), "rowid")
cols = ", ".join(c["name"] for c in users["columns"])

storage.run(action="execute", sql=f"SELECT {cols} FROM users ORDER BY {key} DESC LIMIT 20")
```
