Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70764

How can I use transactions in SQLite plugin on Ionic3?

$
0
0

@aluco wrote:

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

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70764

Trending Articles