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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
getDatabaseAdapter
✓ import { getDatabaseAdapter } from 'dbinfoz';
✗ const getDatabaseAdapter = require('dbinfo');
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'`.
DatabaseAdapter
✓ import type { DatabaseAdapter } from 'dbinfoz';
Import the `DatabaseAdapter` interface for type hinting when working with a database adapter instance in TypeScript.
DatabaseConfig
✓ import type { DatabaseConfig } from 'dbinfoz';
Import the `DatabaseConfig` type for defining database connection options in TypeScript, which is a union type covering various database configurations.
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.
import { getDatabaseAdapter } from 'dbinfoz';
import type { DatabaseConfig, DatabaseAdapter } from 'dbinfoz';
// Configuration for a SQLite database. Replace with your actual database details.
const sqliteConfig: DatabaseConfig = {
filename: process.env.SQLITE_DB_PATH ?? './mydb.sqlite',
};
// Configuration for a PostgreSQL database. Remember to install 'pg' separately.
const postgresConfig: DatabaseConfig = {
host: process.env.PG_DB_HOST ?? 'localhost',
user: process.env.PG_DB_USER ?? 'yourUsername',
database: process.env.PG_DB_NAME ?? 'yourDatabase',
password: process.env.PG_DB_PASSWORD ?? 'yourPassword',
port: parseInt(process.env.PG_DB_PORT ?? '5432', 10),
};
// Choose your database type and config
const type: 'sqlite' | 'postgres' = 'sqlite'; // or 'postgres', 'mysql', 'mssql'
const config = type === 'sqlite' ? sqliteConfig : postgresConfig; // Use appropriate config
(async () => {
let dbAdapter: DatabaseAdapter | null = null;
try {
dbAdapter = getDatabaseAdapter(type, config);
console.log(`Connected to ${type} database.`);
// List tables
const tables = await dbAdapter.listTables();
console.log('Tables:', tables);
// Example: Get schema for a specific table (if it exists)
if (tables.length > 0) {
const firstTable = tables[0];
console.log(`Schema for table '${firstTable}':`);
const schema = await dbAdapter.getTableSchema(firstTable);
console.log(schema);
}
// Run a custom query (example: create a table for sqlite if not exists)
if (type === 'sqlite') {
await dbAdapter.runQuery('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT);');
console.log('Checked/created users table.');
}
} catch (error: any) {
console.error('Error:', error.message);
} finally {
// Some adapters (like SQLite) might have a 'close' method
if (dbAdapter && typeof (dbAdapter as any).close === 'function') {
await (dbAdapter as any).close();
console.log('Database connection closed.');
}
}
})();
Errors
Common errors & fixes
Error: Cannot find module 'dbinfo'
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'.
fixChange the import/require path from `'dbinfo'` to `'dbinfoz'`. For ESM: `import { getDatabaseAdapter } from 'dbinfoz';`. For CommonJS: `const { getDatabaseAdapter } = require('dbinfoz');`. Error: Adapter not found for type 'postgres'
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`.
fixInstall the corresponding database client library for the adapter type you are using. For PostgreSQL, run `npm install pg`.
Error: connect ECONNREFUSED 127.0.0.1:5432
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.
fixVerify 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.
Audit
Dependencies
pgoptionalRequired for PostgreSQL database connectivity when using the 'postgres' adapter.
mysql2optionalCommonly used for MySQL/MariaDB database connectivity when using the 'mysql' adapter. Alternative to 'mysql'.
mssqloptionalRequired for MSSQL (SQL Server) database connectivity when using the 'mssql' adapter.
sqlite3optionalRequired for SQLite database connectivity when using the 'sqlite' adapter.