Tavenem.Blazor.IndexedDB 6.0.6

Prefix Reserved
dotnet add package Tavenem.Blazor.IndexedDB --version 6.0.6
                    
NuGet\Install-Package Tavenem.Blazor.IndexedDB -Version 6.0.6
                    
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="6.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tavenem.Blazor.IndexedDB" Version="6.0.6" />
                    
Directory.Packages.props
<PackageReference Include="Tavenem.Blazor.IndexedDB" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tavenem.Blazor.IndexedDB --version 6.0.6
                    
#r "nuget: Tavenem.Blazor.IndexedDB, 6.0.6"
                    
#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.
#:package Tavenem.Blazor.IndexedDB@6.0.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tavenem.Blazor.IndexedDB&version=6.0.6
                    
Install as a Cake Addin
#tool nuget:?package=Tavenem.Blazor.IndexedDB&version=6.0.6
                    
Install as a Cake Tool

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. Register the IndexedDbService with dependency injection.

    builder.Services.AddIndexedDbService();
    
  2. Register one or more IndexedDb instances with dependency injection.

    // simple
    builder.Services.AddIndexedDb("myDatabaseName");
    
    // all options
    builder.Services.AddIndexedDb(
        databaseName: "myDatabaseName", // the database name
        objectStores: ["valueStore"], // the names of value stores
        version: 2, // the version number of the current database schema
        jsonSerializerOptions: options); // a JsonSerializerOptions instance
    

    Note that use of dependency injection for database instances is optional. They can also be initialized on demand with their public constructor, which requires an instance of IndexedDbService.

  3. Inject an IndexedDb instance in a component.

    [Inject(Key = "myDatabaseName")] private IndexedDb MyDatabase { get; set; } = default!;
    

    Note that the @inject directive does not currently support keyed services.

  4. Retrieve an IndexedDbStore instance by name.

    var store = MyDatabase["valueStore"];
    
  5. Call the StoreItemAsync<T>, GetItemAsync<T>, and RemoveItemAsync<T> methods on an IndexedDbStore to work with strongly-typed data items.

    class Item : IIdItem
    {
        public string Id { get; set; }
        public string? Value { get; set; }
    }
    
    var item = new Item
    {
        Id = "1",
        Value = "Hello, World!",
    };
    
    await store.StoreItemAsync(item);
    
    item.Value = "Goodbye!";
    await store.StoreItemAsync(item);
    
    var fetchedItem = await store.GetItemAsync<Item>(item.Id);
    // fetchedItem is an Item instance: item.Value == "Goodbye!"
    
    await store.RemoveItemAsync(item);
    
    fetchedItem = await store.GetItemAsync<Item>(item.Id);
    // fetchedItem is null
    
  6. 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 store.Query<Item>().AsAsyncEnumerable())
    {
        Console.WriteLine(item.Value);
    }
    
    var helloCount = await store
        .Query<Item>()
        .Select(x => x.Value != null && x.Value.Contains("Hello"))
        .CountAsync();
    
  7. Call the ClearAsync, CountAsync, and GetAllAsync<T> methods to work with the full object store.

    await store.StoreItemAsync(item);
    
    var count = await store.CountAsync();
    // count = 1
    
    var items = await store.GetAllAsync<Item>();
    // items is an array of Items with Length 1
    
    await store.ClearAsync();
    count = await store.CountAsync();
    // count = 0
    
  8. Call the DeleteDatabaseAsync method on the IndexedDb instance to remove the entire database.

    await MyDatabase.DeleteDatabaseAsync();
    // the database has been removed (or will be, after all connections are closed)
    

Roadmap

New versions of Tavenem.IndexedDb should be expected whenever the API surface of the Tavenem DataStore library receives an update.

Other updates to resolve bugs or add new features may occur at any time.

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 net8.0 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
6.0.6 207 6/24/2025
5.1.4 977 1/24/2025
5.0.2 415 12/27/2024
4.2.4 183 12/17/2024
4.1.4 257 11/21/2024
4.0.2 1,334 6/30/2024
3.0.2 819 3/20/2024
2.3.4 177 3/5/2024
2.2.4 168 2/12/2024
2.1.2 223 11/29/2023
2.0.3-preview1 227 12/4/2022
2.0.1 156 11/27/2023
1.0.0 688 12/8/2021