Relational Database Metadata Utility
The `db-info` package is a Node.js utility designed to provide a database-agnostic interface for retrieving relational database metadata, such as table and column schemas. It supports SQLite3, MySQL, PostgreSQL, and Oracle databases by leveraging older versions of `node-sqlite3`, `node-mysql`, `node-postgres`, and `node-oracle` drivers. The current and only known version is 0.0.3, last published in April 2012. Given its age and lack of updates for over a decade, this package is definitively abandoned and not actively maintained. Its API is entirely callback-based, reflecting Node.js development patterns from its release era. Key differentiators at the time were its unified interface across multiple database types for schema introspection, but it is now highly outdated compared to modern ORMs or database toolkit solutions.
Common errors
-
TypeError: require is not a function
cause Attempting to use `require` in an ES module environment (e.g., in a file with `"type": "module"` in `package.json` or a `.mjs` file).fixThis package is CommonJS-only. Either configure your project for CommonJS (`"type": "commonjs"` in `package.json` or use `.cjs` extensions) or find a modern, actively maintained alternative. Dynamic `import()` might technically work but is not recommended for an abandoned package. -
Error: Cannot find module 'sqlite3'
cause A required database driver (e.g., `sqlite3`, `mysql`, `pg`, `db-oracle`) is not installed or available in the project's `node_modules`.fixInstall the specific driver needed using npm: `npm install sqlite3` (or `mysql`, `pg`, `db-oracle`). Note that older versions of these drivers might be required for compatibility with `db-info` itself. -
Error: Callback was already called.
cause A common issue in callback-based APIs where the callback function provided to `getInfo` is invoked multiple times, often due to error handling logic not returning early after an error.fixReview the code invoking `dbinfo.getInfo` to ensure the callback is only called once per execution path. This often requires careful `if (err) return callback(err);` patterns. -
Error: connect ECONNREFUSED
cause The target database server (e.g., MySQL, PostgreSQL, Oracle) is not running, is configured incorrectly, or network access is blocked by a firewall.fixVerify the database server is running and accessible from the machine executing the Node.js application. Check connection parameters (host, port, user, password, database) for correctness and ensure no firewall rules are blocking the connection.
Warnings
- breaking The package is abandoned and has not been updated since 2012. It requires Node.js >=0.6.0 and is highly unlikely to be compatible with modern Node.js versions (e.g., Node.js 16+), modern database drivers, or contemporary security practices.
- gotcha This package is CommonJS-only (`require`). It cannot be directly `import`ed in an ES module project without explicit transpilation or wrapper functions, which might introduce further compatibility issues due to its age.
- deprecated The underlying database drivers it supports (e.g., `node-sqlite3`, `node-mysql`, `node-postgres`, `node-oracle`) have evolved significantly since 2012. Using this package likely means relying on very old, potentially insecure, and unmaintained versions of these drivers.
- gotcha The API is exclusively callback-based, which is an outdated pattern in modern JavaScript/Node.js. It does not support Promises or async/await natively, leading to callback hell if integrating with modern asynchronous code.
- gotcha The package lists `async` as a dependency which likely refers to a very old version of the `async` library. This old version might have its own compatibility issues or even known vulnerabilities.
Install
-
npm install db-info -
yarn add db-info -
pnpm add db-info
Imports
- dbinfo
import dbinfo from 'db-info';
const dbinfo = require('db-info'); - getInfo
import { getInfo } from 'db-info';const dbinfo = require('db-info'); dbinfo.getInfo(...);
Quickstart
const sqlite3 = require('sqlite3').verbose();
const dbinfo = require('db-info');
// Create an in-memory SQLite database for demonstration
const db = new sqlite3.Database(':memory:', (err) => {
if (err) {
return console.error(err.message);
}
console.log('Connected to the in-memory SQLite database.');
// Create a dummy table
db.run(`CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE,
age INTEGER
)`, (err) => {
if (err) {
// Table might already exist if run multiple times in same process
if (err.message.includes('already exists')) {
console.log('Table "users" already exists, proceeding.');
} else {
return console.error('Error creating table:', err.message);
}
} else {
console.log('Table "users" created successfully.');
}
// Get database metadata using db-info
dbinfo.getInfo({
driver: 'sqlite3',
db: db
}, function(err, result) {
if (err) {
return console.error('Error getting DB info:', err.message);
}
console.log('Database metadata retrieved:');
console.log(JSON.stringify(result, null, 2));
// Close the database connection
db.close((err) => {
if (err) {
return console.error(err.message);
}
console.log('Closed the database connection.');
});
});
});
});