Skip to content

Instantly share code, notes, and snippets.

@SomeKittens
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SomeKittens/c5e821c2088b1c7ee2fe to your computer and use it in GitHub Desktop.
Save SomeKittens/c5e821c2088b1c7ee2fe to your computer and use it in GitHub Desktop.
'use strict';
var pg = require('pg')
, bluebird = require('bluebird')
, connString = require('./config').pg;
bluebird.promisifyAll(pg);
bluebird.promisifyAll(pg.Client.prototype);
module.exports = function() {
return pg.connectAsync(connString).bind({}).spread(function(client, close) {
this.close = close;
this.client = client;
}).finally(function() {
this.close();
});
};
var getDb = require('./db');
getDb().then(function() {
return this.client.query('SELECT * FROM myTable WHERE pants = NULL');
}).get(rows).get(0).then(function(results) {
// etc
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment