diff --git a/lib/native.js b/lib/native.js index 16506e2..31143a2 100644 --- a/lib/native.js +++ b/lib/native.js @@ -46,8 +46,8 @@ p.connect = function() { }) } -p.query = function(queryString) { - var q = new NativeQuery(queryString); +p.query = function(config) { + var q = new NativeQuery(config); this._queryQueue.push(q); this._pulseQueryQueue(); return q; @@ -79,7 +79,7 @@ var ctor = function(config) { connection._pulseQueryQueue(); }); - //proxy some events to active query + //proxy some events to active query connection.on('_row', function(row) { connection._activeQuery.emit('row', row); }) @@ -108,7 +108,11 @@ var connect = function(config, callback) { //event emitter proxy var NativeQuery = function(text) { - this.text = text; + if(typeof text == 'object') { + this.text = text.text; + } else { + this.text = text; + } EventEmitter.call(this); }; diff --git a/test/native/evented-api-tests.js b/test/native/evented-api-tests.js index 5d04c3a..ba7282b 100644 --- a/test/native/evented-api-tests.js +++ b/test/native/evented-api-tests.js @@ -39,7 +39,18 @@ test('multiple results', function() { assert.equal(row.name, 'Aaron'); assert.emits(q, 'row', function(row) { assert.equal(row.name, "Brian"); - client.end(); + + }) + }) + assert.emits(q, 'end', function() { + test('query with config', function() { + var q = client.query({text:'SELECT 1 as num'}); + assert.emits(q, 'row', function(row) { + assert.strictEqual(row.num, 1); + assert.emits(q, 'end', function() { + client.end(); + }) + }) }) }) })