{"id":18266,"library":"db-meta","title":"db-meta","description":"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.","status":"active","version":"0.5.1","language":"javascript","source_language":"en","source_url":"https://github.com/kunklejr/node-db-meta","tags":["javascript","database","db","metadata","postgres"],"install":[{"cmd":"npm install db-meta","lang":"bash","label":"npm"},{"cmd":"yarn add db-meta","lang":"bash","label":"yarn"},{"cmd":"pnpm add db-meta","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for PostgreSQL database support","package":"pg","optional":true},{"reason":"Required for MySQL database support","package":"mysql","optional":true},{"reason":"Required for SQLite3 database support","package":"sqlite3","optional":true}],"imports":[{"note":"CommonJS only; no ESM or default export available.","symbol":"dbmeta","correct":"const dbmeta = require('db-meta')"},{"note":"db-meta exports a single function, not a class or object.","wrong":"dbmeta.createConnection('pg', { database: 'test' })","symbol":"Connection API","correct":"dbmeta('pg', { database: 'test' }, function(err, meta) {\n  meta.getVersion(function(err, version) { ... });\n});"},{"note":"Table objects are plain objects with methods like getName(), not classes.","symbol":"Table methods","correct":"meta.getTables(function(err, tables) {\n  tables.forEach(function(table) { console.log(table.getName()); });\n});"}],"quickstart":{"code":"const dbmeta = require('db-meta');\ndbmeta('pg', { database: 'test' }, function(err, meta) {\n  if (err) return console.error(err);\n  meta.getVersion(function(err, version) {\n    if (err) return console.error(err);\n    console.log('PostgreSQL version:', version);\n  });\n  meta.getTables(function(err, tables) {\n    if (err) return console.error(err);\n    tables.forEach(function(table) {\n      console.log('Table:', table.getName());\n    });\n  });\n  meta.getColumns('tablename', function(err, columns) {\n    if (err) return console.error(err);\n    columns.forEach(function(col) {\n      console.log(col.getName(), col.getDataType(), col.isNullable());\n    });\n  });\n});","lang":"javascript","description":"Shows how to connect to PostgreSQL, retrieve database version, list all user tables, and inspect columns for a specific table using callbacks."},"warnings":[{"fix":"npm install pg # or mysql or sqlite3","message":"You must install the database driver (pg, mysql, or sqlite3) separately. They are not included as dependencies.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Always check err: getTables(function(err, tables) { if (err) throw err; ... })","message":"The callback for getTables, getColumns, and other methods follows (err, result) pattern, but older examples may omit the error parameter.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Wrap in a Promise manually or use a library like util.promisify.","message":"The API does not support Promises or async/await. Only callbacks are available.","severity":"deprecated","affected_versions":">=0.0.1"},{"fix":"Use 'pg' instead of 'postgres'.","message":"In version 0.5.0, the driver option 'pg' changed from 'postgres' to 'pg'. Using 'postgres' will cause an error.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Check driver documentation for connection reuse support.","message":"The options object may include a 'connection' key to pass an existing database connection. Not all drivers support this.","severity":"gotcha","affected_versions":">=0.4.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install pg","cause":"The pg driver is not installed.","error":"Error: Cannot find module 'pg'"},{"fix":"Ensure first argument is a valid driver string, second is options object, and third is a callback that accepts (err, meta).","cause":"Using an outdated callback signature that omits the error parameter, or calling dbmeta() with wrong arguments.","error":"TypeError: undefined is not a function"},{"fix":"Use meta.getColumns('tableName', callback), not table.getColumns().","cause":"Calling getColumns on a Table object instead of the meta driver.","error":"Error: getColumns is not a function"},{"fix":"Verify database is running and check host, port, database name, user, password in options.","cause":"Database server is not running or connection options are incorrect.","error":"Error: Connection refused"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}