# Overview

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

One object for every kind of storage. Data is read and written through run(); a computer gets two extras its own files and its own shells.

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

This is what `api.storage.create()`, `connect()`, `device()`, `get()` and `list()` all hand back. You never construct one. The reason it is a single type is the point of the whole resource: the code that reads a database we host is the code that reads one you connected.

## The surface {#surface}

| Member | On | Does |
| --- | --- | --- |
| run(config) | every storage | Reads and writes the data. |
| files | a computer only | That machine's own files. |
| terminals | a computer only | Shells and servers that outlive an answer. |

## What it carries {#properties}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string |  | The identifier. Pass it to `storageId` anywhere one is asked for. |
| `label` | string |  | The display name. The account holder can change it, so do not match on it. |
| `type` | string |  | `filesystem` · `phone` · `browser` · `database` · `object`. **The field to branch on.** |
| `provider` | string |  | What is behind it — `mongodb`, `d1`, `r2`, `s3`, `iagenify`, `machine`, `browser`. |
| `managedBy` | string |  | Who operates it. |
| `service` | string|null |  | `nosql` · `sql` · `object` on an IaGenify Cloud storage. `null` otherwise. |
| `isDefault` | boolean |  | Whether a save with no target lands here. |
| `machineId · hostname` | string|null |  | On a computer: which machine. |
| `deviceId` | string|null |  | On a phone: the identifier its browser keeps. |
| `limits` | object |  | What the storage tracks of its own space. |
| `lastActivityAt · createdAt` | string|null |  | When it was last used, and when it was registered. |

> **No credential is on this object**
>
> What you supplied at connection is used by the server to connect and is never handed back. Nothing here can leak a password by being logged or sent to a page.

## Branch on type, not on provider {#branch}

`provider` tells you what is behind the storage; `type` tells you what you can do with it. The second is what your code should test.

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

## A device is a storage that keeps its own bytes {#devices}

| type | Its data lives | run() | files |
| --- | --- | --- | --- |
| database · object | On the account | yes | no |
| filesystem | On that machine | answers that it is local | yes — on that machine |
| phone · browser | In that browser | answers that it is local | no — see the bridge |

> **files and terminals throw rather than return empty**
>
> On anything that is not a computer, reaching for files raises storage_not_local — or storage_is_phone on a phone, which says where the files actually are. Test type first; an empty result would be a lie.

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

## The same object, wherever it came from {#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()](/sdk/ref/connected-storage/run): Every action, what each one takes, and what it costs.
- [files](/sdk/ref/connected-storage/files): A computer's own files, on that machine.
- [api.storage](/sdk/ref/storage): The six ways to get one of these.

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