simolus3 / drift

Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.
https://drift.simonbinder.eu/
MIT License
2.65k stars 370 forks source link

libsql / Turso Web build #3330

Closed KP-Jaco closed 3 days ago

KP-Jaco commented 5 days ago

I am just doing some preliminary research on what it would take to create a Turso flavor of the wasm build for use in flutter WEB. Their recent announcement about offline writes is quite exciting, but I have a multiplatform app that uses drift currently running on Android, iOS and Web so I'm trying to understand where this work would need to happen. Would there need to be a custom build of libsql for wasm?

simolus3 commented 3 days ago

It's probably easier to write a Dart wrapper around the official JS SDK for turso and then use that instead of using the sqlite3.wasm shipped with sqlite3.dart.

package:sqlite3 has its own custom sqlite3 build that is different from what Turso is doing (they've forked the upstream sqlite3 wasm builds, which is a different setup). The last time I've checked, the actual synchronization bits weren't in libSQL directly and instead parts of different Rust crates, I'm not sure how they end up being compiled for the web in the end. Looking at this, probably not at all.

We have an example here that shows how to do custom sqlite3 compilations with extensions written in Rust for the web. That might be useful as a starting point to port parts of the synchronization stuff over. (if you don't need offline functionality on the web though, you can use drift_hrana already without any external WebAssembly modules).