ujjwalguptaofficial / JsStore

Simplifying IndexedDB with SQL like syntax and promises
http://jsstore.net/
MIT License
858 stars 110 forks source link

SqlWeb Extension not available in service worker #116

Closed jeffbradham closed 5 years ago

jeffbradham commented 5 years ago

I'm attempting to implement a client-side intercept of php calls in a pwa offline-enabled web site. I am able to use JsStore in the service-worker's scope but when I try to call runSql so I can re-use as much of my sql-syntax as possible I get errors. When enabling SqlWeb it references the "window" object, which is not visible in a service-worker.

Can you recommend a way to include the SqlWeb extension?

current code: return Util.sqlWeb == null ? window['SqlWeb'] : Util.sqlWeb;

Thank You Jeff

ujjwalguptaofficial commented 5 years ago

fixed in v - 3.3.1 . It was due to the window object being used, i changed it to self.

Let me know if doesn't work.

jeffbradham commented 5 years ago

well, I can't tell for sure if it works or not because I'm having other issues with this update. I had started this project with JsStore v3.0.0. Jumping to v3.3.1 I'm now falling into situations where the db requests just pile up in the requestQueue without being processed. In looking at some of the more recent changes it does look like there were changes related to this queue going into v3.3.1. Do you know anything specific about this which might help me debug my situation?

Thanks Jeff

ujjwalguptaofficial commented 5 years ago

Hi Jeff

Could you tell me - when its pilling up the queues like certain situations or steps that would help me to debug. I didn't knew this was happening. If you can create a small demo projects, where you can show me the issue that would be great.

It is very strange, it passes all the test scenarios. Anyway, let me know.

Thanks, Ujjwal

On Tue 6 Aug, 2019, 1:22 AM jeffbradham, notifications@github.com wrote:

well, I can't tell for sure if it works or not because I'm having other issues with this update. I had started this project with JsStore v3.0.0. Jumping to v3.3.1 I'm not falling into situations where the db requests just pile up in the requestQueue without being processed. In looking at some of the more recent changes it does look like there were changes related to this queue going into v3.3.1. Do you know anything specific about this which might help me debug my situation?

Thanks Jeff

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ujjwalguptaofficial/JsStore/issues/116?email_source=notifications&email_token=ACTOR56MVYXRCH3NIHAZ4GLQDCAIPA5CNFSM4IJAT5FKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3S4LSQ#issuecomment-518374858, or mute the thread https://github.com/notifications/unsubscribe-auth/ACTOR536N73NFGNF6OSW5WDQDCAIPANCNFSM4IJAT5FA .

jeffbradham commented 5 years ago

Hi Ujjwal,

I'm working to try to isolate the scenario now. I have proven that it has nothing to do with v3.3.1. It fails with v3.0.0 for me as well. I suspect that it has to do with the fact that I'm not creating an additional database in my scenario and attempting to switch between databases.

I'm very new to javascript and web design. Can you explain the best approach to managing connections to multiple IndexedDb db's? Should I be re-using the same JsStore instance and terminating/re-connecting? Do you recommend a different instance for each db connection?

Thanks Jeff

ujjwalguptaofficial commented 5 years ago

ok, i m relieved to know that there is no problem :).

You can use two variable for multiple db's or one variable too - there is no hard rule. The difference is that -

So choice is yours.

Also if you are using service worker - make sure you open/close db manually always when doing something because service worker codes are not always active, they become active for some events only & for very less time.

jeffbradham commented 5 years ago

Thank you very very much for the help. I believe that you hit the nail on the head with the service worker being the cause.

So for db activity being done in the service worker would it be best if I made every action a closed loop? In that I create a new JsStore.Instance / do stuff / and then terminate?

ujjwalguptaofficial commented 5 years ago

Yes, so to make sure -

Feel free to let me know, if there is any issue.

jeffbradham commented 5 years ago

Hi Ujjwal, I really want to express how thankful I am for your quick and effective responses. I'm new to this world but I would be happy to help make a splash here so hopefully I will be able to help you push this technology forward. I wanted to catch you up on my situation and also ask that if we should take this conversation to another medium please let me know. Because we are obviously beyond this bug now but I want to keep your ear. Here is what I think I have learned along the way that should be beneficial to you.

  1. You cannot have table names with underscores or numbers in the name if you want to issue runSql queries to them. The basic JsStore API commands for select, insert, update work, but it seems that the parsing for the sql-like interface breaks.
  2. If you are going to attempt to open connections to more than one IndexedDb database, even if you use two different JsStore.Intance's they will collide if you do not create them with a WebWorker. Which is what leaves me stuck at item 3
  3. From within a service worker you cannot seem to create another "worker" (maybe only in chrome). The way around that seems to be using a polyfill subworker thing I stumbled upon. I'm still failing to get that implemented.

I'm attempting to intercept a php call in the fetch event listener and instead call a local javascript function when I determine that I'm in offline mode. So it would send the "sql" to the local IndexedDb instead of the server-side mysql. This seems like the first and most natural use for these PWA apps....that is what lead us to this technology...but I have yet to see any basic example that exhibits that structure.

I hope this finds you well and I hope that my struggles can pay dividends for us both.

Jeff

ujjwalguptaofficial commented 5 years ago

Hi Jeff

It's all my pleasure & thanks to you buddy for listing out all the things you found so far. This would really help peoples coming to this thread.

Let's take our conversation to gitter - https://gitter.im/JsStore/Lobby . Ping me in personal message