I’m wondering how to use transaction with SQLite from ionic native’s framework. I use the following code:
syncProducts(products: Array<Product>){
if(this.networkService.isConnected()){
this.database.create({name: "data.db.sqlite", location: "default"})
.then(database => {
console.log("Crear una transaccion");
database.addTransaction(tx => {
tx.start();
console.log("TRANSACTION BEGIN -------");
let productsForSync = products.filter(product => product.status == 1);
for(var i = 0; i < productsForSync.length; i++){
this.productService.sendProduct(productsForSync[i]).then(()=>{
tx.executeSql("UPDATE product SET status = 2 WHERE id = "+productsForSync[i].id
,[],data => {
console.log("data:"+data);
},error => {
console.log("Error in sql: "+error);
});
}).catch(error => {
console.error("Error from post: "+JSON.stringify(error));
});
}
});
});
}else{
console.log("No hay internet");
}
}
But the log “TRANSACTION BEGIN” it’s not getting triggered. How Ican use it?
Regards