-
Notifications
You must be signed in to change notification settings - Fork 25
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
Support Browser #65
Comments
Hey! Thought I'd drop some more info on my use case. I essentially would like to use an embedded in-memory database within WASM (Web Assembly). While it's possible to use alternatives (i.e Sqlite3 has a WASM build), cross-compatibitlity between C -> WASM and rust -> WASM isn't great due to the ABI, and the fact that we're in a web environment. native_db looks to solve this problem - a pure rust implementation should have no issues, and as far as I know the only real requirements to compile to wasm are no-std (As browser has no file system support yet). Happy to help test/implement @vincent-herlemont : If you can get a no-std build let me know and i'll happily put together a WASM example. |
@misaim Thank you for your message. Currently, Redb has opened support for adding new backends cberner/redb#707, and the reason for this support is specifically linked to WASM with a technology called JavaScript OPFS. It appears that the API might be present in the It could be a good path to explore, let's see! I'll keep you updated on the progress; a PR should be coming soon. |
Persistence and BrowserCurrently, I am unsure how to correctly integrate support for persistence in browsers. The challenge is that a synchronous interface is needed for the I have explored how SQLite is implemented in WebAssembly. A potential solution could involve using a proxy like sqlite3-opfs-async-proxy.js that could bypass JavaScript's asynchronicity. However, this requires substantial development and seems more like a workaround than a long-term, maintainable solution. Related information sqlite/wasm/building. Here's a summary of the implementations source: The Current State of SQLite Persistence on the Web
PS: Hello @DouglasDwyer, do you by any chance have any advice since you started this job with cberner/redb#707? |
Hey @vincent-herlemont, I haven't gotten around to implementing a web backend for redb yet. But my personal plan was to use wasm_thread to spawn a web worker, and then ferry all database reads/writes to the web worker using a spinlock. The web worker would use the synchronous OPFS API to read and write to a JavaScript file. I think that it is the best approach and it ensures that the API remains synchronous. Let me know if you have interest in such a backend. Due to the fact that the solution is a bit cursed I was not planning on open-sourcing it (just using it in my own work) but I can publish it if there is interest when I code it. |
Thank @DouglasDwyer. I wasn't familiar with the On my side, I will try to make a draft in the coming months if I have some time. You can follow the progress in this issue. |
just my two cents: if you compile to WASI you can just use a WASI-JS polyfill and get browser support with the sync/async issue taken care of for you and not need something like a spinlock. However, that also:
That being said, please @ me in any issue/PR you may make with regard to web support here or in redb! I could likely benefit from it over in Mimir |
wasmer.js
as indicated by @GregoryConrad in his comment.The text was updated successfully, but these errors were encountered: