JeremyLikness / SqliteWasmHelper

Persistent SQLite in Blazor WebAssembly apps with EF Core 6.0 and your browser's cache.
https://youtu.be/ZeJISZgy-FM
MIT License
110 stars 24 forks source link

Embrace EF Core 8 and SQLite with Bit.Besql: A revamped Alternative to SqliteWasmHelper #34

Open ysmoradi opened 8 months ago

ysmoradi commented 8 months ago

Microsoft.EntityFramework 8 introduces significant enhancements for client-side database context usage, including:

1- Exception-free SQLite migrations: EF Core 8 seamlessly rebuilds tables during migrations if required, eliminating the need for manual workarounds previously required. This improved migration functionality is particularly crucial for client-side applications.

2- Performance gains for large model classes: Compiled models offer substantial performance improvements for DB contexts with numerous model classes. This optimization enhances the overall startup time of client-side applications.

3- Unlocked SQLite JSON features: EF Core 8 unlocks the full range of SQLite JSON features, enabling developers to store and manipulate JSON data more effectively. This expansion of JSON capabilities enhances the flexibility and data richness of client-side applications.

4- Enhanced asynchronous API: EF Core 8 provides a more comprehensive asynchronous API, making it easier to perform database operations in a non-blocking manner, improving the responsiveness of client-side applications.

The current library, however, requires several enhancements to fully leverage the benefits of EF Core 8:

1- EF Core 8 and migrations support: The library should be updated to support EF Core 8's latest features, including migrations, to ensure compatibility with modern development practices.

2- IDbContextFactory injection: The library should allow the injection of IDbContextFactory instead of ISqliteWasmDbContextFactory, enabling developers to share code seamlessly between Blazor hybrid and server applications. The current reliance on ISqliteWasmDbContextFactory can be restrictive and even harmful in such scenarios.

3- Simplified database creation and migration: Developers should have a straightforward way to either execute DbContext.Database.CreateAsync() or DbContext.Database.MigrateAsync() instead of providing an IMigration implementation, to simplify database creation and migration processes.

Initial attempts to contribute to this repository through issues and PRs (1,2) proved ineffective due to slow response times. Therefore, I refactored the code, solved all issues mentioned before and migrated it to our own mono repository. This approach allows for greater control over the development process and ensures timely updates.

Since I already have a mono repository, forking this one would not be feasible. Additionally, I've lost confidence in receiving timely attention for new PRs.

Despite the original code being MIT licensed, I'm willing to credit the original work in our new repository and express my gratitude for @JeremyLikness contributions. I kindly request that Bit.Besql be considered as a replacement in nuget and GitHub repository, as I strive to provide unwavering support to the users.

Thank you for your consideration.

syazdian commented 7 months ago

We’re developing a project for Staples Canada! We initially used Sqlite Wasm Helper up to .net 7, but after upgrading to .net 8, we encountered multiple issues. Fortunately, we switched to Bit.Besql and our project is now running smoothly. We’re grateful to @ysmoradi for creating such a fantastic library, and to @JeremyLikness for launching this project in the first place.

myabuta commented 4 months ago

@syazdian, Just out of curiosity, on your app using Bit.Besql, is it an wasm project with the database being stored in cache? similar to SqliteWasmHelper? Were you able to implement a similar approach as SqliteWasmHelper using Bit.Besql? I cant seem to find enough documentation on it. Thank you in advance

ysmoradi commented 4 months ago

@syazdian, Just out of curiosity, on your app using Bit.Besql, is it an wasm project with the database being stored in cache? similar to SqliteWasmHelper? Were you able to implement a similar approach as SqliteWasmHelper using Bit.Besql? I cant seem to find enough documentation on it. Thank you in advance

You can read more about it here I'd recommend you to watch the video Checkout the sample app

syazdian commented 4 months ago

@syazdian, Just out of curiosity, on your app using Bit.Besql, is it an wasm project with the database being stored in cache? similar to SqliteWasmHelper? Were you able to implement a similar approach as SqliteWasmHelper using Bit.Besql? I cant seem to find enough documentation on it. Thank you in advance

Yes, our project was WASM and Bit.Besql worked very smooth same as SqliteWasmHelper.

myabuta commented 4 months ago

I'm having an issue, both with Bit.Besql and SqliteWasmHelper where the memory consumption increases rapidly, and it doesnt get released. with both libraries, if you create a button that inserts short random string into sqlite, and spam the button, the browser memory consumption grows significantly. When I run on a tablet, it becomes unresponsive (app crashes) when it gets to a certain point. I narrowed down the issue to the .SaveChangesAsync(). I believe the issue is on the "backup/replace" of the database in cache, but I'm not sure.