Skip to content

Commit ca9b3cb

Browse files
committed
can pass config object to native query
1 parent 569f760 commit ca9b3cb

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

lib/native.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ p.connect = function() {
4646
})
4747
}
4848

49-
p.query = function(queryString) {
50-
var q = new NativeQuery(queryString);
49+
p.query = function(config) {
50+
var q = new NativeQuery(config);
5151
this._queryQueue.push(q);
5252
this._pulseQueryQueue();
5353
return q;
@@ -79,7 +79,7 @@ var ctor = function(config) {
7979
connection._pulseQueryQueue();
8080
});
8181

82-
//proxy some events to active query
82+
//proxy some events to active query
8383
connection.on('_row', function(row) {
8484
connection._activeQuery.emit('row', row);
8585
})
@@ -108,7 +108,11 @@ var connect = function(config, callback) {
108108

109109
//event emitter proxy
110110
var NativeQuery = function(text) {
111-
this.text = text;
111+
if(typeof text == 'object') {
112+
this.text = text.text;
113+
} else {
114+
this.text = text;
115+
}
112116
EventEmitter.call(this);
113117
};
114118

test/native/evented-api-tests.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,18 @@ test('multiple results', function() {
3939
assert.equal(row.name, 'Aaron');
4040
assert.emits(q, 'row', function(row) {
4141
assert.equal(row.name, "Brian");
42-
client.end();
42+
43+
})
44+
})
45+
assert.emits(q, 'end', function() {
46+
test('query with config', function() {
47+
var q = client.query({text:'SELECT 1 as num'});
48+
assert.emits(q, 'row', function(row) {
49+
assert.strictEqual(row.num, 1);
50+
assert.emits(q, 'end', function() {
51+
client.end();
52+
})
53+
})
4354
})
4455
})
4556
})

0 commit comments

Comments
 (0)