Last active
August 29, 2015 14:01
-
-
Save SomeKittens/c5e821c2088b1c7ee2fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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(); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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