A future for SQL on the web (2021)
jlongster.com
jlongster.com
That article was written in July, and in the intervening time, Chrome's announced an intent to ship "Multiple Readers and Writers in File System Access API" aka `readwrite-unsafe` [0] in v121 (stable in 2 weeks) which could help improve SQLite's performance even more.
[0] https://chromestatus.com/feature/5172892632875008
Edit: It looks like wa-sqlite already has a prototype VFS taking advantage of the above feature https://github.com/rhashimoto/wa-sqlite/discussions/116
As the developer of that build, i wholeheartedly confirm that. wa-sqlite makes use of asyncify, which is a feature we do not want to make use of in the canonical distribution because (to make a long story short) it's third-party voodoo which can be pulled out from under us, or break in incompatible ways, at any time, whereas the sqlite project has a long history of posting only its own code, without third-party dependencies. It's JS/WASM build necessarily depends on Emscripten, but we've also reimplemented all of that glue except for the parts which provide the WASM imports, which are closely tied to the compilation process so cannot simply be swapped out.
> Roy has a great range of example VFSs you can learn from too.
FWIW, his work has been a tremendous inspiration for the sqlite project's JS code, and the 2nd OPFS VFS is a direct port of one of his VFSes.
It does seem to suffer from maintainer problems too though, and I don't blame Roy Hashimoto for that. I wouldn't want to maintain such an obvious wrapper when it should be a task for SQLite's team to upstream the changes.
Roy Hashimoto doesn't want to maintain it as an NPM package for instance, as it is just an experiment: https://github.com/rhashimoto/wa-sqlite/issues/12
"Low traffic is a happy place - I don't have any motivation to mess with that."
As your EDIT notes, Roy (wa-sqlite) has already experimented with this and reports great results. Experimenting with this in the sqlite project's own OPFS VFS (see https://sqlite.org/wasm) is pending, but the feature is not yet widespread enough to replace the current VFSes. We've no information on how long it will take for the other browsers to catch up with that API. Until then, the sqlite project offers two OPFS VFSes, one of which trades speed for a moderate degree of cross-tab concurrency and another which offers tremendous speed but a complete lack of concurrency.
I believe this route with WASM is the correct one. WebSQL would have been tied to one single version of SQLite, with no alternative implementation.
With browsers adopting safe low level APIs like WASM and OPFS it enables a much broader range of databases to be available in the browser. We already have SQLite, DuckDB and various vector dbs.
OPFS is still under active development, but with some of the changes coming to it in 2024 it's going to become significantly better to use.
All of this is part of the enabling tech behind "local-first" apps. I'm somewhat biased as I work on ElectricSQL (we sync Postgres on a server to SQLite in the browser), but 2024 is going to be a supper exciting time for local-first software.
Have you my chance come across a good SQLite vector extension that works in the browser? I haven't found one yet.
An oft-neglected detail in such discussion is that WebSQL was main-thread-only. When WebSQL was designed that was not a serious issue, but it would have been in conflict with the directions web design has since taken, making WebSQL a non-starter for many modern apps.
> WebSQL would have been tied to one single version of SQLite, with no alternative implementation.
Not only that, but with a castrated feature set (e.g. only implicit transactions and lack of many of sqlite's SQL functions). When trying to benchmark WebSQL vs the sqlite project's WASM build, that castration makes it difficult to get apples-to-apples comparisons.
I also want to leverage the web platform (mainly because it's the right thing to do and partly because the web is the only one that offers a decent rich-editor environment without as much plumbing needed if I build natively). So basically a browser app that behaves fully like a desktop app without any needing internet connection.
And for that idea to become reality james long's absurd sql is basically the key. Without such persistent sql based db to work with, that ideas is never going to materialize :)
No affiliation, just interesting project that aligns with your description.
[0]: https://anytype.io/ [1]:https://news.ycombinator.com/item?id=38794733
[1]: https://sqlsync.dev/posts/stop-building-databases/, https://sqlsync.dev/
Treating a browser like a real client application is putting lipstick on a pig. The harder you try, the uglier it gets.
Unless the developer adds synchronisation primitive to sync data between multiple clients all data are local.
I agree with the other commenter though that by putting a DB on the client, you’re implicitly trusting that client more than usual to only make acceptable changes to the DB. If you’re working in a sensitive context, I think Local First means you’ll have to spend some extra time planning out data security
If you recall from the SQLite story, it was created, in-part, to provide a local cache to an offline device yet still have the same query interface that developers enjoy. Because the model of access is shifted to the device, anything you populate a client-side SQL database with is already data that is accessible by the client.
Disgraceful that Apple does this in the name of privacy, when this implies less privacy and pushes people to either build apps (with much of Apple's economic gain) or some centralised database (at the expense of data protection).
Is there any browser based databases with backend synchronisation and E2E encryption included?
A future for SQL on the web - https://news.ycombinator.com/item?id=28156831 - Aug 2021 (218 comments)