# 概览

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/connected-storage/
Language: zh

每种存储都有一个对象。 数据通过运行读写 () ; 计算机可获得两个额外的文件 和自己的外壳 。

Status: run() everywhere · files and terminals on a computer only

就是这样 `api.storage.create()`, `connect()`, `device()`, `get()` 和 `list()` 全部手背。 你从不构建一个。 原因是它是一个单一类型, 整个资源点: 读取我们主机数据库的代码 读取你连接的代码 。

## 表面表面 {#surface}

| 成员 | 日期 日期 | 功能 |
| --- | --- | --- |
| 运行( 配置) | 每个储存 | 阅读和写数据。 |
| 文件 文件 | 计算机 | 那机器是自己的档案 |
| 终端终端 | 计算机 | 贝壳和服务器 寿命超过答案 |

## 随它携带的 {#properties}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string |  | 识别资料, 传递给 `storageId` 任何人被要求的,无论在哪里。 |
| `label` | string |  | 显示名称。 账户持有人可以更改它, 所以不能匹配它 。 |
| `type` | string |  | `filesystem` · `phone` · `browser` · `database` · `object`. **字段到分支上。** |
| `provider` | string |  | 其背后的是什么呢? `mongodb`, `d1`, `r2`, `s3`, `iagenify`, `machine`, `browser`. |
| `managedBy` | string |  | 谁操作它。 |
| `service` | string|null |  | `nosql` · `sql` · `object` 在一个 IaGenify 云层储存。 `null` 否则。 |
| `isDefault` | boolean |  | 是否保存, 且此处没有目标位置 。 |
| `machineId · hostname` | string|null |  | 电脑上: 哪个机器? |
| `deviceId` | string|null |  | 手机上: 浏览器保存的识别码 。 |
| `limits` | object |  | 存储轨道是什么 自己的空间。 |
| `lastActivityAt · createdAt` | string|null |  | 上次使用时,登记时, |

> **此对象上无证书**
>
> 您提供的连接设备被服务器用于连接, 并且从未被发回。 这里没有任何东西可以通过登录或发送到页面来泄露密码 。

## 业务处在类型上,而不是在供应商上 {#branch}

`provider` 仓库后面的东西,你应当告诉你; `type` 第二,你的代码应该测试什么

```javascript
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;
  }
}
```

## 设备是一个存储器, 保存自己的字节 {#devices}

| 类型类型类型 | 其数据生命 | run() | 文件 文件 |
| --- | --- | --- | --- |
| 数据库 目标 | 账户中 | 否 是 | 无 无 |
| 文件系统 | 在那台机器上 | 当地的答复 | 是——在那台机器上 |
| 电话 浏览器 | 浏览器 | 当地的答复 | 看不到——看桥 |

> **丢弃而不是返回空的文件和终端文件**
>
> 任何非电脑的, 查找文件 都会 产生文件 storage_not_local - - 或 storage_is_phone 手机上, 上面写着文件实际上在哪里。 先测试类型; 空结果就是谎言 。

```javascript
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().
  }
}
```

## 同一物体,不论来自何地 {#same}

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

- [run()](/zh/sdk/ref/connected-storage/run): 每一个行动,每个行动,每个行动,它的成本。
- [文件 文件](/zh/sdk/ref/connected-storage/files): 电脑的档案 在那台机器上
- [api.storage](/zh/sdk/ref/storage): 6种方法可以买到其中一种

```python
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.
```

```python
# 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()
```

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