SQLite Storage Adapter (@invariant/sqlite)
SQLite is the simplest durable local store for development, tests, single-host services, and small deployments.
Install and Configure
bash
npm install @invariant/sdk @invariant/sqlitets
import { invariant } from "@invariant/sdk";
import { sqlite } from "@invariant/sqlite";
const store = sqlite({
filename: "./data/invariant.db",
durability: "strict",
busyTimeoutMs: 5_000,
});
export const app = invariant({ storage: store });The string shorthand is equivalent to { filename }:
ts
const app = invariant({ storage: sqlite("./data/invariant.db") });Use sqlite(":memory:") for isolated tests.
Storage Behavior
- Schema migrations run when
SqliteRuntimeStoreis constructed. - File-backed databases enable WAL journaling.
durability: "normal"uses SQLitesynchronous=NORMAL.durability: "strict"usessynchronous=FULL.- Foreign-key enforcement is enabled.
- Execution state, event history, commands, leases, and durable Session context implement the common
RuntimeStorecontract.
Close the Store
ts
await store.close();Close the store during graceful application shutdown. Do not close it while Sessions are executing commands.
Move to PostgreSQL
Workflow definitions do not depend on the physical store, but persisted SQLite rows are not automatically copied. Provision PostgreSQL with initializeSchema(), stop writes, migrate application-required history with an explicit migration process, then change the configured store.
ts
import { PostgresRuntimeStore } from "@invariant/postgres";
const store = new PostgresRuntimeStore({
connectionString: process.env.DATABASE_URL,
});
await store.initializeSchema();
const app = invariant({ storage: store });Next Steps
- PostgreSQL — Distributed durable storage primitives.
- Custom Storage — Implement
RuntimeStore. - Runtime Execution — Understand atomic commits and host dispatch.