Reputation: 155
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
Upvotes: 2
Views: 1835
Reputation: 867
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));
Upvotes: 6