wtulloch / Blazor.IndexedDB

A Blazor library for accessing IndexedDB
MIT License
140 stars 46 forks source link

Dynamic / Simplified Setup #9

Closed andrewwilkin closed 5 years ago

andrewwilkin commented 5 years ago

Firstly, looks like a great library - so thanks.

I'm currently re-writing a Web.Api / React dashboard app in Blazor, and have lots of meta data that drives the application.

So naturally am looking at ways to cache this locally so the startup is faster. Have tested Local Storage which seems to work in initial testing.

Wanted to look at IndexedDB, the thing that puts me off at the moment is the needing to setup in the startup class and maintain all the stores in there, also the need to create the indexes manually for each store.

I see a recent change to add stores dynamically, would this in part go towards this? Is there an easy way of creating the store based upon a POCO?

wtulloch commented 5 years ago

Sorry for the extremely late response.

Part of the reason for initialising in the start-up is based on how IndexedDB works under the covers. It uses a versioning system to determine it's state when creating or modifying the underlying database. For example, given we have a store called Employees and the version is set to 1. If I try to add another store and I don't update the version number IndexedDB won't add the new store.

The ability to dynamically add a new store dynamically gets around this by updating the version automatically. Given this, in theory, you could by-pass the start-up though I would still use it to ensure that the database exists even if you don't add any stores at that point.

In regard to creating a store based on POCO have a look at Reshiru's solution which uses this library to handle the IndexedDB interaction but adds some features such as using attributes to define the indexes.