Registry / database / db0
library0.3.4jsnpmunverified

DB0 is a lightweight SQL connector for Node.js and edge environments, currently at version 0.3.4 (early development). It provides a unified query API over multiple SQL databases (SQLite, PostgreSQL via PGlite, MySQL, and LibSQL) and integrates with ORMs like Drizzle ORM. Unlike full ORMs or heavy query builders, DB0 focuses on a minimal API surface for direct SQL execution, making it suitable for serverless, edge, and framework-agnostic applications. The library is developed by unjs and supports both CommonJS and ESM but defaults to ESM. Key differentiators: zero dependencies, TypeScript-first, and connector-based architecture that allows swapping backends without changing application code.

npm install db0
INSTALL
IMPORT
SIG · DB0
D
db0
databasejavascriptv0.3.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createDatabase
✓ import { createDatabase } from 'db0'
✗ const { createDatabase } = require('db0')
DB0 is ESM-only; require() will fail unless using a dynamic import.
sqliteConnector
✓ import { sqliteConnector } from 'db0/connectors/sqlite'
✗ import { sqliteConnector } from 'db0'
Connectors are exported from subpaths, not from the main module.
mysqlConnector
✓ import { mysqlConnector } from 'db0/connectors/mysql'
✗ import mysqlConnector from 'db0'
Connectors must be imported from their specific paths.

Creates a SQLite database using the sqlite connector and runs a simple query and a parameterized query.

import { createDatabase } from 'db0' import { sqliteConnector } from 'db0/connectors/sqlite' const db = createDatabase( sqliteConnector({ path: './data.db' }) ) // Execute a query const result = await db.sql`SELECT 1 + 1 AS sum` console.log(result) // [{ sum: 2 }] // With parameters const id = 1 const user = await db.sql`SELECT * FROM users WHERE id = ${id}` console.log(user) // Close connection db.close()
Debug
Known issues
breakingThe package is in early development (v0.x), API changes may occur without major version bumps. Pin to a specific version in production.
fix
Use exact version in package.json (e.g., "db0": "0.3.4") and lock file.
affects: >=0.0.0
deprecatedUsing require() to import db0 is deprecated. The package is ESM-only and require() will not work.
fix
Use import statements or dynamic import() instead.
affects: >=0.2.0
gotchaConnectors must be imported from subpaths (e.g., 'db0/connectors/sqlite'), not from the main module. Attempting to import { sqliteConnector } from 'db0' will result in undefined.
fix
Always use the full subpath import for connectors.
affects: >=0.0.0
gotchaThe database should be closed after use to release resources, especially in serverless environments. Failing to call db.close() may cause memory leaks or hang processes.
fix
Call db.close() when the database is no longer needed, e.g., in a finally block or after serverless function completion.
affects: >=0.0.0
deprecatedSeveral connectors require peer dependencies that must be installed separately. Running without the peer dep will cause runtime import errors.
fix
Install the required connector package (e.g., 'npm install better-sqlite3' for sqlite connector).
affects: >=0.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to require() an ESM-only module.
fix
Change to import statement or use dynamic import().
Cannot find module 'better-sqlite3'
Missing peer dependency for the connector being used.
fix
Install the missing connector: npm install better-sqlite3
TypeError: createDatabase is not a function
Incorrect import; likely using destructured require() or wrong named export.
fix
Use: import { createDatabase } from 'db0'
Error: Cannot find module 'db0/connectors/sqlite'
Misspelled connector path or missing subpath export.
fix
Verify the path: 'db0/connectors/sqlite' (note: sqlite, not sqlite3).
Upgrade
Version history
0.3.4latest on npm
Audit
Dependencies
@electric-sql/pgliteoptionalRequired for PostgreSQL connector using PGlite (in-memory or file-backed).
@libsql/clientoptionalRequired for LibSQL connector (Turso).
better-sqlite3optionalRequired for better-sqlite3 connector.
drizzle-ormoptionalRequired for Drizzle ORM integration.
mysql2optionalRequired for MySQL connector.
sqlite3optionalRequired for sqlite3 connector.
Agent activity
5 hits · last 30 days
node
4
Resources
packagedb0 ↗
db0 — npm install db0 · libregistry