3
I have a forEach which traverses a code list and within it I have a select that queries the database records. After the forEach, data is sent from my server to my client, but forEach does not expect the result of SELECT arrive to execute the next element.
How can I make for the forEach await the outcome
lista.forEach(function (row) {
db.query("select * from cad_prospectos where = ?", [row.codigo], function(err, pesquisa){
result.push(pesquisa)
})
})
cb(result)
my return function cb returns empty
Putting the code you currently have will help answer the question...
– Vinícius
I put the code I hope you can understand.
– Erick Zanetti
I could tell if
db.queryreturns a Promise? By the way, is he native to Nodejs or is he from some package?– Woss
He’s from the Firebird package
Firebird.attach(firebirdConfig, function (err, db)– Erick Zanetti
If query returns a
Promissecan store all in an array and usePromisse.all– Isac
[https://stackoverflow.com/questions/36547292/use-promise-to-process-mysql-return-value-in-node-js] I was able to find a good way to do it here, my query does not return a Promisse, so I made some modifications following the example of this link.
– Erick Zanetti