获取 API 密钥
运行 $ 写

创建集合

storage.run({ action: "createCollection", collection })

创建空收藏。 需要的非常少 — 写入名称创建它, 但当结构是点时却明确了 。

document databasefreerefuses a duplicate
Using Python?

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

await storage.run({ action: "createCollection", collection: "invoices" });
// { ok: true, created: "invoices" }
storage.run(action="createCollection", collection="invoices")
# {"ok": True, "created": "invoices"}

当你真正需要的时候

A 音 A 插入插入 将没有收藏的收藏创建为名称。 因此, 这是对于在写入任何文件之前必须存在结构的案例来说 : 设置步骤、 迁移、 界面, 将收藏的收藏在数据出现之前列出 。

拒绝拒绝现有名称, 并附有可读信件

拒绝声明收藏已经存在

而不是数据库自己的代码, 数据库的代码给出了一个条件, 而不说明该怎么做。 如果创建两次对您无害, 请将拒绝视为成功 。

async function ensureCollection(storage, collection) {
  const existing = await storage.run({ action: "collections" });
  if (existing.some((c) => c.name === collection)) return "already there";
  await storage.run({ action: "createCollection", collection });
  return "created";
}
def ensure_collection(storage, collection):
    existing = storage.run(action="collections")
    if any(c["name"] == collection for c in existing):
        return "already there"
    storage.run(action="createCollection", collection=collection)
    return "created"

这是写作,是被要求的

结构变化与数据结构结构的允许类别相同——在创建收藏之前,在每种模式下,只要最开放,都先询问一个代理。 储存类别.