I hope anyone can help me.
I tried to invoke the function createProduct
and create a new dataset in my MySQL
database.
But I want to return the error/result.
let sql = "INSERT INTO ZUTAT (ZUTATENNR, BEZEICHNUNG, EINHEIT, NETTOPREIS, BESTAND, LIEFERANT, KALORIEN, KOHLENHYDRATE, PROTEIN, Gelistet, Bild) VALUES ?";
let values = [
[data.pNr, data.pName, data.pUnit, data.pPrice, data.pCount, '101', data.pKa, data.pKo, data.pPr, data.pListed, data.pImage]
];
let output;
con.query(sql, [values], function(err, result) {
if (err) {
console.log('Error: ' + err);
returnBack(err);
} else {
console.log('Result: ' + result);
returnBack(result);
}
});
function returnBack(returnValue) {
console.log('Return: ' + returnValue);
output = returnValue;
}
l().then({
function() {
console.log('t: ' + output);
return output;
}
})
}
The problem is that the return
statement executes before the con.query
does.
I tried async
but it doesn't works.