Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pg-using-bluebird

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-using-bluebird

Helpers for managing PostgreSQL connections

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2K
decreased by-12.81%
Maintainers
2
Weekly downloads
 
Created
Source

pg-using-bluebird

Utility library for promisifying node-postgres using Bluebird promises with Bluebird's resource management functionality.

This project is based on the postgres example in Bluebird's documentation.

Install

npm install pg-using-bluebird

Usage

var Promise = require('bluebird'),
  pgUsingBluebird = require('pg-using-bluebird'),
  db = pgUsingBluebird({dbUrl: "postgres://localhost/pgrm-tests"}),
  using = Promise.using

using(db.getConnection(), function (connection) {
  return connection.queryAsync("select 1").then(function (res) {
    console.log(res.rows)
  })
}).finally(function() {
  db.end()
})

See connection-test.js for more complete examples.

Documentation

Requiring this module returns a function takes a single parameter object with at least the URL to the DB ({dbUrl: "myUrl"}) and returns an object with the following functions:

getConnection() returns a DB connection

getTransaction([tablesToLock]) returns a DB transaction, 1st argument is an optional list of tables to lock

queryRowsAsync(query, [args]) performs a query with the optional argument list inserted into the query. Returns the resulting rows.

createMultipleInsertCTE(insert) creates a common table expression (CTE) for multiple inserts, returns an object with text for the query and values for the arguments.

createUpsertCTE(table, idField, args) creates an upsert query, returns an object with text for the query and values for the arguments.

Alternatives

  • pg-promise, a more generic Promises/A+ promisification of node-postgres with more features and more code. Does not leverage using() for resource management.
  • dbh-pg, a node-postgres and bluebird specific library with it's own api for querying.

FAQs

Package last updated on 16 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc