pg-connect

2.0.2 • Public • Published

DEPRECATED

As of pg@6, node-postgres has promise suport out of the box. Do not use this package. It is no longer maintained!

pg-connect

js-standard-style Circle CI Dependency Status

Connect to a postgres database with a promise api. Pretty much just an implementation of the suggestions in the bluebird api

Installation

npm install --save pg-connect

Usage

var Promise = require('bluebird')
var getConnection = require('pg-connect')(connectionString)
 
Promise.using(
  getConnection(),
  function (query) {
    return query('SELECT * from foo')
  }
).
then(function (results) {
  // ... use the results
})

where query is a promisified version of client.query in pg.

An example with transactions:

var Promise = require('bluebird')
var getConnection = require('pg-connect')(connectionString)
 
getConnection.withTransaction(function (query) {
  return query('SELECT * from foo')
}).
then(function (results) {
  // ... use the results
})

Also, getConnection.end is equivalent to pg.end. Similarly, getConnection.defaults is equivalent to pg.defauts.

Testing

  1. Ensure you have a local postgres database named pg_connect_test or export DATABASE_URL pointing to a database.
  2. npm test

/pg-connect/

    Package Sidebar

    Install

    npm i pg-connect

    Weekly Downloads

    58

    Version

    2.0.2

    License

    MIT

    Last publish

    Collaborators

    • rahulbharadwaj
    • jasif-wm
    • shyam.mohan
    • qbibrahim
    • sidharth.n
    • hariqb
    • arjuncprasannan
    • renjith_ram_qburst
    • anasqburst
    • jyothis-qb
    • qburst-pratyush
    • cdrohithmqb
    • sudheeshqburst
    • davoodul
    • mable-liza-mathew
    • sowmyab
    • anoop-kuttikkattu
    • munisa
    • dheerajds
    • arjunqb
    • ashishqburst
    • lanetix-system
    • manu-kodiyan-winmore
    • dnm-winmore
    • mkdyanugk
    • vigneshk7
    • soumyaarun
    • aswanth
    • sajith.qb
    • dhiluraj-qburst
    • anandqb
    • arun-dtk
    • vikasqb
    • acpradosh1234
    • apechimp