Docs

Caller storage

Write SQL and keep key-value data scoped to the verified caller of your service with berm-lang and crab.toml.

Caller storage gives each caller of your service their own SQLite storage. Write SQL and key-value operations for a single caller. The host selects the storage using the billed account and the verified end user, when present. An organization account shares storage across its members.

Declare storage

Put the caller's migrations in a directory beside crab.toml and declare it:

[storage.caller]
migrations = "caller"

Use [storage] for shared storage. The two handles have separate transactions. The billed account's plan supplies the size limit for caller storage. A service using caller storage alone reserves zero bytes of shared storage by default.

Read and write

Put this migration in caller/001.sql:

CREATE TABLE preferences (
    key TEXT PRIMARY KEY,
    value TEXT NOT NULL
);

Use berm_lang::caller_storage inside a service tool:

use berm_lang::caller_storage;

caller_storage::rows::<()>(
    "INSERT INTO preferences (key, value) VALUES (?, ?)
     ON CONFLICT (key) DO UPDATE SET value = excluded.value",
    &("timezone", "Asia/Singapore"),
)?;
let timezone = caller_storage::rows::<(String,)>(
    "SELECT value FROM preferences WHERE key = ?",
    &("timezone",),
)?;

Use caller_storage::get, set, get_raw, set_raw and delete for key-value data, encoded as for shared storage. A query tool can read caller storage over GET. Its response is private and cannot be cached. Calls for one caller write in sequence. The service owner pays compute for rows read and written.

Identity and migrations

The first successful write creates the caller's SQLite file. After a deploy, the host applies new migrations when a caller’s storage is next opened with writes allowed. Calls under a read-only allowance can still read the existing schema. A failed migration leaves their data available to download and sends the error to the service's logs.

With crab dev, the unchecked --caller selects local caller storage and defaults to local. An optional --issuer and --user select the end user.

A nested service call uses the sending service’s billed account and the propagated end user, if present. Direct anonymous calls have an empty keyspace and a temporary SQLite database initialized with the migrations. Writes are refused with E0085. A tool invoked directly by a schedule selects no caller file.

Callers manage their own data in Storage.