-
Notifications
You must be signed in to change notification settings - Fork 154
Add storage crate #59
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
Conversation
Dexie.js only uses That's why I think concentrating on good |
Indexeddb is very hard imo |
@derekdreery It sure is, which is why we want to put the work into making |
@c410-f3r Thanks for getting started on this! With regard to Instead, I think we should provide a simple IndexedDB wrapper API which always has the name var request = indexedDB.open("", 1); It would have an extremely simple schema: request.onupgradeneeded = function (event) {
var db = event.target.result;
db.createObjectStore("", { keyPath: "key" });
}; Then it would just store This gives us the same functionality as If you want, I can try sketching up what the API would look like. |
For example, you can keep a Also, I think it would be best to have two crates: |
@Aloso And even then I've previously explained my position on this issue, so I won't repeat that here. Experts have said for several years that It wouldn't surprise me if within a couple years browsers start to deprecate and remove
That's a pretty bad idea regardless: there's all sorts of things that can mess that up, including browser crashes, power outages, etc. The correct thing is to periodically flush to storage (say, every minute or so), so that way it will work regardless of the circumstances. I've implemented debouncing systems like that for state storage in Chrome extensions, they work well.
I'm not going to stop somebody from implementing It's not hard to use the raw web-sys bindings for |
@Pauan
I believe that most websites only need to persist small amounts of data, where
I can live with that. |
I am indeed aware of that. But 10 MB is unacceptable for performance, that's why I said less than a few kilobytes. And even those few kilobytes block rendering. |
Just throwing my 2c in here. I think Gloo should have some kind of support for The interesting thing about saying |
With a local/session storage API and an IndexedDB API, the user has the freedom to choose whatever he likes, even if his option is to shoot himself in the foot with a given situation/API. However, as @Pauan said, local/session storage is so simple that it doesn't have a very strong appeal, one has to simply do the following: let store = window().unwrap_throw().local_storage().unwrap_throw().unwrap_throw();
Looks like the unified approach didn't have much success. For any decision that has to be made, I am personally cool in doing a more simplistic |
@Pauan You mean that the |
That's an argument for it being in Gloo isn't intended to handle literally every API, that's Though I agree
Originally I thought you had a good point, but then I looked it up, and apparently you cannot access new Worker("data:text/javascript,console.log(localStorage);") Even if you could, because it's a synchronous API, it would allow synchronous access to the main context, which is not allowed with web workers (all communication with the main context must be asynchronous). Because So the fact that IndexedDB works with multi-threaded Rust and
Sure, I think that'd be a good idea. And if it ends up being useful, we can reconsider putting it into Gloo.
Right, the simplified API should expose very little to the user, making it as simple and convenient to use as
Yup, that was my thinking: have a full featured IndexedDB, and then also a simplified IndexedDB that can handle the use cases that are currently handled by The simplified API would do a lot more than just hide the version: the API would be simplified a lot, and it would have a hardcoded key/value schema, so the user doesn't need to deal with that either. |
fwiw I would like the API for local/session storage to look like https://github.com/derekdreery/localstorage-rs, or asynchronized if using indexeddb :). The thing about async is it makes some things harder - like it's harder to know if you've finished iterating through the items in localstorage or not. You could possibly have some synchronization in rust to handle this, maybe, like some atomic ref count which disallows iterating when refs are out and vice verca? |
Also, I had a play at implementing indexeddb in rust here, but I got stuck understanding all the callback stuff somewhere. |
Could you explain more? IndexedDB is transactional and atomic, so it shouldn't be possible to modify the db while a different transaction is iterating over it. |
I think in that case this isn't an issue. :) It would be if you used window.localStorage |
We've been trying to front-load more design discussion (as opposed to doing design discussion while looking at an implementation, and potentially having to rework whole PRs due to realizing we want a completely different API). This design-first process is starting to get formalized in #65. Looking at the discussion going on here, and the design discussion issue thread for storage-related stuff, it seems pretty clear to me that we don't have a collective understanding/consensus of exactly what we want to implement yet, and there is more design work that needs to happen before we continue with implementation and PRs. Therefore, I think we should close this PR until we have reached broader consensus on the APIs we want to commit to and their design. Thanks @c410-f3r for writing this PR up. I think the best way to push this forward (either by you or some other motivated person) is to write a design proposal that sketches out the APIs in this PR (or different ones), and their motivation/rationale compared to alternative designs. |
I agree, as such I'll be closing this. But I'm excited to see the design work, since I think data storage is really important. |
Agreed! |
This draft is an attempt to unify both
Storage
andIndexedDB
into a single API.The design was heavily inspired by Dexie.js and other libs like nanoidb and idb.
Please note that I didn't made a full implementation/test-suite, decoupled logic into layers or wrote a more complete documentation because I would like to know upfront if this is the correct approach to handle persistent data storage in gloo.