Skip to content

Instantly share code, notes, and snippets.

@kbariotis
Last active August 29, 2015 14:17
Show Gist options
  • Save kbariotis/cf17629673dc033daac9 to your computer and use it in GitHub Desktop.
Save kbariotis/cf17629673dc033daac9 to your computer and use it in GitHub Desktop.
Wrapper around node-postgres
var BPromise = require('bluebird'),
pg = require('pg');
function Postgres(opts) {
this.host = opts.host;
}
Postgres.prototype.query = function(sql) {
return new BPromise(function(resolve, reject){
var opts = { host: this.host };
pg.connect(opts, function(err, client, done) {
var queryCallback = function(err, ret) {
if (err) {
reject(new Error(err));
} else {
done();
resolve();
}
};
if (err) {
reject(new Error(err));
} else {
client.query(sql, queryCallback)
}
});
})
};
module.exports = Postgres;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment