mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
returning query from function
This commit is contained in:
parent
90bac87578
commit
3933be9e0d
@ -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() {
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user