db-meta
raw JSON → 0.5.1 verified Sat Apr 25 auth: no javascript
db-meta is a JavaScript library for extracting relational database metadata (tables, columns, data types, nullability, primary keys, default values, version) from PostgreSQL, MySQL, and SQLite3. Version 0.5.1 is the current stable release, with irregular updates. It abstracts over database-specific drivers (pg, mysql, sqlite3) using a unified callback-based API. Unlike ORM tools, it focuses purely on schema introspection without query building or object mapping. Requires Node.js >=0.6 and manual installation of the appropriate database driver.
Common errors
error Error: Cannot find module 'pg' ↓
cause The pg driver is not installed.
fix
npm install pg
error TypeError: undefined is not a function ↓
cause Using an outdated callback signature that omits the error parameter, or calling dbmeta() with wrong arguments.
fix
Ensure first argument is a valid driver string, second is options object, and third is a callback that accepts (err, meta).
error Error: getColumns is not a function ↓
cause Calling getColumns on a Table object instead of the meta driver.
fix
Use meta.getColumns('tableName', callback), not table.getColumns().
error Error: Connection refused ↓
cause Database server is not running or connection options are incorrect.
fix
Verify database is running and check host, port, database name, user, password in options.
Warnings
gotcha You must install the database driver (pg, mysql, or sqlite3) separately. They are not included as dependencies. ↓
fix npm install pg # or mysql or sqlite3
breaking The callback for getTables, getColumns, and other methods follows (err, result) pattern, but older examples may omit the error parameter. ↓
fix Always check err: getTables(function(err, tables) { if (err) throw err; ... })
deprecated The API does not support Promises or async/await. Only callbacks are available. ↓
fix Wrap in a Promise manually or use a library like util.promisify.
breaking In version 0.5.0, the driver option 'pg' changed from 'postgres' to 'pg'. Using 'postgres' will cause an error. ↓
fix Use 'pg' instead of 'postgres'.
gotcha The options object may include a 'connection' key to pass an existing database connection. Not all drivers support this. ↓
fix Check driver documentation for connection reuse support.
Install
npm install db-meta yarn add db-meta pnpm add db-meta Imports
- dbmeta
const dbmeta = require('db-meta') - Connection API wrong
dbmeta.createConnection('pg', { database: 'test' })correctdbmeta('pg', { database: 'test' }, function(err, meta) { meta.getVersion(function(err, version) { ... }); }); - Table methods
meta.getTables(function(err, tables) { tables.forEach(function(table) { console.log(table.getName()); }); });
Quickstart
const dbmeta = require('db-meta');
dbmeta('pg', { database: 'test' }, function(err, meta) {
if (err) return console.error(err);
meta.getVersion(function(err, version) {
if (err) return console.error(err);
console.log('PostgreSQL version:', version);
});
meta.getTables(function(err, tables) {
if (err) return console.error(err);
tables.forEach(function(table) {
console.log('Table:', table.getName());
});
});
meta.getColumns('tablename', function(err, columns) {
if (err) return console.error(err);
columns.forEach(function(col) {
console.log(col.getName(), col.getDataType(), col.isNullable());
});
});
});