pg-copy-streams-binary
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -36,2 +36,12 @@ const ieee754 = require('ieee754') | ||
// int8 | ||
const int8send = function (buf, value) { | ||
const tbuf = Buffer.allocUnsafe(8) | ||
tbuf.writeBigInt64BE(value) | ||
buf.put(tbuf) | ||
} | ||
const int8recv = function (buf) { | ||
return buf.readBigInt64BE(0) | ||
} | ||
// text | ||
@@ -201,2 +211,3 @@ const textsend = function (buf, value) { | ||
int4: { oid: 23, send: int4send, recv: int4recv }, | ||
int8: { oid: 20, send: int8send, recv: int8recv }, | ||
text: { oid: 25, send: textsend, recv: textrecv }, | ||
@@ -213,2 +224,3 @@ varchar: { oid: 1043, send: varcharsend, recv: varcharrecv }, | ||
_int4: { oid: 1007, send: array_send.bind(null, 'int4'), recv: array_recv }, | ||
_int8: { oid: 1016, send: array_send.bind(null, 'int8'), recv: array_recv }, | ||
_text: { oid: 1009, send: array_send.bind(null, 'text'), recv: array_recv }, | ||
@@ -215,0 +227,0 @@ _varchar: { oid: 1015, send: array_send.bind(null, 'varchar'), recv: array_recv }, |
{ | ||
"name": "pg-copy-streams-binary", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Streams for parsing and deparsing the COPY binary format", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -285,3 +285,3 @@ ## pg-copy-streams-binary | ||
- bytea | ||
- int2, int4 | ||
- int2, int4, int8 | ||
- float4, float8 | ||
@@ -300,4 +300,8 @@ - text | ||
### version 2.1.1 - published 2021-08-25 | ||
### version 2.2.0 - published 2021-09-13 | ||
- Add int8 type support (usage requires node version 10.20+) | ||
### version 2.1.0 - published 2021-08-25 | ||
- Add varchar type support | ||
@@ -304,0 +308,0 @@ |
const assert = require('assert') | ||
const pg = require('pg') | ||
const { fieldReader } = require('../') | ||
@@ -7,9 +6,4 @@ const { to: copyTo } = require('pg-copy-streams') | ||
const concat = require('concat-stream') | ||
const { getClient } = require('./utils') | ||
const getClient = function () { | ||
const client = new pg.Client() | ||
client.connect() | ||
return client | ||
} | ||
const samples = { | ||
@@ -19,2 +13,3 @@ bool: [null, true, false], | ||
int4: [2938, null, -99283], | ||
int8: [BigInt(2938), null, BigInt(-99283)], | ||
text: ['aaa', 'ééé', null], | ||
@@ -21,0 +16,0 @@ json: [JSON.stringify({}), JSON.stringify([1, 2]), null], |
const assert = require('assert') | ||
const pg = require('pg') | ||
const { rawReader } = require('../') | ||
const { to: copyTo } = require('pg-copy-streams') | ||
const concat = require('concat-stream') | ||
const { getClient } = require('./utils') | ||
const getClient = function () { | ||
const client = new pg.Client() | ||
client.connect() | ||
return client | ||
} | ||
describe('integration test - rawReader', () => { | ||
@@ -14,0 +8,0 @@ it('stream all raw bytes / small fields including empty and null', (done) => { |
const assert = require('assert') | ||
const pg = require('pg') | ||
const { rowReader } = require('../') | ||
@@ -7,9 +6,4 @@ const { to: copyTo } = require('pg-copy-streams') | ||
const concat = require('concat-stream') | ||
const { getClient } = require('./utils') | ||
const getClient = function () { | ||
const client = new pg.Client() | ||
client.connect() | ||
return client | ||
} | ||
const samples = { | ||
@@ -20,2 +14,3 @@ bool: [null, true, false], | ||
int4: [2938, null, -99283], | ||
int8: [BigInt(2938), null, BigInt(-99283)], | ||
text: ['aaa', 'ééé', null], | ||
@@ -22,0 +17,0 @@ json: [JSON.stringify({}), JSON.stringify([1, 2]), null], |
const assert = require('assert') | ||
const util = require('util') | ||
const pg = require('pg') | ||
const { rowWriter } = require('../') | ||
const { from: copyFrom } = require('pg-copy-streams') | ||
const { getClient } = require('./utils') | ||
const getClient = function () { | ||
const client = new pg.Client() | ||
client.connect() | ||
return client | ||
} | ||
describe('integration test - copyIn', () => { | ||
@@ -60,2 +54,19 @@ it('ingesting an empty flow should not trigger an error', (done) => { | ||
], | ||
['int8', 0, null, null], | ||
['int8', 0, BigInt('501007199254740991'), '501007199254740991'], | ||
[ | ||
'int8', | ||
1, | ||
[BigInt('501007199254740991'), BigInt('501007199254740999')], | ||
'{501007199254740991,501007199254740999}', | ||
], | ||
[ | ||
'int8', | ||
2, | ||
[ | ||
[BigInt('501007199254740991'), BigInt('501007199254740999')], | ||
[BigInt('501007199254740993'), BigInt('501007199254740994')], | ||
], | ||
'{{501007199254740991,501007199254740999},{501007199254740993,501007199254740994}}', | ||
], | ||
['float4', 0, 0.2736, '0.2736'], | ||
@@ -62,0 +73,0 @@ ['float4', 0, 2.928e27, '2.928e+27'], |
@@ -10,2 +10,8 @@ const pgtypes = require('../lib/pg_types') | ||
function makeBigIntBuffer(value) { | ||
const buf = Buffer.alloc(8) | ||
buf.writeBigInt64BE(BigInt(value)) | ||
return buf | ||
} | ||
module.exports = [ | ||
@@ -29,2 +35,8 @@ // simple types | ||
{ t: 'int4', v: 128, r: new BP().word32be(4).word32be(128).buffer() }, | ||
{ t: 'int8', v: null, r: new BP().word32be(-1).buffer() }, | ||
{ | ||
t: 'int8', | ||
v: BigInt('128'), | ||
r: new BP().word32be(8).put(makeBigIntBuffer('128')).buffer(), | ||
}, | ||
{ t: 'text', v: null, r: new BP().word32be(-1).buffer() }, | ||
@@ -154,2 +166,28 @@ { t: 'text', v: 'hello', r: new BP().word32be(5).put(Buffer.from('hello')).buffer() }, | ||
}, | ||
{ t: '_int8', v: null, r: new BP().word32be(-1).buffer() }, | ||
{ | ||
t: '_int8', | ||
v: [ | ||
[BigInt('1'), BigInt('2')], | ||
[BigInt('3'), BigInt('4')], | ||
], | ||
r: new BP() | ||
.word32be(76) | ||
.word32be(2) | ||
.word32be(0) | ||
.word32be(types['int8'].oid) | ||
.word32be(2) | ||
.word32be(1) | ||
.word32be(2) | ||
.word32be(1) | ||
.word32be(8) | ||
.put(makeBigIntBuffer('1')) | ||
.word32be(8) | ||
.put(makeBigIntBuffer('2')) | ||
.word32be(8) | ||
.put(makeBigIntBuffer('3')) | ||
.word32be(8) | ||
.put(makeBigIntBuffer('4')) | ||
.buffer(), | ||
}, | ||
{ t: '_bytea', v: null, r: new BP().word32be(-1).buffer() }, | ||
@@ -156,0 +194,0 @@ { |
const assert = require('assert') | ||
const async = require('async') | ||
const pg = require('pg') | ||
const { to: pgCopyTo, from: pgCopyFrom } = require('pg-copy-streams') | ||
const through2 = require('through2') | ||
const { getClient } = require('./utils') | ||
const { transform } = require('../') | ||
const getClient = function (dsn) { | ||
const client = new pg.Client(dsn) | ||
client.connect() | ||
return client | ||
} | ||
describe('integration test - transform', () => { | ||
@@ -17,0 +11,0 @@ it('should correclty extract, transform and load data', (done) => { |
68770
23
1639
377