question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query events with Pool

See original GitHub issue

With a client we can use the “row” event of a query. client.query("select id from table").on("row", row => console.log(row))

{ id: 1 }
{ id: 2 }
{ id: 3 }
{ id: 4 }
{ id: 5 }

But with a pool we can’t do this. pool.query("select id from table").on("row", row => console.log(row)) TypeError: pool.query(...).on is not a function

Is it possible to use the query events with pool?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
brianccommented, Jul 8, 2016

The pool supports returning a client if you want to do something like that:

pool.connect(function(err, client, done) {
  var query = client.query('whatever')
  query.on('row', //etc)
  //...etc
})

That API ^^ has existed for years and is still there. 😄

pool.query is a helper method for the most common operation which is “I want to run a query and get the rows back.” If you want to do something “fancier” with a client (transactions, row events, listen/notify, pg-query-stream, etc) then pool.query isn’t for you. I don’t really want to extend the pool.query method with even more functionality…

Curious: why are you using query.on('row') in the first place?

0reactions
bluenote10commented, May 4, 2021

If you want to do something “fancier” with a client (transactions, row events, listen/notify, pg-query-stream, etc) then pool.query isn’t for you. I don’t really want to extend the pool.query method with even more functionality…

@brianc Thanks for the clarification, that really makes sense. A quick question about the exact semantics: When using client.on('notification', callback) on a client acquired from a pool, is it safe to release this client back to the pool and still get notify updates, or does this require holding on to the client indefinitely?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Query Event DB to find who has connected to a pool...
Hi all,. I need to get a list of users that have connected to a certain pool over the last 2 weeks in...
Read more >
Using SQL Server Extended Events to monitor query ...
In this article, we will explore how we can use SQL Server extended events to monitor query performance in SQL Server.
Read more >
Need query for Getting the Status of a particular app pool in IIS
Hi, Can you share the query to identify when a particular IIS application pool stopped/crashed via Log Analytics. Thanks RC.
Read more >
pg.Pool – node-postgres
The pool will dispatch every query passed to pool.query on the first available idle client. Transactions within PostgreSQL are scoped to a single...
Read more >
Connection terminated unexpectedly does not propagate to ...
Always use a pool, always add an error event listener to the pool. Not emitting the event when there's an active query doesn't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found