{"id":42604,"library":"db0","title":"DB0","description":"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.","status":"active","version":"0.3.4","language":"javascript","source_language":"en","source_url":"https://github.com/unjs/db0","tags":["javascript","typescript"],"install":[{"cmd":"npm install db0","lang":"bash","label":"npm"},{"cmd":"yarn add db0","lang":"bash","label":"yarn"},{"cmd":"pnpm add db0","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for PostgreSQL connector using PGlite (in-memory or file-backed).","package":"@electric-sql/pglite","optional":true},{"reason":"Required for LibSQL connector (Turso).","package":"@libsql/client","optional":true},{"reason":"Required for better-sqlite3 connector.","package":"better-sqlite3","optional":true},{"reason":"Required for Drizzle ORM integration.","package":"drizzle-orm","optional":true},{"reason":"Required for MySQL connector.","package":"mysql2","optional":true},{"reason":"Required for sqlite3 connector.","package":"sqlite3","optional":true}],"imports":[{"note":"DB0 is ESM-only; require() will fail unless using a dynamic import.","wrong":"const { createDatabase } = require('db0')","symbol":"createDatabase","correct":"import { createDatabase } from 'db0'"},{"note":"Connectors are exported from subpaths, not from the main module.","wrong":"import { sqliteConnector } from 'db0'","symbol":"sqliteConnector","correct":"import { sqliteConnector } from 'db0/connectors/sqlite'"},{"note":"Connectors must be imported from their specific paths.","wrong":"import mysqlConnector from 'db0'","symbol":"mysqlConnector","correct":"import { mysqlConnector } from 'db0/connectors/mysql'"}],"quickstart":{"code":"import { createDatabase } from 'db0'\nimport { sqliteConnector } from 'db0/connectors/sqlite'\n\nconst db = createDatabase(\n  sqliteConnector({ path: './data.db' })\n)\n\n// Execute a query\nconst result = await db.sql`SELECT 1 + 1 AS sum`\nconsole.log(result) // [{ sum: 2 }]\n\n// With parameters\nconst id = 1\nconst user = await db.sql`SELECT * FROM users WHERE id = ${id}`\nconsole.log(user)\n\n// Close connection\ndb.close()","lang":"typescript","description":"Creates a SQLite database using the sqlite connector and runs a simple query and a parameterized query."},"warnings":[{"fix":"Use exact version in package.json (e.g., \"db0\": \"0.3.4\") and lock file.","message":"The package is in early development (v0.x), API changes may occur without major version bumps. Pin to a specific version in production.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Use import statements or dynamic import() instead.","message":"Using require() to import db0 is deprecated. The package is ESM-only and require() will not work.","severity":"deprecated","affected_versions":">=0.2.0"},{"fix":"Always use the full subpath import for connectors.","message":"Connectors 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.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Call db.close() when the database is no longer needed, e.g., in a finally block or after serverless function completion.","message":"The 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.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Install the required connector package (e.g., 'npm install better-sqlite3' for sqlite connector).","message":"Several connectors require peer dependencies that must be installed separately. Running without the peer dep will cause runtime import errors.","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.3.4':16 'agnost':70 'allow':101 'api':24,55 'applic':71,106 'architectur':99 'backend':103 'base':98 'builder':49 'chang':105 'code':107 'commonj':81 'connector':7,97 'connector-bas':96 'current':13 'databas':28 'db0':1,2,50 'default':85 'depend':91 'develop':18,75 'differenti':89 'direct':58 'drizzl':41 'earli':17 'edg':11,66 'environ':12 'esm':83,87 'execut':60 'first':94 'focus':51 'framework':69 'framework-agnost':68 'full':44 'heavi':47 'integr':37 'javascript':108 'key':88 'librari':73 'libsql':35 'lightweight':5 'like':40 'make':61 'minim':54 'multipl':26 'mysql':33 'node.js':9 'orm':39,42,45 'pglite':32 'postgresql':30 'provid':20 'queri':23,48 'serverless':65 'sql':6,27,59 'sqlite':29 'suitabl':63 'support':79 'surfac':56 'swap':102 'typescript':93,109 'typescript-first':92 'unifi':22 'unj':77 'unlik':43 'version':15 'via':31 'without':104 'zero':90","created_at":"2026-06-05T16:55:46.786326+00:00","updated_at":"2026-06-05T16:55:46.786326+00:00","problems":[{"fix":"Change to import statement or use dynamic import().","cause":"Attempting to require() an ESM-only module.","error":"ERR_REQUIRE_ESM"},{"fix":"Install the missing connector: npm install better-sqlite3","cause":"Missing peer dependency for the connector being used.","error":"Cannot find module 'better-sqlite3'"},{"fix":"Use: import { createDatabase } from 'db0'","cause":"Incorrect import; likely using destructured require() or wrong named export.","error":"TypeError: createDatabase is not a function"},{"fix":"Verify the path: 'db0/connectors/sqlite' (note: sqlite, not sqlite3).","cause":"Misspelled connector path or missing subpath export.","error":"Error: Cannot find module 'db0/connectors/sqlite'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/unjs/db0#readme","github":"https://github.com/unjs/db0","docs":null,"changelog":null,"pypi":null,"npm":"db0","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}