Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Latest commit

 

History

History
51 lines (36 loc) · 1.91 KB

README.md

File metadata and controls

51 lines (36 loc) · 1.91 KB

pg-query-readstream

version version js-standard-style npm downloads

Expose pg query as a readable stream

Example

var pg = require('pg')
var ndjson = require('ndjson')
var queryStream = require('pg-query-readstream')

pg.connect('postgres://localhost/postgres', function (err, client, done) {
  queryStream(client.query('SELECT * FROM random'))
    .pipe(ndjson.serialize())
    .on('end', client.end.bind(client))
    .pipe(process.stdout)
})

Usage

queryStream(client.query('SELECT * from random'))

queryStream will wrap a client.query call in a readable stream.

Events

  • result – result stats from the pg query

Note

This module was created to expose postgres queries in a simple readable stream without buffering results. The existing pg-query-stream module works great with postgres, however Redshift does not support this same cursor format. pg-cursor ends up buffering the entire result set in memory. Redshift also advises against using their form of cursors when dealing with large results.

This module currently does not deal with backpressure. Rows are emitted as fast as they are received.

License

MIT