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"这是写作,是被要求的
结构变化与数据结构结构的允许类别相同——在创建收藏之前,在每种模式下,只要最开放,都先询问一个代理。 储存类别.