storesafe / cordova-sqlite-storage-help

Help forum for Cordova sqlite plugin projects
2 stars 1 forks source link

Separate transaction from queries #31

Open jondediego opened 7 years ago

jondediego commented 7 years ago

I am working on a project where we need this kind of structure:

startTransaction(){
}
commitTransaction(){
}
rollbackTransaction(){
}
executeQuery() {
}

So we need to separate the creation of transactions from the queries. I have seen this library that allows to use websql API in a promise-based way: https://github.com/brodybits/sql-promise-helper. It works great, the problem is that we have another requirement, executeQuery method should return the result of the query. The promise-helper library executes sql, once we call to commit method, so if we call commit method fromco mmitTransaction, we will obtain results for the queries in that method, not in the executeQuery one.

Do you know if there is a way to follow this structure using this cordova sqlite plugin?

brodycj commented 6 years ago

I don't think I can really follow the code structure you show at the beginning.

If you need the results per query I recommend that you follow the "standard" transaction API as documented. This API will be supported on the Browser platform in the near future.

In case the "standard" transaction API does not work for you there is a special version at https://github.com/litehelpers/cordova-sqlite-evplus-ext-legacy-build-free (GPL or premium commercial license options) that supports a multi-part transaction API with callback per SQL statement, documented at: https://github.com/litehelpers/cordova-sqlite-evplus-ext-legacy-build-free#multi-part-transactions