Compare commits
12 Commits
master
...
v1.2.0-car
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f1d5cb4a5 | ||
|
|
99d397956c | ||
|
|
c85f7d27b8 | ||
|
|
8b355b6e72 | ||
|
|
d7e5c1383f | ||
|
|
cb2227d159 | ||
|
|
7930d1b8dd | ||
|
|
e94fefe902 | ||
|
|
9293926047 | ||
|
|
fd3cc95573 | ||
|
|
922627daaf | ||
|
|
61bc713e0c |
18
NEWS.carto.md
Normal file
18
NEWS.carto.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# CARTO's Changelog
|
||||
|
||||
## v1.2.0-carto.2
|
||||
Released 2018-10-26
|
||||
|
||||
Bug fixes:
|
||||
* Make all modules to use strict mode semantics.
|
||||
|
||||
## v1.2.0-carto.1
|
||||
Released 2018-06-11
|
||||
|
||||
Bug fixes:
|
||||
* Improves performance of COPY TO by sending bigger chunks through low level `push()`. See https://github.com/CartoDB/node-pg-copy-streams/pull/1
|
||||
|
||||
## v1.2.0
|
||||
Released 2016-08-22
|
||||
|
||||
Vanilla version v1.2.0 from upstream repository. See https://github.com/CartoDB/node-pg-copy-streams/releases/tag/v1.2.0
|
||||
20
copy-to.js
20
copy-to.js
@@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(txt, options) {
|
||||
return new CopyStreamQuery(txt, options)
|
||||
}
|
||||
@@ -42,6 +44,16 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) {
|
||||
var messageCode;
|
||||
var needPush = false;
|
||||
|
||||
var buffer = Buffer.alloc(chunk.length);
|
||||
var buffer_offset = 0;
|
||||
|
||||
this.pushBufferIfneeded = function() {
|
||||
if (needPush && buffer_offset > 0) {
|
||||
this.push(buffer.slice(0, buffer_offset))
|
||||
buffer_offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
while((chunk.length - offset) >= (Byte1Len + Int32Len)) {
|
||||
var messageCode = chunk[offset]
|
||||
|
||||
@@ -67,9 +79,10 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) {
|
||||
case code.NoticeResponse:
|
||||
case code.NotificationResponse:
|
||||
break;
|
||||
|
||||
|
||||
case code.ErrorResponse:
|
||||
case code.CopyDone:
|
||||
this.pushBufferIfneeded();
|
||||
this._detach()
|
||||
this.push(null)
|
||||
return cb();
|
||||
@@ -84,7 +97,8 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) {
|
||||
if (needPush) {
|
||||
var row = chunk.slice(offset, offset + length - Int32Len)
|
||||
this.rowCount++
|
||||
this.push(row)
|
||||
row.copy(buffer, buffer_offset);
|
||||
buffer_offset += row.length;
|
||||
}
|
||||
offset += (length - Int32Len)
|
||||
} else {
|
||||
@@ -93,6 +107,8 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) {
|
||||
}
|
||||
}
|
||||
|
||||
this.pushBufferIfneeded();
|
||||
|
||||
if(chunk.length - offset) {
|
||||
var slice = chunk.slice(offset)
|
||||
this._remainder = slice
|
||||
|
||||
2
index.js
2
index.js
@@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var CopyToQueryStream = require('./copy-to')
|
||||
module.exports = {
|
||||
to: function(txt, options) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pg-copy-streams",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.0-carto.2",
|
||||
"description": "Low-Level COPY TO and COPY FROM streams for PostgreSQL in JavaScript using",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert')
|
||||
var gonna = require('gonna')
|
||||
|
||||
@@ -19,7 +21,7 @@ var testBinaryCopy = function() {
|
||||
var fromClient = client()
|
||||
var toClient = client()
|
||||
|
||||
queries = [
|
||||
var queries = [
|
||||
'DROP TABLE IF EXISTS data',
|
||||
'CREATE TABLE IF NOT EXISTS data (num BIGINT, word TEXT)',
|
||||
'INSERT INTO data (num, word) VALUES (1, \'hello\'), (2, \'other thing\'), (3, \'goodbye\')',
|
||||
@@ -33,7 +35,7 @@ var testBinaryCopy = function() {
|
||||
var fromStream = fromClient.query(to('COPY (SELECT * FROM data) TO STDOUT BINARY'))
|
||||
var toStream = toClient.query(from('COPY data_copy FROM STDIN BINARY'))
|
||||
|
||||
runStream = function(callback) {
|
||||
var runStream = function(callback) {
|
||||
fromStream.on('error', callback)
|
||||
toStream.on('error', callback)
|
||||
toStream.on('finish', callback)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert')
|
||||
var gonna = require('gonna')
|
||||
|
||||
@@ -68,6 +70,6 @@ var testSingleEnd = function() {
|
||||
if (count == 1) fromClient.end();
|
||||
})
|
||||
stream.end(Buffer('1\n'))
|
||||
|
||||
|
||||
}
|
||||
testSingleEnd()
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert')
|
||||
var gonna = require('gonna')
|
||||
|
||||
@@ -29,7 +31,7 @@ var testComparators = function() {
|
||||
assert(copy1._gotCopyOutResponse, 'should have received CopyOutResponse')
|
||||
assert(!copy1._remainder, 'Message with no additional data (len=Int4Len+0) should not leave a remainder')
|
||||
}))
|
||||
copy1.end(new Buffer([code.CopyOutResponse, 0x00, 0x00, 0x00, 0x04]));
|
||||
copy1.end(new Buffer([code.CopyOutResponse, 0x00, 0x00, 0x00, 0x04]));
|
||||
|
||||
|
||||
}
|
||||
@@ -104,8 +106,8 @@ var testNoticeResponse = function() {
|
||||
stream.on('data', function(data) {
|
||||
})
|
||||
stream.on('error', callback)
|
||||
|
||||
// make sure stream is pulled from
|
||||
|
||||
// make sure stream is pulled from
|
||||
stream.pipe(concat(callback.bind(null,null)))
|
||||
}
|
||||
|
||||
@@ -118,5 +120,3 @@ var testNoticeResponse = function() {
|
||||
}
|
||||
|
||||
testNoticeResponse();
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
require('./copy-from')
|
||||
require('./copy-to')
|
||||
require('./binary')
|
||||
|
||||
Reference in New Issue
Block a user