Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to run multiple DB transactions on worker thread #1

Open
kumarkratigwithme opened this issue Mar 31, 2016 · 1 comment
Open

Need to run multiple DB transactions on worker thread #1

kumarkratigwithme opened this issue Mar 31, 2016 · 1 comment

Comments

@kumarkratigwithme
Copy link

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
Copy link
Member

brodycj commented Mar 31, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants