Sqlite query in a loop

Hi,

I have this query in a loop and I need all the results to create a html layout. Problem is that query executes and I don’t see results rows in output variable because of asynchronous nature of code. My question is how I can change below code so that queries are run synchronously so I get all results before completion of loop?

Help much appreciated.

app.data.mydb.transaction(function (tx) {
for (let element of iterator) {
var query = ‘SELECT id, sku, name, cats, price, barcode, rrp FROM products WHERE id=’+element;
tx.executeSql(query, [],
(function(i){
return function (tx, results) {
order.products[i].childrenproducts.push(results.rows.item(0));
};
})(i),
function (error) {
console.log("Error processing SQL: " + error.code + " " + error.no + " Query: " + query);
});
}
}, function (error) {
console.log("Transaction Error: " + error.code + " " + error.no + " Query: " + query);
});