One way to process data is promises. Since you are creating a pool, you can build your queries using something like q (or native promises, soon):
// assuming you have your local getConnection above or imported exports.getConnection = function(queryParams) { var d = q.defer(); local.getConnection(function(err, conn) { if(err) d.reject(err); d.resolve(conn); }); });
So, wrap some of your other calls in promises like this, and then just compose your query:
db.getConnection() .then(function(conn){ makeRequest() .then(...) ... .catch(function(err){
Does this look like what you are asking for?
Zlatko
source share