运行 读读

表表表表表格

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

每个表格都包含相关数据库, 包括各栏、类型,

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"}]}
# ]

故意不列计数

A A A COUNT 由某些提供者的行加载

计算每个表格以显示它有多大, 成本会比您要运行的查询要高。 如果您需要计算, 请询问您关心的表格 。

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

内部表格被遗漏

供应商自己的簿记表被过滤, 所以返回的东西就是你创建的。 您制作的无法看见的表格 意味着您连接到不同的数据库 。

撰写声明

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")

了解除顺序以外的关键事项:没有顺序的表格不能一行一行地更新,因为没有单行的名字。