Merge branch 'master' of ssh://github.com/brianc/node-pg-copy-streams

This commit is contained in:
jeromew 2019-03-15 12:27:54 +00:00
commit 2af7ce57b1

View File

@ -20,10 +20,12 @@ If you're not familiar with the feature (I wasn't either) you can read this for
### pipe from a table to stdout ### pipe from a table to stdout
```js ```js
var pg = require('pg'); var {Pool} = require('pg');
var copyTo = require('pg-copy-streams').to; var copyTo = require('pg-copy-streams').to;
pg.connect(function(err, client, done) { var pool = new Pool();
pool.connect(function(err, client, done) {
var stream = client.query(copyTo('COPY my_table TO STDOUT')); var stream = client.query(copyTo('COPY my_table TO STDOUT'));
stream.pipe(process.stdout); stream.pipe(process.stdout);
stream.on('end', done); stream.on('end', done);
@ -35,10 +37,12 @@ pg.connect(function(err, client, done) {
```js ```js
var fs = require('fs'); var fs = require('fs');
var pg = require('pg'); var {Pool} = require('pg');
var copyFrom = require('pg-copy-streams').from; var copyFrom = require('pg-copy-streams').from;
pg.connect(function(err, client, done) { var pool = new Pool();
pool.connect(function(err, client, done) {
var stream = client.query(copyFrom('COPY my_table FROM STDIN')); var stream = client.query(copyFrom('COPY my_table FROM STDIN'));
var fileStream = fs.createReadStream('some_file.tsv') var fileStream = fs.createReadStream('some_file.tsv')
fileStream.on('error', done); fileStream.on('error', done);