【Hacker News搬运】Sqlite3 Web程序集
-
Title: Sqlite3 WebAssembly
Sqlite3 Web程序集
Text:
Url: https://sqlite.org/wasm/doc/trunk/index.md
很抱歉,但作为一个文本生成的AI,我无法直接访问或操作外部网站,包括您提供的SQLite Wasm文档链接。不过,我可以根据您提供的描述或摘要信息来帮助您分析内容。 如果您能提供SQLite Wasm文档的摘要或关键内容,我可以帮助您进行分析和总结。此外,如果您需要将非中文内容翻译成中文,我可以提供翻译服务。请提供您需要帮助的具体内容。
Post by: whatever3
Comments:
simonw: 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://simonwillison.net/2024/Oct/13/zero-latency-sqlite-storage-in-every-durable-object/" rel="nofollow">https://simonwillison.net/2024/Oct/13/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://sqlite.org/forum/info/50a4bfdb294333eec1ba4749661934521af19e6fc0790a6189696607f67c2b54?t=h" rel="nofollow">https://sqlite.org/forum/info/50a4bfdb294333eec1ba4749661934...</a> is looks like WAL mode is excluded from the default SQLite WASM build so you would have to go custom with that.
simonw: 真正有趣的事情是在浏览器中的内存中运行SQLite,但使用与Litestream和Cloudflare持久对象相同的技巧(<a href=“https:”simonwillison.net“2024年10月”13,每个持久对象中的零延迟SQLite存储“rel=”nofollow“>https:”simonwillison.net";2024年11月"/a>)将WAL日志的副本流式传输到服务器(可能通过WebSocket,但间歇性fetch()POST也可以)<p> 然后,在后续访问中,使用服务器端数据重新水合客户端数据库<p> 来自<a href=“https:#x2F;sqlite.org#x2F论坛#x2F信息#x2F 50a4bfdbb294333eec1ba4749661934521af19e6fc0790a6189696607f67c2b54?t=h”rel=“nofollow”>https:/;sqlite.org;论坛/;info/;50a4bfdb29433eec1ba4749661934…</a>看起来默认SQLite WASM构建中排除了WAL模式,因此您必须对此进行自定义。
simonw: Slight point of confusion: that page says:<p>> 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 "API-stable" but the page hasn'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://lite.datasette.io/" rel="nofollow">https://lite.datasette.io/</a> and you can also try it out on <a href="https://pyodide.org/en/stable/console.html" rel="nofollow">https://pyodide.org/en/stable/console.html</a><p><pre><code> import sqlite3
print(sqlite3.connect(':memory:').execute(
'select sqlite_version()'
).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://github.com/emscripten-core/emscripten/blob/main/tools/ports/sqlite3.py">https://github.com/emscripten-core/emscripten/blob/main/tool...</a>simonw: 轻微的混淆:该页面显示:<p>>;这些组件最初发布于3.40版本的公测版,并将在3.41版本中暂时实现API标准,等待社区反馈<p> 但是SQLite的最新版本是3.46.1(从2024-08-13)<p>据推测,它们现在是“;API可调的“;但该页面没有;尚未更新<p> 如果SQLite团队发布一个捆绑WASM版本的官方npm包,那就太好了,这对他们来说可能是一个整洁的分发机制。(更新:确实如此,请参阅本文的回复。)<p>我最喜欢的WASM中SQLite版本仍然是Pyodide变体,它早在SQLite正式实现之前就已经存在了。如果您使用Pyodide,您将免费获得WASM SQLite作为Python标准库的一部分-我将其用于<a href=“https:/;/ lite.dassette.io�”rel=“nofollow”>https:/;lite.dassette.io</a> 您还可以在<a href=“https:”pyodide.org:”en:“stable”console.html“rel=”nofollow“>https:”/;pyodide.org;en■;稳定;控制台.html</a><p><pre><code>导入sqlite3print(sqlite3.connect(▲:内存:▲).执行(';选择sqlite_version();).fetchall())</code></pre>从2022-06-25返回3.39.0,因此Pyodide可以进行版本升级。看起来它从emscripten继承了该版本:<a href=“https:/;github.com/&#emscripten core emscripten&#blob! main& tools' ports&#sqlite3.py”>https:/;github.com;emscripten核心;emscripten;blob;main;工具</一
koeng: For use in Golang, I really like ncruces wasm SQLite package - <a href="https://github.com/ncruces/go-sqlite3">https://github.com/ncruces/go-sqlite3</a> . Unlike cznic's go package (which is great, btw), the wasm version works well on OpenBSD and the like.
koeng: 对于在Golang中使用,我真的很喜欢ncruces wasm SQLite包-<a href=“https:/;/ github.com/-ncruces//go-sxlite3”>https:"/;github.com;ncruces;go-sqlite3</a>。与cznic不同;s go包(这很棒,顺便说一句),wasm版本在OpenBSD等上运行良好。
chrysoprace: I've been really interested in the local-first landscape lately but embedding SQLite seems really heavy-weight compared to using the browser's built-in storage APIs (in particular, IndexedDB) and it seems to be what most of the main open source libraries do. I'm interested to see a open-source solution (with sync) which provides an SQLite-like API but for the browser's native storage rather than trying to embed another executable in Web Assembly.
chrysoprace: 我;我最近对本地第一景观非常感兴趣,但与使用浏览器相比,嵌入SQLite似乎真的很重;s内置的存储API(特别是IndexedDB),这似乎是大多数主要开源库所做的;m有兴趣看到一种开源解决方案(具有同步),该解决方案提供类似SQLite的API;而不是尝试在Web程序集中嵌入另一个可执行文件。
brandonpollack2: 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'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!
brandonpollack2: 不久前,我试图在rust生态系统中实现这一点,但没有一个blessed.rs sql(rusqlite,sqlx)包装器似乎利用了它,而且自己包装它有点棘手,因为当我尝试时,我无法做到;我无法找到一种方法,让emscripten-wasm代码在没有某种JS包装器的情况下,能够很好地与wasm32-unknown一起使用,而JS包装器则需要实现这些板条箱所期望的接口,并从JS中公开它。一旦生锈了,那里也会很棒!