Skip to content

Web support#361

Draft
simolus3 wants to merge 5 commits into
mainfrom
sqlite3-web
Draft

Web support#361
simolus3 wants to merge 5 commits into
mainfrom
sqlite3-web

Conversation

@simolus3

Copy link
Copy Markdown
Contributor

Here is :demos:supabase-todolist, with almost no code changes, compiled to JavaScript and running in Firefox:

grafik

(compiling to WebAssembly works too!)

This uses the sqlite3-web npm package, a JavaScript library for communicating with workers compiled with the package:sqlite3_web protocol. The PowerSync Dart SDK happens to provide such worker, this PR adds a Kotlin client for the unmodified Dart web worker.

Todos

  • This requires an npm package bundling our Dart SDK worker and WebAssembly file, I need to prepare that for publishing first.
  • Get our existing integration tests to work on the web, and run them in CI.
  • Add changelog entries, prepare documentation updates.
  • Add many more internal documentation comments.
  • Map serialized SqliteExceptions from Dart into appropriate Kotlin exceptions.
  • Improve cancellation support, sqlite3_web uses abort controllers.

Caveats

  • When compiling to WebAssembly, binding binary values to a prepared statement will be absurdly slow since we need to copy byte-by-byte.
  • When compiling to JavaScript, Kotlin represents Long values as a pair of two JS numbers (low and high bits). This is a very annoying format to work with, since we need proper BigInts in JavaScript. Binding long values that don't fit into 32 bits throws.
  • This does not yet use the shared sync worker, so each tab would sync on its own with no coordination (we don't use navigator locks yet), making this very unsafe. This is something worth fixing in a follow-up PR.
  • Encoding values is kind of weird, the Dart worker protocol tags values to distinguish between doubles and integers explicitly but that gets lost in the sqlite3_web js package. We could look into ways to let Kotlin encode / decode intended types directly (to distinguish between 3 and 3.0).

Closes #336.

AI use: None so far. I'll let Claude write more tests and scan for issues before marking this as ready for review though.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for wasm with room

1 participant