What if I have a code like this:
var mysql = require('mysql');
var pool = mysql.createPool(...);
pool.getConnection(function(err, connection) {
if (err) throw err; // not connected!
// Use the connection
connection.query('SELECT something FROM sometable', function (error, results, fields) {
// When done with the connection, release it.
connection.release();
// Handle error after the release.
if (error) throw error;
// Don't use the connection here, it has been returned to the pool.
});
});
The logic from initializing the pool until the entire getConnection process is located in an async function. So what happens is, when deployed in AWS, logs in getConnection are not logged because the handler finishes execution before the callback is processed. Due to this, the logs from line "if (err) throw err" is not seen in AWS cloudwatch logs.
Is there a workaround for this? I simply want to await the callback function in pool.getConnection
I did my research but all I found were specific implementations for specific scenarios, none quite similar to my scenario.