Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 589 Bytes

snipits.md

File metadata and controls

25 lines (20 loc) · 589 Bytes

Random Code Snipits

copy from in JavaScript

const {Client} = require('pg');
const escape = require('pg-escape');
const copyFrom = require('pg-copy-streams').from;


const client = new Client({
  connectionString: connectionString,
})
await client.connect();
const inputStream = this.s3.getObject(s3Params).createReadStream()
const stream = client.query(copyFrom(escape('COPY %I FROM STDIN  (header, format csv)', this.table)));

try {
  console.log('starting stream');
  await pipeline(inputStream, stream);
} finally {
  console.log('stream done')
  await client.end()
}