brianc/node-pg-query-stream

Is it necessary to manually release connections?

Closed this issue · 1 comments

drob commented

I noticed in the example use that done() is never called to explicitly release clients back to the pool:

pg.connect(function(err, client, done) {
  if(err) throw err;
  var query = new QueryStream('SELECT * FROM generate_series(0, $1) num', [1000000])
  var stream = client.query(query)
  stream.pipe(JSONStream.stringify()).pipe(process.stdout)
})

Is this correct use? Will the connections be collected under the covers?

Yes! It's still mandatory to do that. My bad on bad documentation! I'll update that now.

Here's a repo I was using internally I just pushed you could use as an example. A lot of times when I'm doing streaming reads I wanna do it over a large amount of data in a batch job or something, so I just connect a client and then when the query stream is finished, I end the client.

https://github.com/brianc/node-pg-readable/blob/master/index.js#L6