serverless-mysql
serverless-mysql copied to clipboard
Log the final query
Is there a way to console.log the final query?
const query = 'INSERT into table SET ?'
const result = await mysql.query(query, [object])
Is there a way to know what the final sql query looked like ?
Thanks
Did you manage to find a solution for this?
I don't believe the mysql library returns the final escaped SQL except on an error. If you catch an error, .sql on the error object will contain the SQL statement executed. I'll see if there is a way to bring that data back for a successful query.
I don't believe the
mysqllibrary returns the final escaped SQL except on an error.
It does, you can use this.sql inside the callback function to get the final SQL query, regardless of whether an error occurs or not, as in this example exerpt:
con.query(sql, sqlData, function(err, result, fields) {
if (err) {
console.log(this.sql);
resolve ({"found":false, "code": -1, "message": "Error retrieving " + selection + " from " + table, "errType": err.name, "errMessage": err.message, "errNo": err.errno});
} else {
console.log(this.sql);
result.found = true;
resolve(result);
}