Skip to main content

One ORM, five databases: Yatta JS just grew a database switch

Updated 2 min readMarkdown

I used to pick a database before I picked a framework. SQLite for the side project, Postgres when it got serious, and a rewrite in between when the first choice stopped fitting.

Yatta JS just removed that decision from the critical path. This week the multi-database build landed on main: one ORM, five adapters, switched by a single config value.

import { createDatabase } from "yatta.js/db";

// SQLite (default) — same as before, no code change.
const db = createDatabase({ path: "Database/app.db", schema });

// Postgres, embedded — await it.
const pgdb = await createDatabase({ driver: "pglite", dataDir: "./pgdata", schema });

// Turso (libSQL), DuckDB, SurrealDB — same call, different driver.
const tdb = await createDatabase({ driver: "turso", url: "file:./app.db", schema });
const ddb = await createDatabase({ driver: "duckdb", path: "./app.duckdb", schema });
const sdb = await createDatabase({ driver: "surrealdb", url: "mem://", schema });

Everything above the adapter — tables, the query DSL, relations, migrations, search — talks to one interface, DatabaseAdapter. It never sees SQL, a driver, or a file. SQLite stays sync; the other four are async, and TypeScript forces you to await them. Your app code doesn't change when the driver does.

The part I like most is that the adapters aren't shallow. PGlite gets real Postgres full-text search (tsvector plus a GIN index). Turso keeps FTS5 with bm25. SurrealDB gets a BM25 index per searchable column. Rollback works on all five, and the comparison run in docs/db-comparison.md spells out the trade-offs plainly: SQLite is fastest everywhere, PGlite pays about 6 seconds to start and 42 MB on disk, DuckDB and SurrealDB are the slowest writers.

Two honest limits, because they matter if you pick a driver this week. ScyllaDB is deliberately outside the portable API — createAdapter throws for it, it isn't a half-finished adapter pretending otherwise. And DuckDB cascade deletes aren't atomic; that's a DuckDB 2.0.1 limitation, documented in the adapter docs rather than hidden.

This is on GitHub main now, not yet in an npm release — the package on npm is still yatta.js@1.0.6. If you build with Yatta, the switch is there when you need it, and the doc to read first is docs/adapters.md, with the numbers in docs/db-comparison.md.

The point isn't five databases. It's that the database stopped being a decision you have to get right on day one.

Docs: https://yatta.js.org — Code: https://github.com/psrockstar098/yatta.js — npm: https://www.npmjs.com/package/yatta.js

No comments yet. Be the first to comment.