You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
freewil edited this page Mar 16, 2012
·
5 revisions
Clients are responsible for creating Queries via the factory method Client#query. The Client can create a new query before the client is connected to the server or while other queries are executing. Internally the Client maintains a queue of Query objects which are popped and executed as the preceding Query completes. When the Client's internal query queue is emptied, the Client raises the drain event. It can be useful to monitor this event, and when the Client goes idle, disconnect it from the server. The [pg|pg] helper also monitors the drain event. When a pg created Client's internal query-queue drops to 0 it is returned to the connection pool.
example
varclient=newClient(...);varquery1=client.query("SELECT * FROM NOW()");//query is queued. client is not connectedquery1.on('end',function(){console.log('query 1 completed');});varquery2=client.query("SELECT * FROM NOW()");//also queuedquery2.on('end',function(){console.log('query 2 completed');});client.on('drain',function(){console.log("drained");});//at this point nothing has been printed to the consoleclient.connect();//this will print the following://query 1 completed//query 2 completed//drained