pg-query-readstream
v1.0.1
Published
Expose pg query as a readable stream
Downloads
33
Keywords
Readme
pg-query-readstream
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