Skip to content

State & Storage ​

Beyond your application database, Chimpbase provides built-in storage primitives for operational state. See the dedicated pages for full API details: KV Store, Collections, Streams.

Key-Value Store ​

Simple key-value storage for configuration, flags, and lightweight state:

ts
await ctx.kv.set("config:feature-flags", { darkMode: true });
const flags = await ctx.kv.get("config:feature-flags");
await ctx.kv.delete("config:feature-flags");
const keys = await ctx.kv.list({ prefix: "config:" });

Stored in the _chimpbase_kv table.

Collections ​

Schemaless JSON document storage for data that doesn't need a rigid schema:

ts
const id = await ctx.collection.insert("notes", { title: "Meeting notes", content: "..." });
const notes = await ctx.collection.find("notes", { title: "Meeting notes" });
const note = await ctx.collection.findOne("notes", { id: noteId });
await ctx.collection.update("notes", { id: noteId }, { content: "updated" });
await ctx.collection.delete("notes", { id: noteId });

Stored in the _chimpbase_collections table.

Streams ​

Append-only event streams for audit logs, activity feeds, and event sourcing patterns:

ts
await ctx.stream.append("audit.todos", "todo.created", {
  todoId: todo.id,
  createdBy: input.userId,
});

const events = await ctx.stream.read("audit.todos");

Stored in the _chimpbase_stream_events table.

Storage Engines ​

Chimpbase supports three storage engines. PostgreSQL is the recommended default for production. See Configuration for setup details.

EngineUse caseCoordination
PostgreSQLProductionMulti-process, distributed
SQLiteLocal development, testsSingle-process
MemoryUnit testsEphemeral

Internal Tables ​

Chimpbase manages its own tables, prefixed with _chimpbase_:

TablePurpose
_chimpbase_eventsPub/sub event bus
_chimpbase_kvKey-value store
_chimpbase_collectionsJSON document storage
_chimpbase_stream_eventsAppend-only event streams
_chimpbase_cron_schedulesDurable cron metadata
_chimpbase_workflowsWorkflow state
_chimpbase_queue_jobsJob queue with retry tracking
_chimpbase_logsPersisted log entries
_chimpbase_metricsPersisted metrics
_chimpbase_tracesPersisted trace spans

These tables are created and migrated automatically. Your application tables live alongside them in the same database.

Schema Management ​

Use the CLI to generate and check schema migrations:

bash
# Generate migration SQL for internal tables
bun run chimpbase.app.ts schema generate

# Check if the current schema matches expected state
bun run chimpbase.app.ts schema check