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
| 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
idstringL'identificator. Passa a storageId in qualsiasi parte si pede.
labelstringIl nome display. Il titular del cont può cambiarlo, quindi non concorde in esso.
typestringfilesystem · phone · browser · database · object. O campo a ramiare.
providerstringCe è dietro di esso — mongodb, d1, r2, s3, iagenify, machine, browser.
managedBystringChi opera.
servicestring|nullnosql · sql · object su un IaGenify Storage cloud. null altrimenti.
isDefaultbooleanSe un salvament senza terras-alvo aquí.
machineId · hostnamestring|nullSu un computer: che macchina.
deviceIdstring|nullSu un telefono: l'identificator del browser mantiene.
limitsobjectQue le trace de stoccaj del suo propio spazio.
lastActivityAt · createdAtstring|nullQuando fu usat per ultima e quando fu registrat.
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
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.
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.Un dispositivo è un stoccaj che conserva i propri octes
| 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 |
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.
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()Il medìs objete, da ov'o di qui provenisse
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")