support for limiting number of rows returned at a time from a cursor

This commit is contained in:
Brian Carlson 2010-11-14 17:53:49 -06:00
parent e61ec5dfed
commit ebf5c5c4ed
2 changed files with 43 additions and 14 deletions

View File

@ -61,7 +61,7 @@ p.submit = function(connection) {
};
var onReadyForQuery = function() {
//remove all listeners
//remove all listeners
connection.removeListener('rowDescription', handleRowDescription);
connection.removeListener('dataRow', handleDatarow);
connection.removeListener('readyForQuery', onReadyForQuery);
@ -110,29 +110,28 @@ p.prepare = function(connection) {
name: self.name || ""
});
//TODO test for & support multpile row requests
connection.execute({
portal: self.name,
rows: self.rows
});
var getRows = function() {
connection.execute({
portal: self.name,
rows: self.rows
});
connection.flush();
};
connection.flush();
getRows();
//TODO support EmptyQueryResponse, ErrorResponse, and PortalSuspended
var onCommandComplete = function() {
connection.removeListener('error', onError);
connection.removeListener('error', onCommandComplete);
connection.removeListener('commandComplete', onCommandComplete);
connection.removeListener('portalSuspended', getRows);
connection.sync();
};
var onError = function() {
connection.removeListener('error', onError);
connection.removeListener('commandComplete', onCommandComplete);
connection.sync();
};
connection.on('portalSuspended', getRows);
connection.on('commandComplete', onCommandComplete);
connection.on('error', onError);
connection.on('error', onCommandComplete);
};
var dateParser = function(isoDate) {

View File

@ -152,3 +152,33 @@ test("prepared statements on different clients", function() {
});
test('prepared statement', function() {
var client = helper.client();
client.on('drain', client.end.bind(client));
client.query('CREATE TEMP TABLE zoom(name varchar(100));');
client.query("INSERT INTO zoom (name) VALUES ('zed')");
client.query("INSERT INTO zoom (name) VALUES ('postgres')");
client.query("INSERT INTO zoom (name) VALUES ('node postgres')");
test('with small row count', function() {
var q = client.query({
name: 'get names',
text: "SELECT name FROM zoom ORDER BY name",
rows: 1
});
test('row callback fires for each result', function() {
assert.emits(q, 'row', function(row) {
assert.equal(row.name, 'node postgres');
assert.emits(q, 'row', function(row) {
assert.equal(row.name, 'postgres');
assert.emits(q, 'row', function(row) {
assert.equal(row.name, 'zed');
})
});
})
})
})
})