Connectors

You can use DB0 api with the connector of your own choice.

Currently supported connectors:

Read more in github.com/unjs/db0/issues/32.

#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.

ConnectorPackage
better-sqlite3better-sqlite3
bun-sqlite— (built into Bun)
cloudflare-d1
cloudflare-hyperdrive-mysqlmysql2
cloudflare-hyperdrive-postgresqlpg
libsql@libsql/client
mysql2mysql2
neon@neondatabase/serverless
node-sqlite— (built into Node.js and Deno)
pglite@electric-sql/pglite
planetscale@planetscale/database
postgresqlpg
sqlite3sqlite3

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" } }

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.

db0  tiny sql connector.