@intentface/latch-drizzle
v0.12.0
Published
Latch StorageAdapter on Drizzle (SQLite/libsql first, Postgres next).
Readme
@intentface/latch-drizzle
The persistence tier for Latch — a StorageAdapter and SecretStore implemented on Drizzle (libsql/SQLite first-class, Postgres alongside).
What it does
createSqliteAdapter/ (pg variant) — theStorageAdapterthe runtime persists through: chats, messages (theAppMessagesource of truth), runs (status, leases, usage, cost incl. cached-token split), usage ledger, and schedules. Owner-keyed for org/user isolation (theownerfn derives the key from yourPrincipal).createSqliteSecretStore— the encrypted record store behind the coreVault(it never sees plaintext; the Vault wraps/unwraps).migrate(client)— creates thelatch_*tables (CREATE TABLE IF NOT EXISTS) plus idempotentALTERs for columns added later (timezone, cached-token counts, …). Safe to run at startup; no migration tooling required.
Tables: latch_chats, latch_messages, latch_runs, latch_usage, latch_secrets, latch_schedules.
Usage
import { createClient } from "@libsql/client";
import { createSqliteAdapter, createSqliteSecretStore, migrate } from "@intentface/latch-drizzle";
const client = createClient({ url: DATABASE_URL, authToken: TURSO_AUTH_TOKEN });
await migrate(client);
const owner = (p: Principal) => (p.userId ? [p.orgId, p.userId] : [p.orgId]);
const storage = createSqliteAdapter<Principal>(client, { owner });Owner-key contract. owner must be a pure projection of the stable part
of your principal — durable ids from your database, never per-session state
(an "active org" that can be null on some requests will silently split one
user's data across two keys). The key is derived once, at root-resource
creation; child rows inherit it. Never re-derive it from a live principal in
a different request context (OAuth callbacks, webhooks, cron) — pin identity
into the flow/run and rebuild it via reconstructPrincipal instead.
Where it fits
The T1 (persistence) tier under @intentface/latch-core. Swap it for another StorageAdapter implementation behind the same contract.
