pg-query-bluebird
v1.0.0
Published
Simplified postgres querying with bluebird
Downloads
9
Readme
pg-query-bluebird
Simplified postgres querying with bluebird
Description
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