Hi, iam developing an app, which reads tickets number and then checks i it is valid. The problem is, that I need to load valid ticket codes from text file. So i load it from file and try to insert it into sqlite database. With larger datasets(10000 tickets and more), it takes ages. Is there some way make it faster?
Method for opening file, reading it and insert it into db looks like this:
openFile() {
this.fileChooser.open().then(uri => {
this.filePath.resolveNativePath(uri).then((path) => {
console.log(path);
let dirPath = path.substring(0, path.lastIndexOf('/'));
let fileName = path.substring(path.lastIndexOf('/') + 1);
console.log(dirPath, fileName);
this.file.readAsText(dirPath, fileName).then((data) => {
this.db.deleteAllTickets().then(() => {
});
let test = data.split('\n');
let i=0;
test.forEach(ticket => {
this.db.insertTicketToTickets(ticket.trim()).then(data=>{
console.log("hura",data)
},err=>console.log(err));
i++;
console.log(i);
});
}).catch(err => console.log(err));
})
});
}
And function for insert looks like this:
insertTicketToTickets(ticketId) {
return this.storage.executeSql('INSERT INTO tickets(ticketNumber) VALUES (?)', [ticketId]).then((data) => {
return (true);
}, (error) => {
console.log(error);
});
}
Any ideas?