{"id":18117,"library":"any-db","title":"any-db","description":"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.","status":"maintenance","version":"2.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/grncdr/node-any-db","tags":["javascript","mysql","postgres","pg","sqlite","sqlite3"],"install":[{"cmd":"npm install any-db","lang":"bash","label":"npm"},{"cmd":"yarn add any-db","lang":"bash","label":"yarn"},{"cmd":"pnpm add any-db","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"required for transaction support","package":"any-db-transaction","optional":true},{"reason":"parses database URL strings","package":"parse-db-url","optional":false},{"reason":"MySQL adapter (peer dependency)","package":"any-db-mysql","optional":true},{"reason":"PostgreSQL adapter (peer dependency)","package":"any-db-postgres","optional":true},{"reason":"SQLite3 adapter (peer dependency)","package":"any-db-sqlite3","optional":true}],"imports":[{"note":"The package supports both ESM and CJS; default export is the main module.","wrong":"const anyDB = require('any-db')","symbol":"default","correct":"import anyDB from 'any-db'"},{"note":"Named export also available; CJS destructuring works but ESM preferred.","wrong":"const { createConnection } = require('any-db')","symbol":"createConnection","correct":"import { createConnection } from 'any-db'"},{"note":"createPool is a named export, not a default export.","wrong":"import createPool from 'any-db'","symbol":"createPool","correct":"import { createPool } from 'any-db'"}],"quickstart":{"code":"import anyDB from 'any-db';\n// Assumes any-db-postgres is installed\nconst url = 'postgres://user:password@localhost/mydb';\nconst conn = anyDB.createConnection(url);\nconn.query('SELECT * FROM users WHERE id = ?', [1], (err, result) => {\n  if (err) throw err;\n  console.log(result.rows);\n});\nconn.on('error', (err) => console.error('Connection error:', err));\nconst pool = anyDB.createPool(url, { min: 2, max: 5 });\npool.query('SELECT 1', (err, res) => {\n  console.log(res.rows);\n  pool.close();\n});","lang":"javascript","description":"Shows creating a connection and a pool, querying with bound parameters, and error handling."},"warnings":[{"fix":"Migrate to a modern database abstraction library like knex.","message":"any-db is no longer actively maintained; consider using knex or sequelize.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Install an adapter like 'any-db-postgres' and ensure it's in your package.json.","message":"Adapter packages must be installed separately; any-db alone does not connect to any database.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use require() or configure a bundler to handle CJS.","message":"The library ships only CommonJS; ESM imports may require bundling or Node --experimental-require-module.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use .on('data') or .pipe() to consume rows; for old event listeners, upgrade code.","message":"Version 2.0.0 changed stream behavior: query() now returns a readable stream instead of emitting 'row' events.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Pass an object with adapter, host, port, database, user, password instead of a URL string.","message":"Connection URL parsing may fail for non-standard ports or special characters; use object syntax for reliability.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install any-db-postgres","cause":"The required adapter is not installed.","error":"Error: Cannot find module 'any-db-postgres'"},{"fix":"Use import anyDB from 'any-db' instead of import { anyDB } from 'any-db'.","cause":"Using wrong import style: named export instead of default export.","error":"TypeError: anyDB.createConnection is not a function"},{"fix":"Kill existing processes or use a different port in the connection URL.","cause":"Port conflict, often due to multiple instances or leftover connections.","error":"Error: listen EADDRINUSE: address already in use :::5432"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}