Registry / database / pg-connect

pg-connect

JSON →
library2.0.2jsnpmunverified

Deprecated wrapper around node-postgres that provides a promise-based API for database connections and transactions, automatically releasing them via Bluebird's disposer pattern. Last version 2.0.2. Since pg@6 (2016), node-postgres natively supports promises, making this package obsolete. No longer maintained. Users should migrate to direct use of pg with async/await.

npm install pg-connect
INSTALL
IMPORT
SIG · PG-CONNECT
P
pg-connect
databasejavascriptv2.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
const getConnection = require('pg-connect')(connectionString)
import getConnection from 'pg-connect'
This package is CommonJS only and returns a function that expects a connection string; ESM import will fail. Use require() for the factory.
withTransaction
getConnection.withTransaction(function(query) { ... })
getConnection.withTransaction()
withTransaction is a method on the factory's return value, not on the module. It requires a callback as argument.
end
getConnection.end()
require('pg-connect').end()
end is on the factory instance, not on the module export.

Demonstrates creating a connection and running a simple query using Promise.using to auto-release.

const Promise = require('bluebird'); const getConnection = require('pg-connect')(process.env.DATABASE_URL ?? ''); Promise.using( getConnection(), function (query) { return query('SELECT NOW()') .then(function(result) { console.log(result.rows[0].now); }); } ).then(function() { console.log('Connection released'); }).catch(function(err) { console.error(err); });
Debug
Known issues
deprecatedPackage is deprecated since pg@6 introduced native promise support.
fix
Use pg directly with pg.Pool and async/await.
affects: >=2.0.2
breakingRequires Bluebird for Promise.using — native Promise does not support .using.
fix
Install bluebird and use it as the Promise implementation.
affects: >=1.0.0
gotchaThe module export is a factory function, not a connection instance. Call it with a connection string before use.
fix
const getConnection = require('pg-connect')(connectionString);
affects: >=1.0.0
gotchaDoes not support ESM. Using import will throw an error.
fix
Use require() or set type: 'commonjs' in package.json.
affects: >=1.0.0
Errors
Common errors & fixes
Unhandled rejection: TypeError: Promise.using is not a function
Native Promise does not have a .using method; Bluebird is required.
fix
npm install bluebird and require('bluebird') before using pg-connect.
TypeError: getConnection is not a function
The import was done without calling the factory with a connection string.
fix
const getConnection = require('pg-connect')(connectionString);
Error: Cannot find module 'pg'
pg is a peer dependency not automatically installed.
fix
npm install pg
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
pgrequiredRuntime dependency for PostgreSQL client
bluebirdrequiredProvides Promise.using and disposer pattern
Agent activity
5 hits · last 30 days
node
4
Resources
pg-connect — npm install pg-connect · libregistry