Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created January 6, 2016 14:42
Show Gist options
  • Save rlemon/e8b4605de073276c82f4 to your computer and use it in GitHub Desktop.
Save rlemon/e8b4605de073276c82f4 to your computer and use it in GitHub Desktop.
import pg from 'pg';
import bluebird from 'bluebird';
import configs from './configs';
bluebird.longStackTraces();
bluebird.promisifyAll(pg);
bluebird.promisifyAll(pg.Client.prototype);
export default function(fn) {
return pg.connectAsync(config.connstr).bind({}).spread((client, close) => {
this.closeConnection = close;
return fn(client);
}).finally(()=>{
this.closeConnection();
});
}
////
import db from './db';
db(client=> {
return client.queryAsync(...);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment