I'm using mysql module in nodejs.
I want to do something like this, but the problem is that the callback of query is async and I can't fill the result array correctly.. How can I do? Thanks!
function fn(callback) {
client.query(
'SELECT * FROM imbarcazioni',
function select(err, ships) {
if(err) {
throw err;
}
ships.forEach(function(ship) {
client.query(
'SELECT * FROM storico_imbarcazioni WHERE id_imbarcazione=' + ship.id,
function select(err, hist) {
ship.history = hist;
}
);
});
callback(hist);
});
}