Registry / database / any-db

any-db

JSON →
library2.2.1jsnpmunverified

any-db is a database-agnostic abstraction layer for Node.js that provides consistent APIs for connection pooling, querying, and transactions across multiple SQL database backends including PostgreSQL, MySQL, SQLite3, and MSSQL. Version 2.2.1 is the latest stable release. The library emphasizes minimal opinionation, preserving driver-specific behavior while offering a unified interface. It supports streaming query results, bound parameters via ?, and event-based error handling. Unlike ORMs, any-db focuses on low-level database access with flexible connection and pool management. Its adapters are installed separately and have any-db as a peer dependency. The library ships only CommonJS modules and does not provide TypeScript definitions.

npm install any-db
INSTALL
IMPORT
SIG · ANY-DB
A
any-db
databasejavascriptv2.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

default
import anyDB from 'any-db'
const anyDB = require('any-db')
The package supports both ESM and CJS; default export is the main module.
createConnection
import { createConnection } from 'any-db'
const { createConnection } = require('any-db')
Named export also available; CJS destructuring works but ESM preferred.
createPool
import { createPool } from 'any-db'
import createPool from 'any-db'
createPool is a named export, not a default export.

Shows creating a connection and a pool, querying with bound parameters, and error handling.

import anyDB from 'any-db'; // Assumes any-db-postgres is installed const url = 'postgres://user:password@localhost/mydb'; const conn = anyDB.createConnection(url); conn.query('SELECT * FROM users WHERE id = ?', [1], (err, result) => { if (err) throw err; console.log(result.rows); }); conn.on('error', (err) => console.error('Connection error:', err)); const pool = anyDB.createPool(url, { min: 2, max: 5 }); pool.query('SELECT 1', (err, res) => { console.log(res.rows); pool.close(); });
Debug
Known issues
deprecatedany-db is no longer actively maintained; consider using knex or sequelize.
fix
Migrate to a modern database abstraction library like knex.
affects: >=2.0.0
gotchaAdapter packages must be installed separately; any-db alone does not connect to any database.
fix
Install an adapter like 'any-db-postgres' and ensure it's in your package.json.
affects: >=1.0.0
gotchaThe library ships only CommonJS; ESM imports may require bundling or Node --experimental-require-module.
fix
Use require() or configure a bundler to handle CJS.
affects: >=2.0.0
breakingVersion 2.0.0 changed stream behavior: query() now returns a readable stream instead of emitting 'row' events.
fix
Use .on('data') or .pipe() to consume rows; for old event listeners, upgrade code.
affects: >=2.0.0
gotchaConnection URL parsing may fail for non-standard ports or special characters; use object syntax for reliability.
fix
Pass an object with adapter, host, port, database, user, password instead of a URL string.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'any-db-postgres'
The required adapter is not installed.
fix
npm install any-db-postgres
TypeError: anyDB.createConnection is not a function
Using wrong import style: named export instead of default export.
fix
Use import anyDB from 'any-db' instead of import { anyDB } from 'any-db'.
Error: listen EADDRINUSE: address already in use :::5432
Port conflict, often due to multiple instances or leftover connections.
fix
Kill existing processes or use a different port in the connection URL.
Upgrade
Version history
2.2.1latest on npm
Audit
Dependencies
any-db-transactionoptionalrequired for transaction support
parse-db-urlrequiredparses database URL strings
any-db-mysqloptionalMySQL adapter (peer dependency)
any-db-postgresoptionalPostgreSQL adapter (peer dependency)
any-db-sqlite3optionalSQLite3 adapter (peer dependency)
Agent activity
29 hits · last 30 days
node
24
OpenAI (training)
1
Resources
any-db — npm install any-db · libregistry