ConnectadStorage

Visão geral

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.

run() everywherefiles and terminals on a computer only
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

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- AFunção
run(config)Cada stoccaggioLee e scrie i dati.
Fichierun computator solamenteAquella máquina son propri files.
Terminalsun computator solamenteConchas e servidores que surviven a una resposta.

Ce porta

idstring

L'identificator. Passa a storageId in qualsiasi parte si pede.

labelstring

Il nome display. Il titular del cont può cambiarlo, quindi non concorde in esso.

typestring

filesystem · phone · browser · database · object. O campo a ramiare.

providerstring

Ce è dietro di esso — mongodb, d1, r2, s3, iagenify, machine, browser.

managedBystring

Chi opera.

servicestring|null

nosql · sql · object su un IaGenify Storage cloud. null altrimenti.

isDefaultboolean

Se un salvament senza terras-alvo aquí.

machineId · hostnamestring|null

Su un computer: che macchina.

deviceIdstring|null

Su un telefono: l'identificator del browser mantiene.

limitsobject

Que le trace de stoccaj del suo propio spazio.

lastActivityAt · createdAtstring|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

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

tipoI suoi dati durarun()Fichier
Base de données · objetoNa contasinon
sistema de fichesSu quella macchinarespondess che è localsi — su quella macchina
Telefono · NavegadorIn quel browserrespondess che è localNo — 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.

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