Couchbase Lite + Webassembly + .NET6 Native Dependencies

Hello,

I have a theoretical question more than a problem and I’m very new to the CB world.

I have just watched a Microsoft YT video where Steve Sanderson shows off the ability to compile SQLite to webassembly and then link that within his Blazor wasm application.

New Blazor WebAssembly capabilities in .NET 6

While I get the concept at a high level, I’m nowhere near clever enough to understand the intricacies that are involved in these scenarios.

Is this theoretically possible with CBL or is it pie in the sky for x, y and z reasons?

Thanks

This is a fascinating find, well and truly. I don’t know the answer 100% but I know it will hinge on one question:

Can emcc compile LiteCore?

I’m unaware of its capabilities, limitations, or modern C++ support (or if it even compiles C++ at all) but if the answer is yes, then I’d say that pretty much assures that CBL will run in Blazor. Traditionally the thing that kept this from happening is the extreme limitation on I/O (both networked and disk) inside of WebAssembly. Basically without network I/O and proper disk I/O CBL is pretty moot.

The problem with SQLite in WASM is that WASM doesn’t have a filesystem API, because web apps don’t have access to the filesystem. I did hear of an epic hack where somebody got around this by implementing a SQLite virtual filesystem plugin that stores files in a row of an IndexedDB. This is probably not very scalable.

The big showstopper for Couchbase Lite in WASM is that (last I heard) WASM doesn’t yet support threads.

@jens I believe the IndexedDB hack is what is used in this demo. I’ve taken a look at the source code for the demo app and it does use IndexedDB.

dbstorage.js

A quick google regards multi-threading in Blazor does suggest that it’s not quite there yet but plans are in motion.

Real multi-threading in Blazor

I did think it all sounded too easy to be honest. It does give me hope that the holy grail might be achievable in the near future though. It would be pretty cool to have a single wasm app that could utilise CBL’s amazing sync feature and deploy it in a web browser as well.

Cheers