2

I want to do a bulk insertion in ionic 3 I have this code it works but it's really slow

 insertQuotation(value){

    for(var i=0; i<=value.length; i++){
    let data=[value[i].quotation_id,value[i].customer_name,value[i].product_name,value[i].price,value[i].services,value[i].response_time,value[i].created_time];

    this.database.executeSql("insert into care_plan_quotation_history(care_plan_quotation_id,customer_name,product,price,services,response_time,created_time) values(?,?,?,?,?,?,?)",data)
    .then(data=>{
      return data;
    },err=>{
      alert("error");
    })
    }
  }

please help me with this

1 Answer 1

6

You can do bulk operations with Ionic and SQLite like this:

let insertRows = [];
items.forEach(item => {
    insertRows.push([
        "INSERT INTO items (id, type, date, message) VALUES (?, ?, ?, ?)",
        [item.id, item.type, item.date, item.message]
    ]);
});
this.database.sqlBatch(insertRows).then((result) => {
    console.info("Inserted items");
}).catch(e => console.log(e));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.