Last active
August 29, 2015 14:17
-
-
Save kbariotis/cf17629673dc033daac9 to your computer and use it in GitHub Desktop.
Wrapper around node-postgres
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 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