# Visão geral

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

Un oggetto per ogni tipo di stoccaggio. I dati sono letti e scrit prin run(); un computer obtiene due extras i propri files e i propri shells.

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

It's what `api.storage.create()`, `connect()`, `device()`, `get()` e `list()` a tote la mano. Tu non ne construis mai uno. La ragione per cui è un solo tipo è il punto del recurso: il codice che lege una base di dati que hospediamo è il codice che lege una che connegìs.

## La superficie {#surface}

| Membro | - A | Função |
| --- | --- | --- |
| run(config) | Cada stoccaggio | Lee e scrie i dati. |
| Fichier | un computator solamente | Aquella máquina son propri files. |
| Terminals | un computator solamente | Conchas e servidores que surviven a una resposta. |

## Ce porta {#properties}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string |  | L'identificator. Passa a `storageId` in qualsiasi parte si pede. |
| `label` | string |  | Il nome display. Il titular del cont può cambiarlo, quindi non concorde in esso. |
| `type` | string |  | `filesystem` · `phone` · `browser` · `database` · `object`. **O campo a ramiare.** |
| `provider` | string |  | Ce è dietro di esso — `mongodb`, `d1`, `r2`, `s3`, `iagenify`, `machine`, `browser`. |
| `managedBy` | string |  | Chi opera. |
| `service` | string|null |  | `nosql` · `sql` · `object` su un IaGenify Storage cloud. `null` altrimenti. |
| `isDefault` | boolean |  | Se un salvament senza terras-alvo aquí. |
| `machineId · hostname` | string|null |  | Su un computer: che macchina. |
| `deviceId` | string|null |  | Su un telefono: l'identificator del browser mantiene. |
| `limits` | object |  | Que le trace de stoccaj del suo propio spazio. |
| `lastActivityAt · createdAt` | string|null |  | Quando fu usat per ultima e quando fu registrat. |

> **Nessuna credencial è su questo objeto**
>
> Lo che ha fornito alla connezione è usat dal servidor per connetter e non è mai restituit. Nulla qui può dispersare un mot de passe mediante log o inviato a una pagina.

## Branche sul tipo, non sul provider {#branch}

`provider` te dice o que è dietro il storage; `type` te dice ce puoi fare con esso. La seconda è ciò que il tuo codice deve testare.

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

## Un dispositivo è un stoccaj che conserva i propri octes {#devices}

| tipo | I suoi dati dura | run() | Fichier |
| --- | --- | --- | --- |
| Base de données · objeto | Na conta | si | non |
| sistema de fiches | Su quella macchina | respondess che è local | si — su quella macchina |
| Telefono · Navegador | In quel browser | respondess che è local | No — ved il ponte |

> **Fichier e terminali lançano piuttosto que restituire vuoto**
>
> Su cosa non è un computer, per acercar i files solleva storage_not_local — o storage_is_phone su un telefono, che dice onde i files realmente sono. Testa prima; un risultato vazio sarebbe un mensonge.

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

## Il medìs objete, da ov'o di qui provenisse {#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()](/pt/sdk/ref/connected-storage/run): Ogni azione, che cosa cada una toma, e quanto costa.
- [Fichier](/pt/sdk/ref/connected-storage/files): Fissari propri di un computer, in que la machina.
- [api.storage](/pt/sdk/ref/storage): Seis modos de s'achiunsare uno di questi.

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