From 2f5b37e0ad1579ce3696fbf09ff130efab14862c Mon Sep 17 00:00:00 2001 From: "Brian M. Carlson" Date: Mon, 28 Oct 2013 21:50:45 -0500 Subject: [PATCH] Do not emit row event --- copy-to.js | 3 ++- index.js | 3 ++- test/copy-from.js | 2 +- test/copy-to.js | 6 +----- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/copy-to.js b/copy-to.js index 2a6bef2..891aea3 100644 --- a/copy-to.js +++ b/copy-to.js @@ -10,6 +10,7 @@ var CopyStreamQuery = function(text) { this.text = text this._listeners = null this._copyOutResponse = null + this.rowCount = 0 } util.inherits(CopyStreamQuery, Transform) @@ -78,7 +79,7 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) { var slice = chunk.slice(offset, offset + length) offset += length this.push(slice) - this.emit('row') + this.rowCount++ } else { break; } diff --git a/index.js b/index.js index e545e4d..858b48d 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,7 @@ var CopyStreamQuery = function(text) { this.text = text this._listeners = null this._copyOutResponse = null + this.rowCount = 0 } util.inherits(CopyStreamQuery, Transform) @@ -39,7 +40,7 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) { lenBuffer.writeUInt32BE(chunk.length + 4, 0) this.push(lenBuffer) this.push(chunk) - this.emit('row') + this.rowCount++ cb() } diff --git a/test/copy-from.js b/test/copy-from.js index e4398ee..1f5bd68 100644 --- a/test/copy-from.js +++ b/test/copy-from.js @@ -36,7 +36,7 @@ var testRange = function(top) { console.log('found ', res.rows.length, 'rows') countDone() var firstRowDone = gonna('have correct result') - assert.equal(rowEmitCount, top, 'should have emitted "row" event ' + top + ' times') + assert.equal(stream.rowCount, top, 'should have rowCount ' + top + ' ') fromClient.query('SELECT (max(num)) AS num FROM numbers', function(err, res) { assert.ifError(err) assert.equal(res.rows[0].num, top-1) diff --git a/test/copy-to.js b/test/copy-to.js index 16b1c31..2d99f0b 100644 --- a/test/copy-to.js +++ b/test/copy-to.js @@ -18,10 +18,6 @@ var testRange = function(top) { var txt = 'COPY (SELECT * from generate_series(0, ' + (top - 1) + ')) TO STDOUT' var stream = fromClient.query(copy(txt)) - var rowEmitCount = 0 - stream.on('row', function() { - rowEmitCount++ - }) var done = gonna('finish piping out', 1000, function() { fromClient.end() }) @@ -30,7 +26,7 @@ var testRange = function(top) { var res = buf.toString('utf8') var expected = _.range(0, top).join('\n') + '\n' assert.equal(res, expected) - assert.equal(rowEmitCount, top, 'should have emitted "row" ' + top + ' times but got ' + rowEmitCount) + assert.equal(stream.rowCount, top, 'should have rowCount ' + top + ' but got ' + stream.rowCount) done() })) }