pg-query-readstream

Expose pg query as a readable stream

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
pg-query-readstream
201.0.17 years ago8 years agoMinified + gzip package size for pg-query-readstream in KB

Readme

pg-query-readstream
Expose pg query as a readable stream
build status

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