就是这样 api.storage.create(), connect(), device(), get() 和 list() 全部手背。 你从不构建一个。 原因是它是一个单一类型, 整个资源点: 读取我们主机数据库的代码 读取你连接的代码 。
表面表面
| 成员 | 日期 日期 | 功能 |
|---|---|---|
| 运行( 配置) | 每个储存 | 阅读和写数据。 |
| 文件 文件 | 计算机 | 那机器是自己的档案 |
| 终端终端 | 计算机 | 贝壳和服务器 寿命超过答案 |
随它携带的
idstring识别资料, 传递给 storageId 任何人被要求的,无论在哪里。
labelstring显示名称。 账户持有人可以更改它, 所以不能匹配它 。
typestringfilesystem · phone · browser · database · object. 字段到分支上。
providerstring其背后的是什么呢? mongodb, d1, r2, s3, iagenify, machine, browser.
managedBystring谁操作它。
servicestring|nullnosql · sql · object 在一个 IaGenify 云层储存。 null 否则。
isDefaultboolean是否保存, 且此处没有目标位置 。
machineId · hostnamestring|null电脑上: 哪个机器?
deviceIdstring|null手机上: 浏览器保存的识别码 。
limitsobject存储轨道是什么 自己的空间。
lastActivityAt · createdAtstring|null上次使用时,登记时,
您提供的连接设备被服务器用于连接, 并且从未被发回。 这里没有任何东西可以通过登录或发送到页面来泄露密码 。
业务处在类型上,而不是在供应商上
provider 仓库后面的东西,你应当告诉你; type 第二,你的代码应该测试什么
for (const storage of await api.storage.list()) {
switch (storage.type) {
case "database":
await storage.run({ action: "collections" });
break;
case "object":
await storage.run({ action: "list" });
break;
case "filesystem":
await storage.files.list(); // this machine's own files
break;
case "phone":
case "browser":
// Its files are in its browser — reachable from the page, not from here.
break;
}
}for storage in api.storage.list():
if storage.type == "database":
storage.run(action="collections")
elif storage.type == "object":
storage.run(action="list")
elif storage.type == "filesystem":
storage.files.list() # this machine's own files
elif storage.type in ("phone", "browser"):
pass # Its files are in its browser — reachable from the page, not from here.设备是一个存储器, 保存自己的字节
| 类型类型类型 | 其数据生命 | run() | 文件 文件 |
|---|---|---|---|
| 数据库 目标 | 账户中 | 否 是 | 无 无 |
| 文件系统 | 在那台机器上 | 当地的答复 | 是——在那台机器上 |
| 电话 浏览器 | 浏览器 | 当地的答复 | 看不到——看桥 |
任何非电脑的, 查找文件 都会 产生文件 storage_not_local - - 或 storage_is_phone 手机上, 上面写着文件实际上在哪里。 先测试类型; 空结果就是谎言 。
import { IaGenifyError } from "iagenify";
try {
await storage.files.list();
} catch (err) {
if (err instanceof IaGenifyError && err.code === "storage_not_local") {
// Not a computer. Its data is read through run().
}
}# In Python, files is None on anything that is not a computer:
# its data is read through run().
if storage.files is None:
storage.run(action="collections")
else:
storage.files.list()同一物体,不论来自何地
const ours = await api.storage.create({ service: "nosql", label: "App data" });
const yours = await api.storage.connect({ label: "Prod", type: "database", provider: "mongodb",
endpoint: { credentials: { uri } } });
// Identical calls, different backends
for (const base of [ours, yours]) {
await base.run({ action: "count", collection: "events" });
}ours = api.storage.create(service="nosql", label="App data")
yours = api.storage.connect(label="Prod", type="database", provider="mongodb",
endpoint={"credentials": {"uri": uri}})
# Identical calls, different backends
for base in (ours, yours):
base.run(action="count", collection="events")