Replies: 2 comments 6 replies
-
These are actually pretty different cases. IDBBatchAtomicVFS requires an asynchronous WebAssembly build, currently with Asyncify, and that doesn't allow multiple simultaneous asynchronous calls into a WebAssembly instance. In theory you could still have multiple SQLite connections in the same WebAssembly instance but you would have to be careful to query only one of them at a time. So it's not very practical and I'm not sure anyone has actually tried it. You could create multiple SQLite WebAssembly instances in the same context, creating only one connection in each, and that would have a much better chance of working. I'm not sure if anyone does this either, though. IDBBatchAtomicVFS does work nicely from multiple contexts - i.e. multiple Windows, dedicated workers, service worker, or shared worker. You can try it yourself by opening the demo on multiple tabs (and selecting the appropriate VFS and runtime). IndexedDB is the only persistent browser storage that works on every kind of context. It isn't easy to use OPFS concurrently on multiple contexts, but OriginPrivateFileSystemVFS does work...as long as each context is a dedicated Worker. This VFS works around that one open handle per file limitation by closing its handle when another context needs access. Chromium browsers have removed this restriction but we're still waiting to see what the others will do. There is a table comparing the example VFS classes in the upcoming 1.0 release here. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your response! 😊
This is what I'm planning to do. In my mind, this should be almost equivalent in behavior to having multiple tabs, each with one connection. Correct?
This is awesome to hear. Is this because IndexedDB offers transactions? Can I expect it to work like SQLite does on a normal file system? To be specific, that means:
I'm going to assume WAL mode won't be much of a possibility, given what you write in your table. Reading while another connection writes would be awesome, though... I was originally planning on switching over from this library to the official SQLite WASM NPM library, but given the multi-tab limitations of that version, I don't find it that attractive anymore. The question that's still on the table for me is whether I should switch from an IDB-based solution to an OPFS-based solution. In the benchmarks, the OPFS solutions seem to have very strange performance characaters. My intuition would be that they would easily outperform IDB in every metric because of the synchronous SQLite build, but they don't. With the current state of how browsers are, do you see any advantage over the OPFS solution compared to the IDB solution? |
Beta Was this translation helpful? Give feedback.
-
First of all, awesome job with this library. I also apologize if the answer to this question is already in here somewhere, I couldn't find it easily.
I'm using it in the "IDBBatchAtomic relaxed" mode, and I was wondering how well this library behaves in the presence of multiple connections. I am talking both:
Now, given that IndexedDB is scoped per origin, there shouldn't be much of a difference between these two cases. For the OPFS, for example, I've heard that multiple connections do not behave nicely (like they do on a real file system), and only one handle is permitted. How is it with IndexedDB? Can I expect transactions from multiple connections to behave as expected?
Beta Was this translation helpful? Give feedback.
All reactions