Sqlite3 WebAssembly
SQLite's documentation for WebAssembly and JavaScript outlines resources for using sqlite3 in modern browsers, with APIs moving towards stability in version 3.41 and emphasizing user privacy.
Read original articleThe SQLite project's documentation for WebAssembly (WASM) and JavaScript provides resources for utilizing sqlite3 in modern browsers that support WASM. Initially released in beta with version 3.40, the APIs are expected to reach API-stable status with the upcoming 3.41 release, contingent on community feedback. The site emphasizes that it requires a modern JavaScript-capable browser for optimal functionality and uses client-side storage for preferences without retaining user data server-side, except for logged-in developers. The documentation includes a three-step guide for integrating the sqlite3 WASM module, download options, and technical support avenues. It also features an API index, a cookbook for client-level code, and persistent storage options. Several third-party projects are noted for utilizing this technology, including SQLime, Evolu, and SQLiteNext, among others. The documentation also references earlier implementations of sqlite3 in web browsers and related projects that enhance the functionality of sqlite3 in WASM environments.
- SQLite's WebAssembly and JavaScript APIs enable sqlite3 usage in modern browsers.
- The APIs were released in beta with version 3.40 and are expected to stabilize in version 3.41.
- The documentation includes guides, API indexes, and support resources for developers.
- Several third-party projects are leveraging the sqlite3 WASM technology.
- The site prioritizes user privacy by not storing personal data server-side.
Related
What Happens When You Put a Database in the Browser?
WebAssembly (Wasm) enhances browser capabilities, enabling high-performance apps like DuckDB for ad-hoc queries and Python environments. DuckDB Wasm boosts performance in interfaces like lakeFS, Evidence, and Count. MotherDuck enables local querying, emphasizing efficient data processing.
We sped up Notion in the browser with WASM SQLite
Notion improved web performance with WebAssembly SQLite, enhancing navigation by 20% in modern browsers. SharedWorker architecture managed SQLite queries efficiently, overcoming initial challenges for a seamless user experience.
Notion about their usage of WASM SQLite
Notion enhanced browser performance by integrating WebAssembly SQLite, OPFS, and Web Workers technologies. Overcoming challenges, they improved page navigation by 20%, optimizing SQLite usage for efficient cross-tab queries and compatibility.
SQLite is not a toy database
SQLite is a versatile, serverless database management system that supports advanced features, efficiently handles large datasets, and is suitable for small web applications, countering misconceptions about its limitations.
LocalStorage vs. IndexedDB vs. Cookies vs. OPFS vs. WASM-SQLite
The article compares web storage technologies like LocalStorage, IndexedDB, Cookies, OPFS, and WASM-SQLite, emphasizing their features, limitations, and suitability for modern web applications, particularly highlighting IndexedDB and WASM-SQLite.
- There is interest in using SQLite for local-first applications, but concerns about its weight compared to native browser storage options like IndexedDB.
- Several users express a desire for better integration of SQLite with various programming languages, including Rust and Go.
- Some commenters highlight the need for improved documentation and updates regarding the API stability of SQLite in WASM.
- There are discussions about potential use cases for SQLite in the browser, including offline capabilities and user privacy.
- Users are exploring the possibility of syncing SQLite databases with server-side data for enhanced functionality.
Then on subsequent visits use that server-side data to rehydrate the client-side database.
From https://sqlite.org/forum/info/50a4bfdb294333eec1ba4749661934... is looks like WAL mode is excluded from the default SQLite WASM build so you would have to go custom with that.
> These components were initially released for public beta with version 3.40 and will tentatively be made API-stable with the 3.41 release, pending community feedback.
But the most recent release of SQLite is 3.46.1 (from 2024-08-13)
Presumably they are now "API-stable" but the page hasn't been updated yet.
It would be great if the SQLite team published an official npm package bundling the WASM version, could be a neat distribution mechanism for them. (UPDATE: They do, see replies to this post.)
My favourite version of SQLite-in-WASM remains the Pyodide variant, which has been around since long before the official SQLite implementation. If you use Pyodide you get a WASM SQLite for free as part of the Python standard library - I use that for https://lite.datasette.io/ and you can also try it out on https://pyodide.org/en/stable/console.html
import sqlite3
print(sqlite3.connect(':memory:').execute(
'select sqlite_version()'
).fetchall())
That returns 3.39.0 from 2022-06-25 so Pyodide could do with a version bump. Looks like it inherits that version from emscripten: https://github.com/emscripten-core/emscripten/blob/main/tool...Is there any hope of that happening? Instead of abstracting and over specifying sqlite, can the spec just specify a version of the SQLite API browsers should support and roll the version periodically?
More specifically, would this be able to be a "replacement" for indexedDB? Does the data persist, or do I need to keep the sqlite file in the filesytemAPI (or indexedDB/localstorage) myself?
For an in-browser app, that seems a bit much but of course wasm runs in other places these days where it might make more sense.
It's more of an experiment than an attempt to make something production ready, though I could see it being useful to bring dependency-less sqlite tooling to the JVM ecosystem.
What's your opinion on SQLite in-memory vs plain objects/arrays?
When would you use which and why?
There is no way to use Sqlite3 off-thread without memory sharing? Couldn't postMessage work to pass data to the sqlite thread by using the third Transfer argument?
Would postMessage transfer allow memory to be stored in a sqlite wasm database running a worker off-thread?
Refering to this implementation's docs: https://github.com/sqlite/sqlite-wasm
Meanwhile for “local-only” it would be great to use sqlite in the browser + native file system API so that the db could be stored on the user’s file system and we wouldn’t have to worry about browser storage eviction. i think that could really open up a whole world of privacy preserving offline software delivered through the browser
(Previously discussed 7 months ago: https://news.ycombinator.com/item?id=39477457)
I’m happy that we are actually be able to use SQL in the browser now (although I would rather skip the MBs of the bundle bloat). But I feel like the standards committee will now have even less of a reason to fix the very broken state of IndexedDB.
Related
What Happens When You Put a Database in the Browser?
WebAssembly (Wasm) enhances browser capabilities, enabling high-performance apps like DuckDB for ad-hoc queries and Python environments. DuckDB Wasm boosts performance in interfaces like lakeFS, Evidence, and Count. MotherDuck enables local querying, emphasizing efficient data processing.
We sped up Notion in the browser with WASM SQLite
Notion improved web performance with WebAssembly SQLite, enhancing navigation by 20% in modern browsers. SharedWorker architecture managed SQLite queries efficiently, overcoming initial challenges for a seamless user experience.
Notion about their usage of WASM SQLite
Notion enhanced browser performance by integrating WebAssembly SQLite, OPFS, and Web Workers technologies. Overcoming challenges, they improved page navigation by 20%, optimizing SQLite usage for efficient cross-tab queries and compatibility.
SQLite is not a toy database
SQLite is a versatile, serverless database management system that supports advanced features, efficiently handles large datasets, and is suitable for small web applications, countering misconceptions about its limitations.
LocalStorage vs. IndexedDB vs. Cookies vs. OPFS vs. WASM-SQLite
The article compares web storage technologies like LocalStorage, IndexedDB, Cookies, OPFS, and WASM-SQLite, emphasizing their features, limitations, and suitability for modern web applications, particularly highlighting IndexedDB and WASM-SQLite.