Connectors
You can use DB0 api with the connector of your own choice.
Currently supported connectors:
#Connector dependencies
DB0 itself has no runtime dependencies. Connectors that talk to a third-party database library (better-sqlite3, pg, mysql2, @libsql/client, ...) import it lazily and dynamically on first use, so you only need to install what the connectors you actually use require. Each connector page lists its own install command.
| Connector | Package |
|---|---|
better-sqlite3 | better-sqlite3 |
bun-sqlite | — (built into Bun) |
cloudflare-d1 | — |
cloudflare-hyperdrive-mysql | mysql2 |
cloudflare-hyperdrive-postgresql | pg |
libsql | @libsql/client |
mysql2 | mysql2 |
neon | @neondatabase/serverless |
node-sqlite | — (built into Node.js and Deno) |
pglite | @electric-sql/pglite |
planetscale | @planetscale/database |
postgresql | pg |
sqlite3 | sqlite3 |
If your bundler or runtime cannot resolve the dynamic import (or you simply prefer a static top-level import), every such connector accepts a lib option:
import { createDatabase } from "db0";
import postgresql from "db0/connectors/postgresql";
import * as pg from "pg";
const db = createDatabase(
postgresql({
url: process.env.DATABASE_URL,
lib: pg, // the module itself
// lib: () => import("pg"), // or a (sync/async) function returning it
}),
);#Introspecting dependencies
Each connector module exports a CONNECTOR_DEPENDENCIES object describing what it needs, keyed by the option used to provide it. The same data is aggregated for all built-in connectors as connectorDependencies, so frameworks can check (or install) what a configured connector requires:
import { connectorDependencies } from "db0";
connectorDependencies["postgresql"];
// { lib: { name: "pg", version: "^8" } }
connectorDependencies["mysql2"];
// { lib: { name: "mysql2", import: "mysql2/promise", version: "^3" } }name is the npm package to install. import is the specifier the connector actually imports and is only set when it differs from name (a subpath such as mysql2/promise), so resolve the library from dep.import ?? dep.name when you load it yourself to pass back via the lib option.
optional: true means the package is only needed for some connector features or configurations. Connectors with no third-party dependencies are absent from the map.