diff --git a/lib/index.js b/lib/index.js index ddb09843..f0641693 100644 --- a/lib/index.js +++ b/lib/index.js @@ -20,6 +20,7 @@ var Client = function(config) { this.host = config.host; this.queryQueue = []; this.stream = config.stream || new net.Stream(); + this.queryQueue = []; }; sys.inherits(Client, EventEmitter); @@ -62,7 +63,10 @@ Client.prototype.disconnect = function() { }; Client.prototype.query = function() { - return new Query(); + var query = new Query(); + query.client = this; + this.queryQueue.push(this); + return query; }; var Query = function() { diff --git a/test/communication-tests.js b/test/communication-tests.js index 3b50cdd8..f4e09bf1 100644 --- a/test/communication-tests.js +++ b/test/communication-tests.js @@ -50,9 +50,17 @@ test('query queue', function() { var stream = new MemoryStream(); stream.readyState = 'open'; var client = new Client({stream: stream}); - client.query('select * from bang'); + test('new client has empty queue', function() { + assert.empty(client.queryQueue); + }); + + test('calling query queues the query object', function() { + var query = client.query('select * from bang'); + assert.length(client.queryQueue, 1); + }); + assert.empty(stream.packets); - + stream.emit('data', buffers.readyForQuery()); - assert.equal(stream.packets.length, 1); + assert.length(stream.packets, 1); });