litehelpers / cordova-sqlite-evmax-ext-workers-legacy-build-free

Other
5 stars 0 forks source link

Need to run multiple DB transactions on worker thread #1

Open kumarkratigwithme opened 8 years ago

kumarkratigwithme commented 8 years ago

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

brodycj commented 8 years ago

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.