-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
FIDB persistence #12
Comments
Currently: no Plans: I'd like to do it at some point, but I don't have any immediate plans to do it Sync to real IndexedDB: The only reason I can think to do this is if you use FIDB as a cache layer, but it's currently too slow to do that, which is a separate issue (basically I used arrays to store data because it's simple, but a good binary tree could make it fast enough to open up this use case). |
@dumbmatter It might be slower with |
I was wondering if you had at all looked into compiling any of the actual IndexedDB implementations so they could be used in Node? I know thats not the aim of the project, just asking around related projects to see if anyone has tried |
I'm not aware of anyone trying that, and I'd guess that would be a pretty huge task. |
Just looking at this to provide support for dodgy browser implementations. My previous attempt also used in-memory arrays. I persisted these to LocalStorage when changes were made. It was a non-optimal thing - basically write the whole array to Storage when any changes were made, with a little SetTimer stuff as a lame attempt to optimise. It's was ok for my use-case which is mainly read, with few writes. I've not delved into the source just yet, but it would be great to have some kind of event to hook into when data has changed, with a link to the (native fake) Store that has changed. This would enable people to roll their own persistence. I'm working in Typescript with WebPack and had to use
The /auto stuff didn't work for me, but the above worked very well. I plan to use this for production code, not just for test. I don't need persistence, but it would help lots. Great library! Jeff. |
What would it take to make fakeIndexedDB into a realIndexedDB? What parts of the source code needs to be changed to make this the case. It should be possible to build on top of Then one could use |
Currently data is stored in basically the simplest/stupidest way possible, which you can see in https://github.com/dumbmatter/fakeIndexedDB/blob/0dd50f24711d73c8a213111406ed9f683c926259/src/lib/RecordStore.ts The end result is pretty slow performance compared to what you'd get from a more intelligent approach. And of course no persistence to disk. Possibly you could implement another backend just by replacing that one file. Ideally that would be true. But I'm not 100% sure if it's actually true, since this is mostly code I wrote a few years ago :) Also there are some bugs that would be nice to fix. Several can be found from the W3C tests. But I think they're all pretty rare edge cases, since there have not been much complaints about them. |
Is the performance bad because of specifically Because if it is just |
Where are these failing W3C tests? |
Probably just RecordStore, I think.
Run Also, these tests are a snapshot of the W3C web platform tests from a couple years ago, it's possible there are even more failing tests they've added since then :) |
@dumbmatter Thanks for writing this library. I'm looking at getting this ported over to Deno, updating the WPT, and adding optional persistence via sqlite WASM binding. Super helpful discussion of the RecordStore class here in this thread! If I can port v4 over to Deno with minimal changes and that still packages for Node, would you want a PR back for those changes? Not sure if it's easily feasible to make isomorphic (mainly due to If I can do that, would you be comfortable with a method for users to choose persistence? My idea is an exported function which sets a variable in the module that |
@dumbmatter There's some genuine complexity in all the test harnessing you've written/converted with a pretty tight dependency on Node/Jest/PhantomJS. That would be the biggest hold-up to making this completely isomorphic between Deno/Node. Would you be comfortable with a (potentially) breaking change to some of the tests that allows them to run in Node and Deno, and which probably removes PhantomJS in favor of Qunit's headless Chrome solution? |
For the tests, the Jest/PhantomJS stuff is not really necessary, it's mostly there just to ensure I don't break compatibility with test runners a lot of people use, and to serve as examples for how to use them. At this point, I could arguably get rid of PhantomJS since it's pretty old and maybe not that commonly used, but since I already have it working I'd like to keep it if possible. Overall... I'm open to a PR to add persistence. I'm also open to a PR to make it work in Deno, although I don't really know what that entails, so it's hard for me to say much about it. I would not accept a PR that somehow makes things worse for the typical user, who is not interested in persistence or Deno. There's also some chance I look at your PR and think it's too complicated to be worth it, in which case I might recommend you fork instead. |
I've had better luck recently with targeting Deno and transpiling for Node ESM by modifying the imports before transpiling and packaging for Node. That said, persistence for Node would add yet another persistence store, for a total of three: the original RecordStore, support for Deno's sqlite bindings, and then Node's. I think for now, I'll maintain as a separate fork, perodically pulling in your changes. If I'm ever satisfied that the complexity is manageable (or non-existent) then I'll make a PR. |
I needed this use case of persistence too. Following the suggestions above to use Level I have created in node-indexeddb. It cannot be merged in without breaking fake-indexeddb's purpose though. Also, it's currently still using the same RecordStore.ts but using level just for initial read and also uses level asynchronously to write the files (it's a write-through cache pattern) |
Is there any options for permanent storages? If not, does FIDB have any plans for supporting this feature? Something like sync data with the real IndexedDB?
The text was updated successfully, but these errors were encountered: