Registry / database / db-meta

db-meta

JSON →
library0.5.1jsnpmunverified

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.

npm install db-meta
INSTALL
IMPORT
SIG · DB-META
D
db-meta
databasejavascriptv0.5.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dbmeta
const dbmeta = require('db-meta')
CommonJS only; no ESM or default export available.
Connection API
dbmeta('pg', { database: 'test' }, function(err, meta) { meta.getVersion(function(err, version) { ... }); });
dbmeta.createConnection('pg', { database: 'test' })
db-meta exports a single function, not a class or object.
Table methods
meta.getTables(function(err, tables) { tables.forEach(function(table) { console.log(table.getName()); }); });
Table objects are plain objects with methods like getName(), not classes.

Shows how to connect to PostgreSQL, retrieve database version, list all user tables, and inspect columns for a specific table using callbacks.

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()); }); }); });
Debug
Known issues
gotchaYou must install the database driver (pg, mysql, or sqlite3) separately. They are not included as dependencies.
fix
npm install pg # or mysql or sqlite3
affects: >=0.0.1
breakingThe 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; ... })
affects: >=0.5.0
deprecatedThe 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.
affects: >=0.0.1
breakingIn 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'.
affects: >=0.5.0
gotchaThe 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.
affects: >=0.4.0
Errors
Common errors & fixes
Error: Cannot find module 'pg'
The pg driver is not installed.
fix
npm install pg
TypeError: undefined is not a function
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: getColumns is not a function
Calling getColumns on a Table object instead of the meta driver.
fix
Use meta.getColumns('tableName', callback), not table.getColumns().
Error: Connection refused
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.
Upgrade
Version history
0.5.1latest on npm
Audit
Dependencies
pgoptionalRequired for PostgreSQL database support
mysqloptionalRequired for MySQL database support
sqlite3optionalRequired for SQLite3 database support
Agent activity
8 hits · last 30 days
node
8
Resources
db-meta — npm install db-meta · libregistry