Most active commenters
  • sgbeal(4)
  • simonw(3)

←back to thread

Sqlite3 WebAssembly

(sqlite.org)
506 points whatever3 | 16 comments | | HN request time: 0.596s | source | bottom
1. simonw ◴[] No.41851270[source]
Slight point of confusion: that page says:

> 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...
replies(5): >>41851515 #>>41851565 #>>41851901 #>>41852552 #>>41853076 #
2. rblank ◴[] No.41851515[source]
https://github.com/sqlite/sqlite-wasm

sqlite-wasm loads much faster than Pyodide, so if you don't need Python, then the former is a better choice.

replies(1): >>41851545 #
3. simonw ◴[] No.41851545[source]
Amazing!

    npm install @sqlite.org/sqlite-wasm
replies(2): >>41851670 #>>41851788 #
4. Ciantic ◴[] No.41851565[source]
> 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.

I think they've been doing that for a while, in JS script you can already do this:

    import sqlite3InitModule from "https://cdn.jsdelivr.net/npm/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs";

    const sqlite3 = await sqlite3InitModule({
        locateFile(file: string) {
            return "https://cdn.jsdelivr.net/npm/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3.wasm";
        },
    });

    // SQLite's C API
    const capi = sqlite3.capi;
    console.log("sqlite3 version", capi.sqlite3_libversion(), capi.sqlite3_sourceid());

    // OO API example below oo1 docs https://sqlite.org/wasm/doc/tip/api-oo1.md
    const oo = sqlite3.oo1;

    const db = new oo.DB();
    const createPersonTableSql = `
    CREATE TABLE IF NOT EXISTS person (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        name TEXT NOT NULL,
        age INTEGER NOT NULL
    );
    `;
    db.exec([createPersonTableSql]);
It works in regular old script tag with type=module, or Deno. I have example HTML here:

https://github.com/Ciantic/experimenting-sqlite-wasm/blob/ma...

replies(1): >>41854738 #
5. wg0 ◴[] No.41851670{3}[source]
This would run on client side I presume? Where the data would go?

Okay that's listed here: https://sqlite.org/wasm/doc/trunk/persistence.md

EDIT: Self answered.

6. simonw ◴[] No.41851788{3}[source]
I built my own little demo page here: https://tools.simonwillison.net/sqlite-wasm

With the help of Claude, though it incorrectly hallucinated some of the details despite me pasting in documentation: https://gist.github.com/simonw/677c3794051c4dfeac94e514a8e5b...

7. CodeWriter23 ◴[] No.41851901[source]
> 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.

You may benefit from perusing the FAQ on that page.

8. jarpineh ◴[] No.41852552[source]
You can use DuckDB WASM independently of Pyodide and can extend it with SQLite.

Though it seems to be somewhat limited. I couldn't even check what version it has, since sqlite_version() was missing. Version in the repository [1] is 3.38.1, which is from quite a ways ago.

At the moment DuckDB web shell can't load SQLite extension, since that hasn't been released for yesterday's 1.1.2. Earlier version does work using recently updated WASM edition. That can be extended with spatial including GDAL, vector search etc [2]. Making your own "SQL web shell" wasn't too hard, though docs weren't quite complete enough for me.

[1] https://github.com/duckdb/sqlite_scanner/blob/main/src/sqlit... [2] https://github.com/duckdb/duckdb-wasm/releases/tag/v1.29.0

9. sgbeal ◴[] No.41853076[source]
> Presumably they are now "API-stable" but the page hasn't been updated yet.

That's correct. i'll try my best to remember to update that reference the next time i'm back on the computer.

> It would be great if the SQLite team published an official npm package

Not a chance. We publish only vanilla JS and adamantly refuse to go down the rabit hole of supporting out-of-language tools (none of which any of our project members use). We support an "officially sanctioned" npm build, maintained by Thomas Steiner, but do not actively develop for any JS frameworks.

Direct support for any given framework (npm included) would give the impression that we endorse that framework, and endorsement of third-party projects is something we actively avoid.

replies(1): >>41853135 #
10. rezonant ◴[] No.41853135[source]
> We publish ONLY vanilla JS and adamantly refuse to go down rabit hole of supporting the frameworks du jour

A bit confused at this, NPM is just a package manager / distribution mechanism, not a framework. Totally fair if you don't want to publish for all the package managers, though for Javascript there's only a few that are relevant. NPM has been around for a decade.

replies(1): >>41853181 #
11. sgbeal ◴[] No.41853181{3}[source]
> A bit confused at this, NPM is just a package manager / distribution mechanism, not a framework

It's an out-of-language packaging/distribution framework (and it's not the only one). It's not part of the JS standards.

My comments above have been edited to reframe our stance on npm and frameworks in general.

replies(2): >>41853749 #>>41853977 #
12. rezonant ◴[] No.41853749{4}[source]
I don't think there will ever be a package manager dictated by the Ecmascript standards.
replies(1): >>41854172 #
13. samatman ◴[] No.41853977{4}[source]
I think the communication barrier here is that in JavaScript, framework very distinctly means things like React, Vue, Angular, and so on. It definitely does not refer to projects like Node/npm/Bun/Deno, those are toolchains, sometimes called ecosystems for obscure reasons.

If you changed the word "framework" to "toolchain" in your post I think it would make a lot more sense to people.

replies(1): >>41854657 #
14. syndicatedjelly ◴[] No.41854172{5}[source]
Then ES will continue to remain an outlier among major language implementations
15. sgbeal ◴[] No.41854657{5}[source]
> If you changed the word "framework" to "toolchain" in your post I think it would make a lot more sense to people.

Fair point but the edit window has passed ;). For the sake of clarity for those still following along: "framework," in the context of my above comments, includes any non-formally-standardized tools or APIs which are built atop the standardized core.

16. sgbeal ◴[] No.41854738[source]
> > It would be great if the SQLite team published an official npm package

> I think they've been doing that for a while,

Kinda: <https://sqlite.org/wasm/doc/trunk/npm.md>

We in the sqlite project neither use nor require npm in any capacity whatsoever, so it would be kinda silly for us to attempt to support it. We instead leave that level of code/tools to folks who use and/or care about them.

There _is_ an "officially sanctioned/blessed" npm repo, and we actively support its maintainer (e.g. we participate the issue tracker and make patches in the core distribution where they're strictly needed), but we otherwise keep a "hands off" policy when it comes to non-standardized APIs and toolchains.

We _like_ to see people to plug the sources into their tools of choice, but we cannot feasibly take on the burden of doing that plugging-in for them, especially given how fluid the JavaScript ecosystem is when it comes to frameworks and tools.

Sidebar: we rely heavily on Emscripten because there is, for all practical purposes, it has no substitute, but we also actively go out of our way to ensure that the sources can be easily plugged in to an alternative should one ever appear.