5 Commits

Author SHA1 Message Date
brianc
be7af371d8 Add more versions to the travis test matrix 2016-05-03 13:07:50 -05:00
brianc
17697e98d7 Re-enable old tests 2016-05-03 13:07:29 -05:00
Chris Kinsman
bd4a87d3a0 Remove node 0.10 and add 0.12 2015-12-16 16:58:18 -08:00
Chris Kinsman
9d197a91e1 Add resume 2015-12-16 16:43:22 -08:00
Chris Kinsman
e1ce9a3948 Eliminate detach/reattach strategy as it isn't able to differentiate between on/once and inconsistenly loses unshifted data depending on node version. Instead just split stream and send it to copy stream and the connection.stream at the same time. Disconnecting copy stream just means unpiping. Added handleCopyData to fulfill query contract but ignore the incoming data.
Add node 4.2.2 to Travis
Minimum postgres 9.2 to allow tests to complete in Travis

Remove test that is no longer needed since we no longer disconnect/reconnect listeners
2015-12-16 16:21:13 -08:00
3 changed files with 7 additions and 9 deletions

View File

@@ -39,6 +39,7 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) {
lenBuffer.writeUInt32BE(chunk.length + 4, 0)
this.push(lenBuffer)
this.push(chunk)
this.rowCount++
cb()
}
@@ -57,14 +58,7 @@ CopyStreamQuery.prototype.handleCopyInResponse = function(connection) {
this.pipe(connection.stream)
}
CopyStreamQuery.prototype.handleCommandComplete = function(msg) {
// Parse affected row count as in
// https://github.com/brianc/node-postgres/blob/35e5567f86774f808c2a8518dd312b8aa3586693/lib/result.js#L37
var match = /COPY (\d+)/.exec((msg || {}).text)
if (match) {
this.rowCount = parseInt(match[1], 10)
}
CopyStreamQuery.prototype.handleCommandComplete = function() {
this.unpipe()
this.emit('end')
}

View File

@@ -1,6 +1,6 @@
{
"name": "pg-copy-streams",
"version": "1.1.0",
"version": "0.3.0",
"description": "Low-Level COPY TO and COPY FROM streams for PostgreSQL in JavaScript using",
"main": "index.js",
"scripts": {

View File

@@ -30,6 +30,10 @@ var testRange = function(top) {
var txt = 'COPY numbers FROM STDIN'
var stream = fromClient.query(copy(txt))
var rowEmitCount = 0
stream.on('row', function() {
rowEmitCount++
})
for(var i = 0; i < top; i++) {
stream.write(Buffer('' + i + '\t' + i*10 + '\n'))
}