{"id":17205,"library":"dbinfoz","title":"DBINFOZ Universal Database Adapter","description":"DBINFOZ is a JavaScript/TypeScript library designed to provide a simple and unified interface for interacting with various SQL databases, including PostgreSQL, MySQL, MSSQL, and SQLite. Currently at version 0.14.0, the package aims to abstract away database-specific connection and query methods, allowing developers to list databases, tables, and retrieve table schemas through a consistent API. While there's no explicit release cadence mentioned, the 0.x.x versioning implies active development and potential for non-semver breaking changes. Its key differentiator is offering a single factory function to obtain adapters for multiple database types, reducing the boilerplate of managing individual database client libraries directly in application logic.","status":"active","version":"0.14.0","language":"javascript","source_language":"en","source_url":"https://github.com/rootedbox/dbinfoz","tags":["javascript","Database","Table","Schema","SQLite","MySQL","Postgres","MSSQL","typescript"],"install":[{"cmd":"npm install dbinfoz","lang":"bash","label":"npm"},{"cmd":"yarn add dbinfoz","lang":"bash","label":"yarn"},{"cmd":"pnpm add dbinfoz","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for PostgreSQL database connectivity when using the 'postgres' adapter.","package":"pg","optional":true},{"reason":"Commonly used for MySQL/MariaDB database connectivity when using the 'mysql' adapter. Alternative to 'mysql'.","package":"mysql2","optional":true},{"reason":"Required for MSSQL (SQL Server) database connectivity when using the 'mssql' adapter.","package":"mssql","optional":true},{"reason":"Required for SQLite database connectivity when using the 'sqlite' adapter.","package":"sqlite3","optional":true}],"imports":[{"note":"The README examples incorrectly show `require('dbinfo')`. The correct package name for import is `dbinfoz`. Since the package ships TypeScript types, ESM `import` is preferred for modern Node.js and bundler environments. CommonJS `require` should use `'dbinfoz'`.","wrong":"const getDatabaseAdapter = require('dbinfo');","symbol":"getDatabaseAdapter","correct":"import { getDatabaseAdapter } from 'dbinfoz';"},{"note":"Import the `DatabaseAdapter` interface for type hinting when working with a database adapter instance in TypeScript.","symbol":"DatabaseAdapter","correct":"import type { DatabaseAdapter } from 'dbinfoz';"},{"note":"Import the `DatabaseConfig` type for defining database connection options in TypeScript, which is a union type covering various database configurations.","symbol":"DatabaseConfig","correct":"import type { DatabaseConfig } from 'dbinfoz';"}],"quickstart":{"code":"import { getDatabaseAdapter } from 'dbinfoz';\nimport type { DatabaseConfig, DatabaseAdapter } from 'dbinfoz';\n\n// Configuration for a SQLite database. Replace with your actual database details.\nconst sqliteConfig: DatabaseConfig = {\n  filename: process.env.SQLITE_DB_PATH ?? './mydb.sqlite',\n};\n\n// Configuration for a PostgreSQL database. Remember to install 'pg' separately.\nconst postgresConfig: DatabaseConfig = {\n  host: process.env.PG_DB_HOST ?? 'localhost',\n  user: process.env.PG_DB_USER ?? 'yourUsername',\n  database: process.env.PG_DB_NAME ?? 'yourDatabase',\n  password: process.env.PG_DB_PASSWORD ?? 'yourPassword',\n  port: parseInt(process.env.PG_DB_PORT ?? '5432', 10),\n};\n\n// Choose your database type and config\nconst type: 'sqlite' | 'postgres' = 'sqlite'; // or 'postgres', 'mysql', 'mssql'\nconst config = type === 'sqlite' ? sqliteConfig : postgresConfig; // Use appropriate config\n\n(async () => {\n  let dbAdapter: DatabaseAdapter | null = null;\n  try {\n    dbAdapter = getDatabaseAdapter(type, config);\n    console.log(`Connected to ${type} database.`);\n\n    // List tables\n    const tables = await dbAdapter.listTables();\n    console.log('Tables:', tables);\n\n    // Example: Get schema for a specific table (if it exists)\n    if (tables.length > 0) {\n      const firstTable = tables[0];\n      console.log(`Schema for table '${firstTable}':`);\n      const schema = await dbAdapter.getTableSchema(firstTable);\n      console.log(schema);\n    }\n\n    // Run a custom query (example: create a table for sqlite if not exists)\n    if (type === 'sqlite') {\n      await dbAdapter.runQuery('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT);');\n      console.log('Checked/created users table.');\n    }\n\n  } catch (error: any) {\n    console.error('Error:', error.message);\n  } finally {\n    // Some adapters (like SQLite) might have a 'close' method\n    if (dbAdapter && typeof (dbAdapter as any).close === 'function') {\n      await (dbAdapter as any).close();\n      console.log('Database connection closed.');\n    }\n  }\n})();","lang":"typescript","description":"This quickstart demonstrates how to instantiate a database adapter for SQLite or PostgreSQL, list tables, retrieve a table's schema, and execute a custom query, while also showing proper type usage and environment variable integration for sensitive credentials."},"warnings":[{"fix":"Always use `import { getDatabaseAdapter } from 'dbinfoz';` for ESM or `const { getDatabaseAdapter } = require('dbinfoz');` for CommonJS.","message":"The README examples incorrectly instruct users to `require('dbinfo')`. The package name is `dbinfoz`, and the correct import path for both CommonJS and ESM should be `'dbinfoz'`. Following the README's incorrect path will result in a 'module not found' error.","severity":"breaking","affected_versions":"0.1.0 - 0.14.0"},{"fix":"Install necessary database drivers: `npm install pg` for PostgreSQL, `npm install mysql2` for MySQL, `npm install mssql` for MSSQL, and `npm install sqlite3` for SQLite.","message":"DBINFOZ acts as an adapter layer but does not include the actual database client drivers (e.g., `pg`, `mysql2`, `mssql`, `sqlite3`). Users must explicitly install the appropriate driver packages for the databases they intend to connect to. Failure to do so will result in runtime errors when attempting to instantiate an adapter for that database type.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Pin to exact versions (`\"dbinfoz\": \"0.14.0\"`) or use cautious ranges (`\"dbinfoz\": \"^0.14.0\"`) and thoroughly test when upgrading, especially in production environments.","message":"As a 0.x.x version package, DBINFOZ is not bound by semantic versioning (SemVer) and may introduce breaking changes in minor or even patch releases without prior deprecation warnings. Review release notes carefully when upgrading.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change the import/require path from `'dbinfo'` to `'dbinfoz'`. For ESM: `import { getDatabaseAdapter } from 'dbinfoz';`. For CommonJS: `const { getDatabaseAdapter } = require('dbinfoz');`.","cause":"Attempting to import or require the package using the incorrect name 'dbinfo' as shown in outdated README examples, instead of the correct package name 'dbinfoz'.","error":"Error: Cannot find module 'dbinfo'"},{"fix":"Install the corresponding database client library for the adapter type you are using. For PostgreSQL, run `npm install pg`.","cause":"The required database client library (e.g., `pg` for PostgreSQL, `mysql2` for MySQL, `mssql` for MSSQL, `sqlite3` for SQLite) has not been installed alongside `dbinfoz`.","error":"Error: Adapter not found for type 'postgres'"},{"fix":"Verify that your database server is running and accessible from the application's host. Double-check all connection configuration parameters (host, port, user, password, database name) for accuracy. Ensure no firewalls are blocking the connection.","cause":"The application could not establish a connection to the database server. This usually indicates incorrect connection parameters (host, port, user, password), the database server not running, or firewall issues.","error":"Error: connect ECONNREFUSED 127.0.0.1:5432"}],"ecosystem":"npm","meta_description":null}