Hi guys, i am a bit confused when using Asyc/await, i am basically retrieving the data from the mysql DB and then use the information when constructing an object user_details
that i will use later.
I have defined the Asyc function and call right away and then implemented .then to resolve the promise but the promise doesnt seems to get resolved and when i console the Invoice_No_Per_Trasaction
it shows as Promise { <pending> }
not sure how i can overcome this issue .
Any suggestions guys please. Thanks
let Invoice_No_Per_Trasaction = (async function Invoice_No() {
connection.query("SELECT invoiceNo FROM users_basket WHERE users_user_id=?;", [user_id], function (err, results) {
console.log("107", results); //RowDataPacket { invoiceNo: 1 },. ....
return results;
});
})()
.then((data) => {
console.log("112x", data); // undefined
return data;
})
.then((data) => {
console.log("116", data); // undefined
return data;
});
console.log("120x", Invoice_No_Per_Trasaction); //Promise { <pending> }
let user_details = {
user_FirstName: results[0].first_name, // name
user_email: userIdentitiy, // [email protected]
Invoice_No: Invoice_No_Per_Trasaction, //Promise { <pending> }
};