TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Sqlite3 WebAssembly

647 pointsby whatever37 months ago

24 comments

simonw7 months ago
Something that would be really fun would be to run SQLite in-memory in a browser but use the same tricks as Litestream and Cloudflare Durable Objects (<a href="https:&#x2F;&#x2F;simonwillison.net&#x2F;2024&#x2F;Oct&#x2F;13&#x2F;zero-latency-sqlite-storage-in-every-durable-object&#x2F;" rel="nofollow">https:&#x2F;&#x2F;simonwillison.net&#x2F;2024&#x2F;Oct&#x2F;13&#x2F;zero-latency-sqlite-st...</a>) to stream a copy of the WAL log to a server (maybe over a WebSocket, though intermittent fetch() POST would work too).<p>Then on subsequent visits use that server-side data to rehydrate the client-side database.<p>From <a href="https:&#x2F;&#x2F;sqlite.org&#x2F;forum&#x2F;info&#x2F;50a4bfdb294333eec1ba4749661934521af19e6fc0790a6189696607f67c2b54?t=h" rel="nofollow">https:&#x2F;&#x2F;sqlite.org&#x2F;forum&#x2F;info&#x2F;50a4bfdb294333eec1ba4749661934...</a> is looks like WAL mode is excluded from the default SQLite WASM build so you would have to go custom with that.
评论 #41853089 未加载
评论 #41854586 未加载
评论 #41856415 未加载
评论 #41852040 未加载
评论 #41858635 未加载
评论 #41854540 未加载
评论 #41857000 未加载
评论 #41852194 未加载
评论 #41854654 未加载
评论 #41855596 未加载
simonw7 months ago
Slight point of confusion: that page says:<p>&gt; 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.<p>But the most recent release of SQLite is 3.46.1 (from 2024-08-13)<p>Presumably they are now &quot;API-stable&quot; but the page hasn&#x27;t been updated yet.<p>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.)<p>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 <a href="https:&#x2F;&#x2F;lite.datasette.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;lite.datasette.io&#x2F;</a> and you can also try it out on <a href="https:&#x2F;&#x2F;pyodide.org&#x2F;en&#x2F;stable&#x2F;console.html" rel="nofollow">https:&#x2F;&#x2F;pyodide.org&#x2F;en&#x2F;stable&#x2F;console.html</a><p><pre><code> import sqlite3 print(sqlite3.connect(&#x27;:memory:&#x27;).execute( &#x27;select sqlite_version()&#x27; ).fetchall()) </code></pre> 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: <a href="https:&#x2F;&#x2F;github.com&#x2F;emscripten-core&#x2F;emscripten&#x2F;blob&#x2F;main&#x2F;tools&#x2F;ports&#x2F;sqlite3.py">https:&#x2F;&#x2F;github.com&#x2F;emscripten-core&#x2F;emscripten&#x2F;blob&#x2F;main&#x2F;tool...</a>
评论 #41853076 未加载
评论 #41851565 未加载
评论 #41851515 未加载
评论 #41852552 未加载
评论 #41851901 未加载
koeng7 months ago
For use in Golang, I really like ncruces wasm SQLite package - <a href="https:&#x2F;&#x2F;github.com&#x2F;ncruces&#x2F;go-sqlite3">https:&#x2F;&#x2F;github.com&#x2F;ncruces&#x2F;go-sqlite3</a> . Unlike cznic&#x27;s go package (which is great, btw), the wasm version works well on OpenBSD and the like.
评论 #41853244 未加载
parhamn7 months ago
WebSQL should&#x27;ve just been Sqlite and the whole offline-first (and general app storage) ecosystem would&#x27;ve been so much nicer.<p>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?
评论 #41852850 未加载
评论 #41861101 未加载
评论 #41852879 未加载
catapart7 months ago
I wasn&#x27;t able to tell from a quick look through the page: could someone help me understand the use cases here?<p>More specifically, would this be able to be a &quot;replacement&quot; for indexedDB? Does the data persist, or do I need to keep the sqlite file in the filesytemAPI (or indexedDB&#x2F;localstorage) myself?
评论 #41852717 未加载
chrysoprace7 months ago
I&#x27;ve been really interested in the local-first landscape lately but embedding SQLite seems really heavy-weight compared to using the browser&#x27;s built-in storage APIs (in particular, IndexedDB) and it seems to be what most of the main open source libraries do. I&#x27;m interested to see a open-source solution (with sync) which provides an SQLite-like API but for the browser&#x27;s native storage rather than trying to embed another executable in Web Assembly.
评论 #41854825 未加载
评论 #41854044 未加载
评论 #41855967 未加载
TiredGuy7 months ago
So after downloading from the official downloads page and stripping away all the mjs files and &quot;bundler-friendly&quot; files, a minimal sqlite wasm dependency will be about 1.3MB.<p>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.
评论 #41851622 未加载
评论 #41851724 未加载
评论 #41851618 未加载
评论 #41851337 未加载
评论 #41851840 未加载
评论 #41854092 未加载
评论 #41852258 未加载
评论 #41855860 未加载
brandonpollack27 months ago
I was trying to get this working in a rust ecosystem some time ago but none of the blessed.rs sql (rusqlite, sqlx) wrappers seem to take advantage of it yet and wrapping it yourself is a bit tricky since when I was trying I couldn&#x27;t figure out a way to to get emscripten wasm code to play nice with wasm32-unknown-unknown without some kind of JS wrapper which then requires implementing the interface those crates expect and exposing it from JS. Once that is done in rust itll be great there too!
评论 #41852996 未加载
评论 #41853144 未加载
评论 #41854660 未加载
评论 #41852082 未加载
bhelx7 months ago
I used the wasm build of sqlite and the Chicory runtime to create a pure JVM executed sqlite library: <a href="https:&#x2F;&#x2F;github.com&#x2F;dylibso&#x2F;sqlite-zero">https:&#x2F;&#x2F;github.com&#x2F;dylibso&#x2F;sqlite-zero</a><p>It&#x27;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.
评论 #41853167 未加载
jjcm7 months ago
As a general question, in what scenarios is it more beneficial to send the full DB and let the browser handle the queries? Maybe phrased a better way - when would I use this to improve a user experience over the traditional server-hosted db model?
评论 #41852807 未加载
评论 #41851976 未加载
评论 #41851993 未加载
评论 #41855888 未加载
runarberg7 months ago
I’m working on a hobby-project that uses IndexedDB for persistent client-side storage, and it really feels like W3C made some very bad design decision and than instead of fixing they they have just given up on the standard. Issues like not being able to index values in objects in arrays [1] (not even in fixed position e.g. &quot;key.path.[0].value&quot;) despite almost a decade of developers asking for it, a very limited query syntax, and even the documentation on MDN seems of very lower quality than the rest of the web docs.<p>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.<p>1: <a href="https:&#x2F;&#x2F;github.com&#x2F;w3c&#x2F;IndexedDB&#x2F;issues&#x2F;35">https:&#x2F;&#x2F;github.com&#x2F;w3c&#x2F;IndexedDB&#x2F;issues&#x2F;35</a>
outlore7 months ago
i’ve been looking for a Tanstack Query style library that is backed by Sqlite (backed by OPFS or some other browser storage) and syncs with an API in the background. Does anything like that exist? i’ve seen ElectricSQL and other sync engines but they are a bit opinionated. I’m pretty new to local-first but i feel like the developer ergonomics are not quite there yet<p>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
评论 #41851686 未加载
评论 #41851613 未加载
评论 #41854685 未加载
评论 #41851366 未加载
delduca7 months ago
It would be great if Go had a WebAssembly runtime with simple interoperability, so I could stop using CGO (I need to use it because SQLite in Go depends on CGO. There’s a Go version, but I don’t trust using transpiled code).
shautvast7 months ago
Shameless plug for the fastest way to get the serverdata to the client: just send data in the format that sqlite itself uses: <a href="https:&#x2F;&#x2F;gitlab.com&#x2F;sander-hautvast&#x2F;sqlighter" rel="nofollow">https:&#x2F;&#x2F;gitlab.com&#x2F;sander-hautvast&#x2F;sqlighter</a> (available in java and rust, no dependencies on sqlite itself). This works well with the wasm build. The java project contains a demo that also shows how to setup the UI code.
me551ah7 months ago
After years of being able to run SQLite on my mobile phone, my tv, my router and gaming consoles, I can finally run it on my browser. Which also happens to be running on the most powerful machine I own
评论 #41852109 未加载
koolala7 months ago
The CORS restrictions &#x2F; needing SharedArrayBuffer support kinda stinks.<p>There is no way to use Sqlite3 off-thread without memory sharing? Couldn&#x27;t postMessage work to pass data to the sqlite thread by using the third Transfer argument?<p>Would postMessage transfer allow memory to be stored in a sqlite wasm database running a worker off-thread?<p>Refering to this implementation&#x27;s docs: <a href="https:&#x2F;&#x2F;github.com&#x2F;sqlite&#x2F;sqlite-wasm">https:&#x2F;&#x2F;github.com&#x2F;sqlite&#x2F;sqlite-wasm</a>
评论 #41854755 未加载
baudaux7 months ago
I definitely have to put sqlite in <a href="https:&#x2F;&#x2F;exaequOS.com" rel="nofollow">https:&#x2F;&#x2F;exaequOS.com</a>
gnarbarian7 months ago
How long until we see WebAssembly&#x2F;WebGPU become a platform independent choice for deploying server side code as well?
评论 #41852090 未加载
评论 #41852575 未加载
评论 #41851398 未加载
评论 #41851405 未加载
评论 #41852681 未加载
k__7 months ago
Half-OT:<p>What&#x27;s your opinion on SQLite in-memory vs plain objects&#x2F;arrays?<p>When would you use which and why?
kohlerm7 months ago
WASM ATM is IMHO most useful for VSCode Extension, where it can help to avoid the dependency nightmare that nodejs modules with native code cause.
emrah7 months ago
Fwiw, duckdb is replacing sqlite for me, particularly due to its rich plugin ecosystem
baq7 months ago
See also <a href="https:&#x2F;&#x2F;github.com&#x2F;electric-sql&#x2F;pglite">https:&#x2F;&#x2F;github.com&#x2F;electric-sql&#x2F;pglite</a> (REPL at <a href="https:&#x2F;&#x2F;pglite.dev&#x2F;repl&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pglite.dev&#x2F;repl&#x2F;</a>)<p>(Previously discussed 7 months ago: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=39477457">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=39477457</a>)
benthecarman7 months ago
Whats needed is a rust-wasm compatible library that can use this.
评论 #41852964 未加载
throwaway815237 months ago
Why have this instead of making it a browser API?