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!!
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!!