run · let

Tabelles

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

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

relational databasefreeno row counts
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

await storage.run({ action: "tables" });
// [
//   { name: "users", columns: [
//       { name: "id",    type: "INTEGER", primaryKey: true },
//       { name: "email", type: "TEXT" },
//       { name: "created_at", type: "TEXT" } ] }
// ]
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

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.

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

Tavole internes sono oltra

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

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` });
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")

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.