From ac438e8952fca2f1de551775f292f328011f4b5e Mon Sep 17 00:00:00 2001 From: Frederick Stark Date: Fri, 12 Feb 2016 13:37:49 +1100 Subject: [PATCH 1/2] Add integration test for Result.addRow --- test/integration/client/simple-query-tests.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/integration/client/simple-query-tests.js b/test/integration/client/simple-query-tests.js index f8ef1adad..c311193b7 100644 --- a/test/integration/client/simple-query-tests.js +++ b/test/integration/client/simple-query-tests.js @@ -36,6 +36,27 @@ test("simple query interface", function() { }); }); +test("simple query interface using addRow", function() { + + var client = helper.client(); + + var query = client.query("select name from person order by name"); + + client.on('drain', client.end.bind(client)); + + query.on('row', function(row, result) { + assert.ok(result); + result.addRow(row); + }); + + query.on('end', function(result) { + assert.lengthIs(result.rows, 26, "result returned wrong number of rows"); + assert.lengthIs(result.rows, result.rowCount); + assert.equal(result.rows[0].name, "Aaron"); + assert.equal(result.rows[25].name, "Zanzabar"); + }); +}); + test("multiple simple queries", function() { var client = helper.client(); client.query({ text: "create temp table bang(id serial, name varchar(5));insert into bang(name) VALUES('boom');"}) From b78a508420a33a31dffebee1d2ea025a8503993b Mon Sep 17 00:00:00 2001 From: Frederick Stark Date: Fri, 12 Feb 2016 13:38:38 +1100 Subject: [PATCH 2/2] Add function stub to native result to solve broken test --- lib/native/result.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/native/result.js b/lib/native/result.js index 485f36b46..9fd23f52c 100644 --- a/lib/native/result.js +++ b/lib/native/result.js @@ -19,3 +19,10 @@ NativeResult.prototype.addCommandComplete = function(pq) { }); } }; + +NativeResult.prototype.addRow = function(row) { + // This is empty to ensure pg code doesn't break when switching to pg-native + // pg-native loads all rows into the final result object by default. + // This is because libpg loads all rows into memory before passing the result + // to pg-native. +};