Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] WebAssambly build #233

Open
panstromek opened this issue Feb 22, 2019 · 10 comments
Open

[Request] WebAssambly build #233

panstromek opened this issue Feb 22, 2019 · 10 comments

Comments

@panstromek
Copy link

I am not sure how much is this possible, but I would like to use this library compiled do to WASM. I know there are some projects that already compile SQLite to WASM or ASM.js (most notably SQL.js), but honestly I like your API the most, and some of these are not mature enough.

Main reason is that I use this on multiple different devices and I have often problem with compiling it. I cannot always cross compile so I need to build the package on the target device during deployment, which often fails for some obscure reasons and behaves differently on each device.

WASM is supported in Node without compilation during installation. This would allow me to bundle everything and deploy without compiling anything.

Moreover, I need to use the database in a browser, and this would allow me to reuse code without creating some adapters, because mentioned libs have have slightly different APIs.

I am really not sure if that is even possible here, though ;) thx for great lib anyway ;)

@JoshuaWise
Copy link
Member

It's an interesting request. I can see the benefits, but I'm not familiar enough with WebAssembly to charge forward right now.

@lygstate
Copy link

+1 for wasm

@only-cliches
Copy link

only-cliches commented Aug 25, 2019

I actually compiled SQLite to webassembly for one of my projects, it works great except for Windows. The file directory/structure provided by Node doesn't allow the underlying SQLite functions to mount or read a database, I wasn't able to find a way around this and abandoned SQLite for WASM. It does work just fine in the browser (for memory databases) and MacOS/Linux.

A working build script and files are here if anyone wants to work with it:
https://github.com/ClickSimply/snap-db/tree/688bcd86b434f357bb73f702d65c8964a5978a29/src-wasm

@s20208413
Copy link

Error while building better-sqlite3 with node-gyp on Android (termux). I can post more error information later. But building node-sqlite3 on Android is OK.

So WebAssembly is also useful here.

@lygstate
Copy link

lygstate commented Mar 7, 2020

@micahscopes
Copy link

Hey, seems like the technology is gradually getting more mature for this. I'd imagine using a WASI build of sqlite3 (example here) along with the built in WASI implementation in Node 16 could be a way to make this happen.

Other WASM versions of sqlite, such as websql or sql.js, don't have a simple cross platform way of interacting with the file system. This is the big benefit of WASI. It gives a standard sandboxed system interface for stuff like file system access.

Implementing a WASI/Node option could mitigate issues like #694 and make downstream cross platform distribution much more sustainable.

@lukebayes
Copy link

Just chiming in here, I love this library and want to use it in the browser for a wasm-based sqlite3 deployment.

It seems the Sqlite project is taking on Wasm as a supported platform target.

I haven't dug in too deep yet, but just trying to build better-sqlite3 for a browser using esbuild's current instructions, I get a handful of errors (23x in better-sqlite v7.6.2).

These are essentially in 2 categories:

Node libraries like: path, util and fs

✘ [ERROR] Could not resolve "path"

    node_modules/file-uri-to-path/index.js:6:18:
      6 │ var sep = require('path').sep || '/';~~~~~~

Destructuring assignments

✘ [ERROR] Transforming destructuring to the configured target environment ("chrome58", "edge16", "firefox57", "safari11") is not supported yet

    node_modules/better-sqlite3/lib/methods/serialize.js:2:6:
      2 │ const { cppdb } = require('../util');

For the second issue (destructuring), I was able to update my build to target edge18 instead of edge16 and this resolved that set and left me with only 8 errors of the first variety.

I'm going to take a look and see if there are some simple things that could get us running in the browser.

@lukebayes
Copy link

It's more complicated than I hoped and I've got to get some sleep tonight. I'll try to make some time to take another look in the next week or two.

Any thoughts or tips would be appreciated.

Thanks again for a great library!

@cellvia
Copy link

cellvia commented Feb 15, 2023

wasm build of sqlite3 has gone official…having this api in the browser would be most excellent

bump!

@flaviut
Copy link

flaviut commented Sep 25, 2023

Looks like @tndrle has implemented exactly this, with some small limitations: https://github.com/tndrle/node-sqlite3-wasm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

9 participants