pg-query-bluebird

Simplified postgres querying with bluebird

Usage no npm install needed!

<script type="module">
  import pgQueryBluebird from 'https://cdn.skypack.dev/pg-query-bluebird';
</script>

README

pg-query-bluebird

Simplified postgres querying with bluebird

Description

Build Status

Run queries with node-postgres with less boilerplate. Similar to pg-query but uses bluebird.

Basic Usage

You'll have to install pg separately

var query = require('pg-query-bluebird');

query('SELECT NOW()')
  .then(function(rows) {
    console.log(rows[0]);
  });

API

Query rows

Promise<Array<Object>> query(String text | Object query | Array<Object> queries, [Array<dynamic> values])

Query the db, returns an array of rows.

Query single row

Promise<Object> query.single(String text | Object query | Array<Object> queries, [Array<dynamic> values])

Query a single row.

Original pg query

Promise<Object> query.raw(String text | Object query | Array<Object> queries, [Array<dynamic> values])

Query the db, returns a full result result.rows,...

Connect

Disposer query.connect([String connStr | Object connParams])

Disposer to use with bluebird's Promise.using. Automatically releases the client back to the pool after use.

var Promise = require('bluebird');
var query = require('pg-query-bluebird');

var CONN_STR = '...';

var rows = Promise.using(query.connect(CONN_STR), function (query) {
  return query('SELECT NOW()');
  // return query.single(...)
  // return query.raw(...)
});

History

1.0.0

  • update to bluebird 3