Expose pg query as a readable stream
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)
})
queryStream
will wrap a client.query
call in a readable stream.
result
– result stats from the pg query
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.
MIT