brodycj / cordova-sqlite-ext

A Cordova/PhoneGap plugin to open and use sqlite databases on Android/iOS/macOS/Windows with REGEXP (Android/macOS/iOS) and pre-populated databases (Android/iOS/macOS/Windows)
Other
72 stars 55 forks source link

cascading selects #80

Open diegodcl opened 6 years ago

diegodcl commented 6 years ago

I´m developing a app with cordova+framework7+sqlite-ext. The app works offline, and synchronize the collected data troughout the day, with a API on the server.

A JSON is builded selecting data from the database with a sql transaction and a lot of callbacks. Something like this:

db.transaction(function(tx){ tx.executeSql("select from table1",[], function(tx, rs){ if (rs.rows.length>0) { var tb1_id = rs.rows.item(0).tb1_id; tx.executeSql("select from table2 where father_id = ?,[tb1_id], function(tx,rs) { tx.executeSql("select * from table3 where father_id = ?,[tb1_id], function(tx,rs) {
} }); });

in between the "tx.executeSql" statments it´s loaded the results into an array of objects to be sent later to the API.

The problem is that I´m having trouble with the sync of these selects. The question is, the best way to do this kind of thing is via transaction? should I use readTransaction? should it be only the "executeSql" statments cascading? I noticed that the transaction API is deprecated.

brodycj commented 4 years ago

It would be ideal to do this in a readTransaction, then all data comes from the same state.

I had wanted to deprecate the transaction API but found that it is still needed by many users.

I am hoping to make a clean API redesign someday, see xpbrew/cordova-sqlite-storage#862.

My apologies for the extremely long delay.