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-dbVerified import paths — ran on the pinned version, not inferred.
Shows creating a connection and a pool, querying with bound parameters, and error handling.
Migrate to a modern database abstraction library like knex.
Install an adapter like 'any-db-postgres' and ensure it's in your package.json.
Use require() or configure a bundler to handle CJS.
Use .on('data') or .pipe() to consume rows; for old event listeners, upgrade code.Pass an object with adapter, host, port, database, user, password instead of a URL string.
npm install any-db-postgres
Use import anyDB from 'any-db' instead of import { anyDB } from 'any-db'.Kill existing processes or use a different port in the connection URL.