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

Make it runnable in a webworker #172

Open
lennardv2 opened this issue Sep 9, 2019 · 3 comments
Open

Make it runnable in a webworker #172

lennardv2 opened this issue Sep 9, 2019 · 3 comments

Comments

@lennardv2
Copy link

lennardv2 commented Sep 9, 2019

Is your feature request related to a problem? Please describe.
I would like to run nSQL in a webworker. This however is not possible due to nanosql referencing to localStorage (when using IndexedDB). LocalStorage is not available in a webworker.

Describe the solution you'd like
Let nanosql no longer reference the localstorage when on IndexedDB

@neofuture
Copy link

neofuture commented Sep 9, 2019

use postMessage() to communicate back to localStorage

@lennardv2
Copy link
Author

The problem is that nanosql is trying to access localstorage while its not available in the webworker.

@danbritt
Copy link

I had this issue as well. To get around it you can mock localStorage on the global object in your web worker.

Example:

self.localStorage = {
    getItem: function() {},
    setItem: function() {},
    removeItem: function() {}
};

It looks like it's using localStorage to store some information about the database version and model hash if you don't supply a version number. It's also storing some information about auto increment if you are using that. At least that's my understanding from looking at this file: https://github.com/ClickSimply/Nano-SQL/blob/master/packages/Core/src/adapters/indexedDB.ts

If you aren't using any of these things, the mock above should work. If you do need these things, you'll have to add code to your mock to make it work, keeping in mind that nanosql expects these methods to be synchronous.

The indexeddb adapter could probably be modified to use a separate indexeddb database to store these values instead of localStorage.

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

No branches or pull requests

3 participants