Rust implementation of IDBBatchAtomicVFS? #154
Replies: 5 comments 10 replies
-
I don't really understand your question, but I also don't know anything about Rust. On first reading, it sounds like you want a way to use IndexedDB for SQLite storage "entirely in rust" without involving any JavaScript. I don't think that's possible as I don't know of any direct WebAssembly bindings for IndexedDB. If you're instead asking whether you can use the SQLite C API directly in WebAssembly instead of the wa-sqlite wrappers, while still using the IDBBatchAtomicVFS, I think that can be done. I don't think you can use wa-sqlite as-is; I think you'll want to steal pieces of it and incorporate them into your application build. Maybe someone else here will have a better understanding of your goals and better advice. |
Beta Was this translation helpful? Give feedback.
-
Did you get this WASM build working with Rust by any chance? |
Beta Was this translation helpful? Give feedback.
-
Hey @daaku @abhay-agarwal @quolpr @rhashimoto ! I have a crate with a SQLite WASM build that creates a diesel backend working here with the official sqlite build: There's a branch that uses Roy's It's a bit tricky to implement the backend with full-async in Rust WASM to be compatible with this build, because of the lack of a good A downside to this is that OPFS is all in JS and just loaded into rust. It would be more complex to create a vfs straight from rust -- i'm not even sure the bindings for that exist in Rust. I would have to look more into how VFS' and their initialization work in SQLite3, but that will definitely be my next step. However, the WASM module is available so loading values into/out of SQLite WASM memory can occur through pointers, which circumvents the JS part of it. Future work:
Going to be talking about my work on this lib in a couple days if you're interested: |
Beta Was this translation helpful? Give feedback.
-
HN discussion on SQLite's official wasm build (which doesn't seem to support shared workers?) has caused some more chatter about a Rust-centric build. Curious if anyone else is interested in collaborating? |
Beta Was this translation helpful? Give feedback.
-
We went a slightly different route to get something similar: We built a Rust-based SQLite extension, which can then be loaded on any practically platform where you can use SQLite, including WASM. While we haven't tested with Tauri yet, I can't imagine any blockers there. Some advantages include:
The biggest complexity comes in with figuring out how to build and load the extension for each platform, but if you only need to support WASM + Tauri it's not that much. Our codebase is here: https://github.com/powersync-ja/powersync-sqlite-core/ |
Beta Was this translation helpful? Give feedback.
-
Curious if there is any existing work around having a set of native rust bindings to wasm sqlite that can still leverage the IndexedDB-backed VFS.
We have a hybrid application where we have a common rust codebase that cross compiles to wasm for web, with wa-sqlite as a sqlite implementation, and then a native toolchain with a desktop binary of sqlite for our Tauri application.
It would be great to not have to call back out to js in wasm, but just to handle the operations entirely in rust, with the native c bindings. Happy to try and work on this, but just wanted to confirm if I have the right mental model here, and if there are any extreme gotchas. Things we also need:
If anyone has some pointers to prior art, would love to jump on that!
Beta Was this translation helpful? Give feedback.
All reactions