-
-
Save rlemon/e8b4605de073276c82f4 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
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