I have this node.js function which returns a Promise after executing a single MySQL query.
function deletePoint(PointObj, door_id) {
return new Promise(function(resolve, reject) {
try {
var connection = jonMySQL.getMySQL_connection();
var mysql_query = '`DELETE FROM table1 WHERE user_id=? and door_id=?`';
var mysql_query_placeholder_arr = [PointObj.user_id, door_id];
connection.query(mysql_query, mysql_query_placeholder_arr, function(err, rows, fields) {
if (err) {
return reject(err);
} else {
resolve(rows);
}
});
} catch (err) {
reject(err);
}
});
} The above function works fine. However, what if I would like the function to finish running 2 MYSQL queries?
The second query would look something like this;
var mysql_query2 = '`DELETE FROM table2 WHERE user_id=? and door_id=?`';
var mysql_query2_placeholder_arr = [PointObj.user_id, door_id];
How do I integrate this second MySQL query into the function such that the Promise will return only after both queries have been executed?
EDIT: It would be preferable if the answer provided can handle up to several queries (say, up to 5) without callback hell. Can someone provide an answer using async module?