sqlite / sqlite-wasm

SQLite Wasm conveniently wrapped as an ES Module.
580 stars 47 forks source link

Document how to load in a Cloudflare Workers script #47

Closed sorenbs closed 1 year ago

sorenbs commented 1 year ago

Running in-memory SQLite on Cloudflare Workers has a number of use cases.

Cloudflare Workers supports WASM, and previous work by the community suggests that it is possible to get a wasm version of SQLite to run in a workers script.

Documenting how to get the official SQLite WASM distribution to work on Cloudflare Workers would be a great help.

tomayac commented 1 year ago

The package is primarily thought for the browser. It may be possible to get it to run in non-browser environments, but not necessarily. For example, it is known to not currently work on Node.js. If you manage to get it to run on Cloudflare Workers, happy to add a link to documentation to do so in the README.

sorenbs commented 1 year ago

Thank you @tomayac!

I intend to open a bounty to figure out the details and write up instructions for how to get it to work. Would it be okay for such a writeup to be created in this thread, or do you prefer it in an external blogpost? I want to be mindful of not creating unwanted work for you and the team.

tomayac commented 1 year ago

Thank you! Ideally this documentation would live somewhere on someone's blog, or maybe on StackOverflow or so. Just to make clear that it's distinct from the project.

Should this library end up being usable on more platforms, like Node in the future, we would of course document it here.

sgbeal commented 1 year ago

or maybe on StackOverflow or so.

Ha! Pun probably not intended ;).

@sorenbs in the upstream library we have a build which supposedly works with node.js, but none of the upstream devs (🙋) actually use node in any capacity, so we have to rely on the reports of users that it works. The wasm dist file:

https://www.sqlite.org/download.html

(search that page for "wasm") contains a file called sqlite3-node.mjs which you "should" be able to use as a basis. It is not available via npm (none of have any use for npm, either!). Feel free to contact me (stephan sqlite org) if you have feedback for that build (like "it doesn't work at all" or "it works if you change this one part...").

If you can get that working without having to go through npm then we will be happy to host a howto doc on sqlite.org/wasm.

Edit: PS: the prerelease snapshps at https://sqlite.org/wasm/uv/snapshot.html are newer, based on yesterday's trunk. That shouldn't affect you for most stuff, but may if you intended to use one of the OPFS-backed VFSes, as those have received small additions since the 3.43 release.

tomayac commented 1 year ago

Some Node.js experiments in https://github.com/sqlite/sqlite-wasm/pull/48.