- Notifications
You must be signed in to change notification settings - Fork 0
Queryqueue
An advanced usage feature which might come in handy is using the internal query queue to queue up several queries in a row. 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. The error handling semantics here get really complicated and isn't recommended unless you're banging out a quick script and don't care about error handling or you really, really have some specific use case. This "feature" is mostly a hold-over from a bad design decision I made years ago, but have left to maintain backwards compatibility.
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