Tavenem.Blazor.IndexedDB 2.0.3-preview1

Prefix Reserved
This is a prerelease version of Tavenem.Blazor.IndexedDB.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Tavenem.Blazor.IndexedDB --version 2.0.3-preview1                
NuGet\Install-Package Tavenem.Blazor.IndexedDB -Version 2.0.3-preview1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tavenem.Blazor.IndexedDB" Version="2.0.3-preview1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tavenem.Blazor.IndexedDB --version 2.0.3-preview1                
#r "nuget: Tavenem.Blazor.IndexedDB, 2.0.3-preview1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Tavenem.Blazor.IndexedDB as a Cake Addin
#addin nuget:?package=Tavenem.Blazor.IndexedDB&version=2.0.3-preview1&prerelease

// Install Tavenem.Blazor.IndexedDB as a Cake Tool
#tool nuget:?package=Tavenem.Blazor.IndexedDB&version=2.0.3-preview1&prerelease                

build NuGet downloads

Tavenem.Blazor.IndexedDB

Tavenem.Blazor.IndexedDB is a Razor class library (RCL) containing a Razor component. It grants managed access to the IndexedDB API.

It uses the idb javascript library by Jake Archibald, and implements the IDataStore interface from the Tavenem DataStore library.

Installation

Tavenem.Blazor.IndexedDB is available as a NuGet package.

Use

  1. Construct an IndexedDb object to define the characteristics of your database.

    // simple
    var db = new IndexedDb("myDatabaseName", 1);
    
    // all options
    var db = new IndexedDb<int>(
        databaseName: "myDatabaseName",
        version: 2,
        storeName: "valueStore");
    

    This object can be a static instance, or you can construct instances dynamically as needed.

  2. Call AddIndexedDb(db) with an IndexedDb instance, or AddIndexedDb(provider => GetMyDatabase()) with a function that supplies one through dependency injection.

  3. Inject the IndexedDbService instance in a component.

  4. Call the StoreItemAsync<T>, GetItemAsync<T>, and RemoveItemAsync<T> methods to work with strongly-typed data items.

    class Item : IdItem
    {
        public int Id { get; set; }
        public string? Value { get; set; }
    }
    
    var item = new Item
    {
        Value = "Hello, World!",
    };
    
    await IndexedDbService.StoreItemAsync(item);
    
    item.Value = "Goodbye!";
    await IndexedDbService.StoreItemAsync(item);
    
    var fetchedItem = await IndexedDbService.GetItemAsync<Item>(item.Id);
    // fetchedItem is an Item instance: item.Value = "Goodbye!"
    
    await IndexedDbService.RemoveItemAsync(item);
    
    fetchedItem = await IndexedDbService.GetItemAsync<Item>(item.Id);
    // fetchedItem is null
    
  5. Call the Query<T> method to obtain an IDataStoreQueryable<T>. IDataStoreQueryable<T> is similar to IQueryable<T>, and can be used to make queries against the data source.

    await foreach (var item in IndexedDbService.Query().AsAsyncEnumerable())
    {
        Console.WriteLine(item.Value);
    }
    
    var helloCount = await IndexedDbService
        .Query()
        .Select(x => x.Value != null && x.Value.Contains("Hello"))
        .CountAsync();
    
  6. Call the ClearAsync, CountAsync, DeleteDatabaseAsync, and GetAllAsync<T> methods to work with the full database.

    await IndexedDbService.StoreItemAsync(item);
    
    var count = await IndexedDbService.CountAsync();
    // count = 1
    
    var items = await IndexedDbService.GetAllAsync<Item>();
    // items is an array of Items with Length 1
    
    await IndexedDbService.ClearAsync();
    count = await IndexedDbService.CountAsync();
    // count = 0
    
    await IndexedDbService.DeleteDatabaseAsync();
    // the database has been removed (or will be, after all connections are closed)
    

Roadmap

Tavenem.IndexedDb v2.0 is currently in a prerelease state. Development is ongoing, and breaking changes are possible before the production release.

No release date is currently set for v2.0 of Tavenem.IndexedDb. The project is currently in a "wait and see" phase while Tavenem.DataStore is in prerelease. When that project has a stable release, a production release of Tavenem.IndexedDb v2.0 will follow.

In the meantime, v1 of Tavenem.IndexedDb is stable and will not undergo any breaking changes. It has a significantly different API. See the v1 branch's README for details.

Contributing

Contributions are always welcome. Please carefully read the contributing document to learn more before submitting issues or pull requests.

Code of conduct

Please read the code of conduct before engaging with our community, including but not limited to submitting or replying to an issue or pull request.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.0.2 25 12/27/2024
4.2.4 102 12/17/2024
4.1.4 106 11/21/2024
4.0.2 1,197 6/30/2024
3.0.2 785 3/20/2024
2.3.4 142 3/5/2024
2.2.4 137 2/12/2024
2.1.2 201 11/29/2023
2.0.3-preview1 192 12/4/2022
2.0.1 135 11/27/2023
1.0.0 604 12/8/2021