Need to run multiple DB transactions on worker thread
kumarkratigwithme opened this issue · 1 comments
Hi,
Currently all my DB transactions are on main thread. I need to transfer them into worker thread.
Can you please tell me the best practices.
importScripts('SQLitePlugin.js');
self.addEventListener('message', function(ev) {
if (ev.data === 'go') {
sqlitePlugin.openDatabase({name:'my.db'}, function(db) {
db.executeSql("SELECT UPPER('Some US-ASCII text') as uppertext", [], function(res) {
self.postMessage('got uppertext: ' + res.rows.item(0).uppertext);
});
});
}
if (ev.data === 'welcome') {
sqlitePlugin.openDatabase({name:'my.db'}, function(db) {
db.executeSql("SELECT UPPER('Some US-ASCII text') as uppertext", [], function(res) {
self.postMessage('got uppertext: ' + res.rows.item(0).uppertext);
});
});
}
});
I dont want to openDatabase again and again for all the calls.
Is this possible that I open the DB in main thread and can pass the reference in the worker thread?
Please help!!
Store the db handle object in a variable or object declared in a scope outside the event handler function.
I will add an example when I get a chance.