Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run offline database usage in Blazor WebAssembly-PWA?

I have a Blazor WebAssembly ASP.NET Core hosted - PWA application and want to run it offline. The database is currently built with SQLite and EF-Core. Is it possible to add offline functionality? I have read about IndexedDB but don't actually know how to implement that into the project (client-side). Or is there any NuGet Package for this support?

The functionality I want to bring into the project is - tracking local changes and fetching them to the DB when its online again.

like image 799
brstkr Avatar asked Jul 05 '20 19:07

brstkr


4 Answers

I've created a library that provides bi-directional offline sync for mobile clients that should do the job: https://github.com/stefffdev/NubeSync

Especially handling conflict resolution when multiple clients did change a record can become tricky, so you could use that as a starting point.

I plan to create a blazor wasm offline sample and blog about it soon.

like image 58
stefffdev Avatar answered Oct 06 '22 11:10

stefffdev


check This example, uses javascript to store locally in the browser

like image 21
Jim K Avatar answered Oct 06 '22 10:10

Jim K


You can try this package. This is a Blazor library to work with IndexedDB DOM API

https://github.com/amuste/DnetIndexedDb

like image 1
copycat_am Avatar answered Oct 06 '22 12:10

copycat_am


I'm using event sourcing to solve this problem. It deals well with syncing occasionally connected clients as described here. It means dropping entity framework and probably rearchitecting your entire persitance tech stack, so it is far from ideal. But if you plan on building a large complicated system, this is the way to go.

like image 1
DharmaTurtle Avatar answered Oct 06 '22 11:10

DharmaTurtle