{"id":42614,"library":"dbh-pg","title":"dbh-pg","description":"Lightweight Database Handler for PostgreSQL built on top of node-postgres (pg) and bluebird promises. Provides a thin wrapper around pg's connection pool with promise-based methods for common database operations, transactions, and query shorthands. Current version 3.0.0. The library simplifies common tasks like transactions and connection lifecycle management using bluebird's Promise.using pattern. Compared to raw pg, it reduces boilerplate for queries and transactions but adds a dependency on bluebird. Suitable for projects already using bluebird or wanting a minimal promise-based interface over pg.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/sapienlab/dbh-pg","tags":["javascript","pg","database","db","dbh","then","promise","postgres","PostgreSQL"],"install":[{"cmd":"npm install dbh-pg","lang":"bash","label":"npm"},{"cmd":"yarn add dbh-pg","lang":"bash","label":"yarn"},{"cmd":"pnpm add dbh-pg","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Transaction handling and Promise.using require bluebird; strongly recommended","package":"bluebird","optional":true},{"reason":"Core PostgreSQL driver; required for database access","package":"pg","optional":false}],"imports":[{"note":"Default export, not named. ESM/CJS both work due to dual package.","wrong":"const { DBH } = require('dbh-pg')","symbol":"DBH","correct":"import DBH from 'dbh-pg'"},{"note":"CJS: use require directly; no .default needed.","wrong":"const dbh = require('dbh-pg').default","symbol":"DBH","correct":"const DBH = require('dbh-pg')"},{"note":"DBH expects bluebird Promise; native Promise may work but not guaranteed.","wrong":"const Promise = global.Promise","symbol":"Promise (bluebird)","correct":"const Promise = require('bluebird')"}],"quickstart":{"code":"const DBH = require('dbh-pg');\nconst Promise = require('bluebird');\nconst using = Promise.using;\n\nconst db = new DBH('postgres://user:password@localhost/mydb');\n\nusing(db.conn(), function(conn) {\n  return conn.fetchOne('SELECT * FROM users WHERE id = $1', [1])\n    .then(user => {\n      console.log(user);\n    });\n});\n\n// Transaction example:\nusing(db.conn(), function(conn) {\n  return conn\n    .begin()\n    .then(function() {\n      return this.exec('UPDATE accounts SET balance = balance - 100 WHERE id = $1', [1]);\n    })\n    .then(function() {\n      return this.exec('UPDATE accounts SET balance = balance + 100 WHERE id = $1', [2]);\n    })\n    .then(function() {\n      return this.commit();\n    });\n});","lang":"javascript","description":"Shows basic connection usage with fetchOne and a transaction using begin/commit."},"warnings":[{"fix":"Install bluebird: npm install bluebird and require it.","message":"Requires bluebird for Promise.using; native Promise.using does not exist.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always call .commit() after successful transaction, or handle rollback explicitly.","message":"conn.commit() must be called explicitly; otherwise auto-rollback on connection release.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use bluebird promises or async/await with bluebird's Promise.promisifyAll.","message":"Version 2.x dropped support for callbacks; promises only.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use conn.exec and conn.commit directly.","message":"Static methods DBH.exec, DBH.commit etc. are less idiomatic; prefer instance methods.","severity":"deprecated","affected_versions":">=3.0.0"}],"env_vars":null,"search_vec":"'3.0.0':44 'add':73 'alreadi':81 'around':24 'base':32,90 'bluebird':18,57,77,83 'boilerpl':67 'built':9 'common':35,48 'compar':61 'connect':27,53 'current':42 'databas':5,36,96 'db':97 'dbh':2,98 'dbh-pg':1 'depend':75 'handler':6 'interfac':91 'javascript':94 'librari':46 'lifecycl':54 'lightweight':4 'like':50 'manag':55 'method':33 'minim':87 'node':14 'node-postgr':13 'oper':37 'pattern':60 'pg':3,16,25,64,93,95 'pool':28 'postgr':15,101 'postgresql':8,102 'project':80 'promis':19,31,89,100 'promise-bas':30,88 'promise.using':59 'provid':20 'queri':40,69 'raw':63 'reduc':66 'shorthand':41 'simplifi':47 'suitabl':78 'task':49 'thin':22 'top':11 'transact':38,51,71 'use':56,82 'version':43 'want':85 'wrapper':23","created_at":"2026-06-05T16:55:49.417124+00:00","updated_at":"2026-06-05T16:55:49.417124+00:00","problems":[{"fix":"Run `npm install dbh-pg` and ensure node_modules contains it.","cause":"Package not installed or incorrect import path.","error":"Cannot find module 'dbh-pg'"},{"fix":"Install bluebird and use `const Promise = require('bluebird');` before using `Promise.using`.","cause":"Using native Promise instead of bluebird.","error":"Promise.using is not a function"},{"fix":"Verify PostgreSQL is running and connection string is correct (postgres://user:pass@host/db).","cause":"Database server not running or connection string incorrect.","error":"Error: Connection terminated unexpectedly"},{"fix":"Wrap db.conn() inside `Promise.using(db.conn(), function(conn) { ... });`.","cause":"Trying to call .then on a disposer object; must use Promise.using.","error":"TypeError: db.conn(...).then is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/sapienlab/dbh-pg#readme","github":"https://github.com/sapienlab/dbh-pg","docs":null,"changelog":null,"pypi":null,"npm":"dbh-pg","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}