Skip to main content

Examples

Each example is a self-contained project that applies a todos schema with the standalone db-x CLI. They all follow the same shape: schema.tsx holds a reusable component, dbx.tsx wires the connection around it.

Experimental

DB-X is an early prototype. Do not point it at a database you care about.

Runnable today

ExampleLibraryEngine pageNeeds
examples/postgres@db-x/postgres-libraryPostgreSQLpsql, Docker
examples/sqlite@db-x/sqlite-librarySQLitesqlite3
examples/mongodb@db-x/mongodb-libraryMongoDBmongosh, Docker
examples/cockroachdb@db-x/postgres-libraryCockroachDBpsql, Docker
examples/supabase@db-x/postgres-librarySupabaseSupabase CLI, Docker

examples/sqlite is the quickest start: the file is the database, so there is no server, no credentials and no container.

Engine support at a glance

EngineSnapshot driverDrift detectionNotable limit
PostgreSQLpg_dump (schema or full)yes
SQLitefile copy (always full)yesno ALTER COLUMN — needs a table rebuild (#56)
MongoDBmongodumpyesvalidator tightening detected heuristically
CockroachDBnoneyespg_dump unsupported, so no rollback (#85)
Supabasepg_dump (schema or full)yesauth.users and RLS are raw SQL, not components

Not built yet

examples/ also holds README-only placeholders for CouchDB, DuckDB, MySQL, Oracle and SQL Server. They describe the intended shape and link to the issue tracking the library each would need — there is nothing to run yet.

The loop

Every runnable example supports the same cycle:

pnpm install && pnpm build # from the repo root, once
cd examples/<engine>
pnpm preview # render, diff, print the exact statements
pnpm apply --yes # execute them, persist state to .dbx/
pnpm apply --yes --allow-destructive # snapshot first, then apply
pnpm restore --yes # roll back to that snapshot
pnpm destroy # tear it down in reverse order

preview renders and diffs offline — it never connects to a database. apply refuses a destructive change unless you pass --allow-destructive, and refuses again if it cannot capture a snapshot first, so there is always something to roll back to. CockroachDB is the one target where that second gate never opens.

Start with the Quickstart (Docker), then read Time Machine for how snapshots and rollback work.