pg-query-readstream

1.0.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i pg-query-readstream

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • mkohaley
  • bt-wil
  • rich-hart
  • bteng
  • ankitbt
  • blinblin
  • btro
  • abronzan
  • sekhar2889
  • toli
  • wvonnegut