I'm not sure if this will be a redundant or stupid question, but I didn't find a satisfying answer yet.
I want to do sql queries in Javascript. I want to achieve that the inserts are completely executed, when I start with selects. Now the problem is that I have to that in a loop and I don't know how to ensure that all queries have been finished.
in pseudocode, it looks like this.
for (var i = 0; i < N; i++) {
db.transaction(function(tx) {
tx.executeSql("INSERT ...", [], success, error);
}, error, success)
}
db.transaction(function(tx) {
tx.executeSql("SELECT ...", [], success, error);
});
If I just did two transaction, I could do the second in the callback of the first, but in a loop that seems not that easy.
Is there an elegant way to achieve my goal, without too much magic?
P.S. I can't do all queries in one transaction, because later inserts are dependent on previous ones, and there is a post request inbetween that takes a little time.
Thank you for reading my question.