diff --git a/index.js b/index.js index ee09dc81..042d697b 100644 --- a/index.js +++ b/index.js @@ -83,13 +83,16 @@ Pool.prototype.connect = function (cb) { Pool.prototype.take = Pool.prototype.connect -Pool.prototype.query = function (text, values) { +Pool.prototype.query = function (text, values, cb) { return new this.Promise(function (resolve, reject) { this.connect(function (err, client, done) { if (err) return reject(err) client.query(text, values, function (err, res) { done(err) err ? reject(err) : resolve(res) + if (cb) { + cb(err, res) + } }) }) }.bind(this)) diff --git a/test/index.js b/test/index.js index 956f15cc..a7772b61 100644 --- a/test/index.js +++ b/test/index.js @@ -32,6 +32,16 @@ describe('pool', function () { }) }) + it('can run a query with a callback', function (done) { + const pool = new Pool() + pool.query('SELECT $1::text as name', ['brianc'], function (err, res) { + expect(res.rows[0]).to.eql({ name: 'brianc' }) + pool.end(function () { + done(err) + }) + }) + }) + it('removes client if it errors in background', function (done) { const pool = new Pool() pool.connect(function (err, client, release) {