Skip to content

Commit cdd0846

Browse files
committed
add Pool#query
1 parent fd984a7 commit cdd0846

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/Pool.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ Pool.prototype.end = function (cb) {
107107
}
108108
};
109109

110+
Pool.prototype.query = function (sql, values, cb) {
111+
if (typeof values === 'function') {
112+
cb = values;
113+
values = null;
114+
}
115+
116+
this.getConnection(function (err, conn) {
117+
if (err) return cb(err);
118+
119+
conn.query(sql, values, function () {
120+
conn.end();
121+
cb.apply(this, arguments);
122+
});
123+
});
124+
};
125+
110126
Pool.prototype._createConnection = function() {
111127
var self = this;
112128
var connection = (this.config.createConnection)

test/integration/pool/test-query.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var common = require('../../common');
2+
var assert = require('assert');
3+
var pool = common.createPool();
4+
5+
pool.query('SELECT 1', function (err, _rows, _fields) {
6+
if (err) throw err;
7+
8+
rows = _rows;
9+
fields = _fields;
10+
11+
pool.end();
12+
});
13+
14+
process.on('exit', function () {
15+
assert.deepEqual(rows, [{1: 1}]);
16+
assert.equal(fields[0].name, '1');
17+
});

0 commit comments

Comments
 (0)