### DnetIndexedDb - Installation and Configuration
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Instructions on how to install the DnetIndexedDb NuGet package, add script references, and configure the library within a Blazor application.
```APIDOC
## DnetIndexedDb Installation and Configuration
### Description
This section details the steps required to install and configure the DnetIndexedDb library in your Blazor project.
### Installation Steps
1. **Install NuGet Package**:
Install the `DnetIndexedDb` NuGet package using the .NET CLI or your IDE's package manager.
```bash
dotnet add package DnetIndexedDb
```
2. **Add Script References**:
Add the following script references to your `Index.html` file, ensuring they are placed after the `blazor.webassembly.js` or `blazor.server.js` reference:
```html
```
3. **Create Derived Class**:
Create a C# class that derives from `IndexedDbInterop`. This class will be used to interact with the IndexedDB JavaScript API for your specific database.
```csharp
public class GridColumnDataIndexedDb : IndexedDbInterop
{
public GridColumnDataIndexedDb(IJSRuntime jsRuntime, IndexedDbOptions options)
: base(jsRuntime, options)
{
}
}
```
4. **Configure Database Model**:
Create an instance of `IndexedDbDatabaseModel` to define your database schema, including stores and indexes. You can use the `IndexedDbStore`, `IndexedDbIndex`, and `IndexedDbStoreParameter` classes for this.
```csharp
public class IndexedDbDatabaseModel
{
public string Name { get; set; }
public int Version { get; set; }
public List Stores { get; set; } = new List();
public int DbModelId { get; set; }
}
```
5. **Register Service**:
Register your derived `IndexedDbInterop` class in the `ConfigureServices` method of your `Startup.cs` (or `Program.cs` for Blazor WASM/Server .NET 6+). Use the `AddIndexedDbDatabase` extension method and configure it with your database model.
```csharp
services.AddIndexedDbDatabase(options =>
{
options.UseDatabase(GetGridColumnDatabaseModel()); // Replace with your method to get the model
});
```
6. **Inject and Use**:
Inject the instance of your derived `IndexedDbInterop` class into your Blazor components or pages and start interacting with your IndexedDB.
```csharp
@inject GridColumnDataIndexedDb MyDbService
```
```
--------------------------------
### Install DnetIndexedDb Nuget Package and Add Script References
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Instructions for installing the DnetIndexedDb Nuget package and adding the necessary JavaScript references to your Blazor project's Index.html file. These scripts are required for the library to function correctly.
```html
```
--------------------------------
### Perform Full CRUD Lifecycle with DnetIndexedDb
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
This example demonstrates the complete lifecycle of IndexedDB operations including opening a database, adding records, reading via keys and indexes, updating items, and deleting data. It is designed for use within a Blazor component using dependency injection.
```csharp
@page "/"
@inject GridColumnDataIndexedDb GridColumnDataIndexedDb
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await PerformCrudOperations();
}
}
private async Task PerformCrudOperations()
{
var dbResult = await GridColumnDataIndexedDb.OpenIndexedDb();
if (dbResult == -1)
{
Console.WriteLine("Failed to open database");
return;
}
await GridColumnDataIndexedDb.DeleteAll("TableFieldDtos");
var newRecords = new List
{
new TableFieldDto
{
TableFieldId = 1,
TableName = "Products",
FieldVisualName = "Product Name",
AttachedProperty = "productName",
Width = 200
},
new TableFieldDto
{
TableFieldId = 2,
TableName = "Products",
FieldVisualName = "Price",
AttachedProperty = "price",
Width = 100
}
};
await GridColumnDataIndexedDb.AddItems("TableFieldDtos", newRecords);
var singleRecord = await GridColumnDataIndexedDb.GetByKey("TableFieldDtos", 1);
Console.WriteLine($"Single record: {singleRecord?.FieldVisualName}");
var allRecords = await GridColumnDataIndexedDb.GetAll("TableFieldDtos");
Console.WriteLine($"Total records: {allRecords.Count}");
var rangeRecords = await GridColumnDataIndexedDb.GetRange("TableFieldDtos", 1, 2);
Console.WriteLine($"Records in range: {rangeRecords.Count}");
var indexRecords = await GridColumnDataIndexedDb.GetByIndex("TableFieldDtos", "Products", null, "tableName", false);
Console.WriteLine($"Records by index: {indexRecords.Count}");
var maxKey = await GridColumnDataIndexedDb.GetMaxKey("TableFieldDtos");
var minKey = await GridColumnDataIndexedDb.GetMinKey("TableFieldDtos");
Console.WriteLine($"Key range: {minKey} - {maxKey}");
foreach (var record in allRecords)
{
record.Width += 50;
record.FieldVisualName += " (Modified)";
}
await GridColumnDataIndexedDb.UpdateItems("TableFieldDtos", allRecords);
await GridColumnDataIndexedDb.DeleteByKey("TableFieldDtos", 1);
var remainingRecords = await GridColumnDataIndexedDb.GetAll("TableFieldDtos");
Console.WriteLine($"Remaining records after delete: {remainingRecords.Count}");
await GridColumnDataIndexedDb.DeleteAll("TableFieldDtos");
await GridColumnDataIndexedDb.DeleteIndexedDb();
Console.WriteLine("Database operations completed");
}
}
```
--------------------------------
### Fluent IndexedDb Database Configuration in C#
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Configure an IndexedDb database using a fluent API with extension methods for a more concise syntax. This method achieves the same result as manual configuration but reduces boilerplate code, making database schema setup cleaner and more readable.
```CSharp
using DnetIndexedDb.Fluent;
...
services.AddIndexedDbDatabase(options =>
{
var model = new IndexedDbDatabaseModel()
.WithName("Security")
.WithVersion(1)
.WithModelId(0);
model.AddStore("tableFieldDtos")
.WithAutoIncrementingKey("tableFieldId")
.AddUniqueIndex("tableFieldId")
.AddIndex("attachedProperty")
.AddIndex("fieldVisualName")
.AddIndex("hide")
.AddIndex("isLink")
.AddIndex("memberOf")
.AddIndex("tableName")
.AddIndex("textAlignClass")
.AddIndex("type")
.AddIndex("width");
options.UseDatabase(model);
});
```
--------------------------------
### Add Items to IndexedDB Store (C#)
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Provides examples of adding a list of items to an IndexedDB store. It shows two overloads: one where the object store name is explicitly provided, and another where the store name is inferred from the entity class name. This operation requires the `GridColumnDataIndexedDb` service.
```CSharp
// Manually set DataStore name
var result = await GridColumnDataIndexedDb.AddItems("tableField", items);
// OR
// DataStore name inferred from class
var result = await GridColumnDataIndexedDb.AddItems(items);
```
--------------------------------
### Register IndexedDB Service in Startup (C#)
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Shows how to register a custom IndexedDB service using the `AddIndexedDbDatabase` extension method within the `ConfigureServices` method of `Startup.cs`. The `options` builder is used to configure the database model, including specifying the database name and version.
```CSharp
services.AddIndexedDbDatabase(options =>
{
options.UseDatabase(GetGridColumnDatabaseModel());
});
// Example for multiple databases:
services.AddIndexedDbDatabase(options =>
{
options.UseDatabase(GetSecurityDatabaseModel());
});
```
--------------------------------
### Create IndexedDB Interop Service (C#)
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Demonstrates how to create a custom IndexedDB service by inheriting from the `IndexedDbInterop` base class. This allows for type-safe interactions with a specific IndexedDB database. The constructor requires an `IJSRuntime` and `IndexedDbOptions`.
```CSharp
public class GridColumnDataIndexedDb : IndexedDbInterop
{
public GridColumnDataIndexedDb(IJSRuntime jsRuntime, IndexedDbOptions options)
:base(jsRuntime, options)
{
}
}
```
--------------------------------
### Register IndexedDB Services in Dependency Injection
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Demonstrates how to register IndexedDB databases in the IServiceCollection during startup. It supports manual, attribute-based, and fluent configuration styles.
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddIndexedDbDatabase(options =>
{
options.UseDatabase(GetGridColumnDatabaseModel());
});
services.AddIndexedDbDatabase(options =>
{
var model = new IndexedDbDatabaseModel()
.WithName("TestAttributes")
.WithVersion(1);
model.AddStore();
options.UseDatabase(model);
});
services.AddIndexedDbDatabase(options =>
{
var model = new IndexedDbDatabaseModel()
.WithName("Security")
.WithVersion(1)
.WithModelId(0);
model.AddStore("tableFieldDtos")
.WithAutoIncrementingKey("tableFieldId")
.AddUniqueIndex("tableFieldId")
.AddIndex("tableName");
options.UseDatabase(model);
});
}
```
--------------------------------
### Open IndexedDB Instance (C#)
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Shows the basic C# code to open and potentially upgrade an IndexedDB database instance using the `OpenIndexedDb` method provided by the `IndexedDbInterop` service. This is typically one of the first operations performed when interacting with the database.
```CSharp
var result = await GridColumnDataIndexedDb.OpenIndexedDb();
```
--------------------------------
### Database Configuration - Attribute-Based
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Configuring the database schema by decorating C# entity classes with attributes.
```APIDOC
## Attribute-Based Configuration
### Description
Automatically generates the database schema based on class definitions using attributes.
### Method
N/A (Configuration Pattern)
### Parameters
#### Attributes
- **[IndexDbKey]** - Required - Marks the property as the primary key.
- **[IndexDbIndex]** - Optional - Marks the property to be indexed in the store.
### Request Example
public class TableFieldDto {
[IndexDbKey(AutoIncrement = true)]
public int? TableFieldId { get; set; }
[IndexDbIndex]
public string TableName { get; set; }
}
// Registering
indexedDbDatabaseModel.AddStore();
```
--------------------------------
### Retrieve All Records from IndexedDB
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Demonstrates how to fetch all records from a specified store. Supports both explicit store naming and inferred store names based on the class type.
```csharp
@inject GridColumnDataIndexedDb GridColumnDataIndexedDb
@code {
private List _allRecords = new();
private async Task LoadAllRecords()
{
_allRecords = await GridColumnDataIndexedDb.GetAll("TableFieldDtos");
_allRecords = await GridColumnDataIndexedDb.GetAll();
Console.WriteLine($"Loaded {_allRecords.Count} records");
}
}
```
--------------------------------
### GetAll
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Retrieves all items stored within a specific object store.
```APIDOC
## GET GetAll
### Description
Fetches all records from the defined object store.
### Method
GET
### Parameters
#### Query Parameters
- **objectStoreName** (string) - Optional - The name of the store.
### Response
#### Success Response (200)
- **items** (List) - A list containing all entities in the store.
```
--------------------------------
### Using Open Iconic SVGs
Source: https://github.com/amuste/dnetindexeddb/blob/master/samples/ServerSide/wwwroot/css/open-iconic/README.md
Demonstrates how to use Open Iconic's SVG files directly as images. It requires specifying the path to the SVG file and providing an alt attribute for accessibility.
```html
```
--------------------------------
### Database Configuration - Fluent API
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Configuring the database schema using the fluent API pattern for improved readability and conciseness.
```APIDOC
## Fluent API Configuration
### Description
Defines the database schema using fluent extension methods to configure stores, keys, and indexes.
### Method
N/A (Configuration Pattern)
### Parameters
#### Configuration Methods
- **WithName(string)** - Required - Sets the database name.
- **WithVersion(int)** - Required - Sets the database version.
- **AddStore(string)** - Required - Adds a new object store to the database.
- **WithAutoIncrementingKey(string)** - Required - Configures the primary key path and auto-increment behavior.
- **AddUniqueIndex(string)** - Optional - Adds a unique index to the store.
- **AddIndex(string)** - Optional - Adds a standard index to the store.
### Request Example
var model = new IndexedDbDatabaseModel().WithName("Security").WithVersion(1);
model.AddStore("tableFieldDtos").WithAutoIncrementingKey("tableFieldId").AddUniqueIndex("tableFieldId").AddIndex("tableName");
```
--------------------------------
### Open or Create IndexedDB Database
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Shows how to initialize an IndexedDB connection within a Blazor component. It returns the database model ID or -1 if the operation fails.
```csharp
@inject GridColumnDataIndexedDb GridColumnDataIndexedDb
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var result = await GridColumnDataIndexedDb.OpenIndexedDb();
if (result != -1)
{
Console.WriteLine($"Database opened successfully with ID: {result}");
}
else
{
Console.WriteLine("Failed to open database");
}
}
}
}
```
--------------------------------
### Retrieve Item by Key from IndexedDB Store (C#)
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Demonstrates how to retrieve a single item from an IndexedDB store using its key. Similar to adding items, it offers overloads for explicitly specifying the object store name or inferring it from the entity class. This requires the `GridColumnDataIndexedDb` service.
```CSharp
// Manually set DataStore name
var result = await GridColumnDataIndexedDb.GetByKey("tableField", 11);
// OR
// DataStore name inferred from class
var result = await GridColumnDataIndexedDb.GetByKey(11);
```
--------------------------------
### OpenIndexedDb
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Opens, creates, or upgrades an IndexedDB database instance.
```APIDOC
## OpenIndexedDb
### Description
Opens, creates, or upgrades an IndexedDB database instance. Returns the database model ID on success or -1 on failure.
### Method
ASYNC
### Endpoint
OpenIndexedDb()
### Response
#### Success Response (200)
- **result** (int) - The database model ID.
#### Failure Response
- **result** (int) - Returns -1 on failure.
```
--------------------------------
### Register Derived IndexedDb Class with Dependency Injection in C#
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Shows how to register your custom IndexedDbInterop derived class with the service collection in Startup.cs. This involves using the AddIndexedDbDatabase extension method and configuring it with a database model.
```csharp
services.AddIndexedDbDatabase(options =>
{
options.UseDatabase(GetGridColumnDatabaseModel());
});
```
--------------------------------
### Using Open Iconic Icon Font with Foundation
Source: https://github.com/amuste/dnetindexeddb/blob/master/samples/ServerSide/wwwroot/css/open-iconic/README.md
Demonstrates the integration of Open Iconic's icon font with the Foundation framework. It requires linking the Foundation-specific stylesheet and using span elements with 'fi' and 'fi-icon-name' classes.
```html
```
```html
```
--------------------------------
### Manual IndexedDb Database Configuration in C#
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Manually configure an IndexedDb database model by instantiating classes like IndexedDbDatabaseModel, IndexedDbStore, and IndexedDbIndex. This provides explicit control over database schema definition, including store names, key paths, auto-increment settings, and various index properties.
```CSharp
var indexedDbDatabaseModel = new IndexedDbDatabaseModel
{
Name = "GridColumnData",
Version = 1,
Stores = new List
{
new IndexedDbStore
{
Name = "tableField",
Key = new IndexedDbStoreParameter
{
KeyPath = "tableFieldId",
AutoIncrement = true
},
Indexes = new List
{
new IndexedDbIndex
{
Name = "tableFieldId",
Definition = new IndexedDbIndexParameter
{
Unique = true
}
},
new IndexedDbIndex
{
Name = "attachedProperty",
Definition = new IndexedDbIndexParameter
{
Unique = false
}
},
new IndexedDbIndex
{
Name = "fieldVisualName",
Definition = new IndexedDbIndexParameter
{
Unique = false
}
}, new IndexedDbIndex
{
Name = "hide",
Definition = new IndexedDbIndexParameter
{
Unique = false
}
},
new IndexedDbIndex
{
Name = "isLink",
Definition = new IndexedDbIndexParameter
{
Unique = false
}
},
new IndexedDbIndex
{
Name = "memberOf",
Definition = new IndexedDbIndexParameter
{
Unique = false
}
},
new IndexedDbIndex
{
Name = "tableName",
Definition = new IndexedDbIndexParameter
{
Unique = false
}
},
new IndexedDbIndex
{
Name = "textAlignClass",
Definition = new IndexedDbIndexParameter
{
Unique = false
}
},
new IndexedDbIndex
{
Name = "type",
Definition = new IndexedDbIndexParameter
{
Unique = false
}
},
new IndexedDbIndex
{
Name = "width",
Definition = new IndexedDbIndexParameter
{
Unique = false
}
}
}
}
},
DbModelId = 0
};
```
--------------------------------
### OpenIndexedDb
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Opens and upgrades an instance of the configured IndexedDB database.
```APIDOC
## OpenIndexedDb
### Description
Opens the database connection and performs any necessary version upgrades.
### Method
ValueTask
### Endpoint
OpenIndexedDb()
### Request Example
await GridColumnDataIndexedDb.OpenIndexedDb();
### Response
#### Success Response (200)
- **result** (int) - The version number of the opened database.
```
--------------------------------
### Retrieve Single Record by Primary Key
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Demonstrates fetching a specific record from a store using a primary key. Supports explicit store name or type-inferred store name.
```csharp
@inject GridColumnDataIndexedDb GridColumnDataIndexedDb
@code {
private async Task GetSingleRecord()
{
var record = await GridColumnDataIndexedDb.GetByKey("TableFieldDtos", 11);
var record2 = await GridColumnDataIndexedDb.GetByKey(11);
if (record != null)
{
Console.WriteLine($"Found: {record.FieldVisualName} - {record.TableName}");
}
}
}
```
--------------------------------
### AddItems
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Adds a list of items to a specified object store.
```APIDOC
## AddItems
### Description
Inserts a list of entities into the specified object store. If the store name is omitted, it is inferred from the class name.
### Method
ValueTask
### Parameters
#### Path Parameters
- **objectStoreName** (string) - Optional - The name of the store. If not provided, the class name is used.
#### Request Body
- **items** (List) - Required - The list of objects to add to the store.
### Request Example
await GridColumnDataIndexedDb.AddItems(items);
### Response
#### Success Response (200)
- **result** (TEntity) - The added entity.
```
--------------------------------
### Retrieve Key and Index Boundaries in DNetIndexedDb
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Methods to calculate the minimum and maximum values for primary keys or specific indexed fields. These are useful for range queries and data analysis.
```csharp
@inject GridColumnDataIndexedDb GridColumnDataIndexedDb
@code {
private async Task GetBoundaries()
{
var maxKey = await GridColumnDataIndexedDb.GetMaxKey("TableFieldDtos");
var minKey = await GridColumnDataIndexedDb.GetMinKey();
var maxIndexValue = await GridColumnDataIndexedDb.GetMaxIndex("TableFieldDtos", "attachedProperty");
var minIndexValue = await GridColumnDataIndexedDb.GetMinIndex("attachedProperty");
}
}
```
--------------------------------
### Fluent API Database Schema Configuration in C#
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Configures the IndexedDB schema using a fluent API for a more concise and readable syntax. This method achieves the same results as manual configuration but with cleaner code.
```csharp
using DnetIndexedDb;
using DnetIndexedDb.Fluent;
using DnetIndexedDb.Models;
var model = new IndexedDbDatabaseModel()
.WithName("Security")
.WithVersion(1)
.WithModelId(0);
model.AddStore("tableFieldDtos")
.WithAutoIncrementingKey("tableFieldId")
.AddUniqueIndex("tableFieldId")
.AddIndex("attachedProperty")
.AddIndex("fieldVisualName")
.AddIndex("hide")
.AddIndex("isLink")
.AddIndex("memberOf")
.AddIndex("tableName")
.AddIndex("textAlignClass")
.AddIndex("type")
.AddIndex("width");
```
--------------------------------
### DnetIndexedDb - Core API Methods
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Overview of the core methods provided by the DnetIndexedDb library for managing IndexedDB instances and data.
```APIDOC
## DnetIndexedDb - Core API Methods
### Description
The DnetIndexedDb library exposes the following methods for interacting with IndexedDB databases.
### Methods Overview
* **Instance Management**:
* `OpenAsync(string databaseName)`: Opens or creates an instance of an IndexedDB database.
* `CloseAsync(string databaseName)`: Closes an instance of an IndexedDB database.
* `DeleteAsync(string databaseName)`: Deletes an instance of an IndexedDB database.
* **Data Operations**:
* `AddAsync(string databaseName, string storeName, T item)`: Adds an item to a specified store.
* `UpdateAsync(string databaseName, string storeName, T item)`: Updates an item in a specified store.
* `DeleteByKeyAsync(string databaseName, string storeName, object key)`: Deletes an item from a store by its key.
* `ClearStoreAsync(string databaseName, string storeName)`: Deletes all items from a specified store.
* `GetAllItemsAsync(string databaseName, string storeName)`: Retrieves all items from a specified store.
* `GetItemsByIndexAsync(string databaseName, string storeName, string indexName, object indexValue)`: Retrieves items by an index value.
* `GetItemsByKeyRangeAsync(string databaseName, string storeName, IDBKeyRange range)`: Retrieves a range of items by key.
* `GetItemsByIndexRangeAsync(string databaseName, string storeName, string indexName, IDBKeyRange range)`: Retrieves a range of items by index.
* **Key/Index Retrieval**:
* `GetMaxKeyAsync(string databaseName, string storeName)`: Retrieves the maximum key value from a store.
* `GetMaxIndexValueAsync(string databaseName, string storeName, string indexName)`: Retrieves the maximum value from a specified index.
* `GetMinKeyAsync(string databaseName, string storeName)`: Retrieves the minimum key value from a store.
* `GetMinIndexValueAsync(string databaseName, string storeName, string indexName)`: Retrieves the minimum value from a specified index.
### Compatibility
* Server-side Blazor
* Client-side Blazor
```
--------------------------------
### AddItems
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Adds a list of items to a specified data store.
```APIDOC
## AddItems
### Description
Adds a list of items to a specified data store. Supports both explicit store name and type-inferred store name approaches.
### Method
ASYNC
### Endpoint
AddItems(storeName, items) or AddItems(items)
### Parameters
#### Request Body
- **storeName** (string) - Optional - The name of the store to add items to.
- **items** (List) - Required - The list of items to insert into the store.
### Response
#### Success Response (200)
- **result** (bool) - Returns true if the operation was successful.
```
--------------------------------
### Create Database Service Class in C#
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Defines a C# class that inherits from IndexedDbInterop to serve as the primary interface for database operations in Blazor. This class requires an IJSRuntime instance and IndexedDbOptions.
```csharp
using DnetIndexedDb;
using Microsoft.JSInterop;
public class GridColumnDataIndexedDb : IndexedDbInterop
{
public GridColumnDataIndexedDb(IJSRuntime jsRuntime, IndexedDbOptions options)
: base(jsRuntime, options)
{
}
}
```
--------------------------------
### Manual Database Schema Configuration in C#
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Configures the IndexedDB schema manually by defining models for the database, stores, keys, and indexes. This approach offers granular control over the database structure.
```csharp
using DnetIndexedDb;
using DnetIndexedDb.Models;
var indexedDbDatabaseModel = new IndexedDbDatabaseModel
{
Name = "GridColumnData",
Version = 1,
DbModelId = 0,
UseKeyGenerator = true,
Stores = new List
{
new IndexedDbStore
{
Name = "TableFieldDtos",
Key = new IndexedDbStoreParameter
{
KeyPath = "tableFieldId",
AutoIncrement = true
},
Indexes = new List
{
new IndexedDbIndex
{
Name = "tableFieldId",
Definition = new IndexedDbIndexParameter { Unique = true }
},
new IndexedDbIndex
{
Name = "tableName",
Definition = new IndexedDbIndexParameter { Unique = false }
},
new IndexedDbIndex
{
Name = "fieldVisualName",
Definition = new IndexedDbIndexParameter { Unique = false }
}
}
}
}
};
```
--------------------------------
### Using Open Iconic Icon Font Standalone
Source: https://github.com/amuste/dnetindexeddb/blob/master/samples/ServerSide/wwwroot/css/open-iconic/README.md
Explains how to use Open Iconic's icon font independently without a framework. This involves linking the default stylesheet and using span elements with the 'oi' class and a 'data-glyph' attribute.
```html
```
```html
```
--------------------------------
### Configure IndexedDB Schema from Class Attributes (C#)
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Defines a data transfer object (DTO) with attributes to automatically configure IndexedDB DataStores and indexes. The `[IndexDbKey]` attribute specifies the primary key (with optional auto-increment), and `[IndexDbIndex]` marks properties for indexing. A `IndexedDbDatabaseModel` is then configured with this DTO.
```CSharp
public class TableFieldDto
{
[IndexDbKey(AutoIncrement = true)]
public int? TableFieldId { get; set; }
[IndexDbIndex]
public string TableName { get; set; }
[IndexDbIndex]
public string FieldVisualName { get; set; }
[IndexDbIndex]
public string AttachedProperty { get; set; }
[IndexDbIndex]
public bool IsLink { get; set; }
[IndexDbIndex]
public int MemberOf { get; set; }
[IndexDbIndex]
public int Width { get; set; }
[IndexDbIndex]
public string TextAlignClass { get; set; }
[IndexDbIndex]
public bool Hide { get; set; }
[IndexDbIndex]
public string Type { get; set; }
}
var indexedDbDatabaseModel = new IndexedDbDatabaseModel()
.WithName("TestAttributes")
.WithVersion(1);
indexedDbDatabaseModel.AddStore();
```
--------------------------------
### Add Records to IndexedDB Store
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Provides methods to insert a list of items into a store, supporting both explicit store naming and type-inferred naming.
```csharp
@inject GridColumnDataIndexedDb GridColumnDataIndexedDb
@code {
private async Task AddRecords()
{
var items = new List { /* ... items ... */ };
var result = await GridColumnDataIndexedDb.AddItems("TableFieldDtos", items);
var result2 = await GridColumnDataIndexedDb.AddItems(items);
Console.WriteLine($"Add result: {result}");
}
}
```
--------------------------------
### Create Derived IndexedDbInterop Class in C#
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Demonstrates how to create a derived class from IndexedDbInterop in C#. This custom class will be used to interact with the IndexedDB JavaScript API for a specific database. It requires an IJSRuntime instance and IndexedDbOptions.
```csharp
public class GridColumnDataIndexedDb : IndexedDbInterop
{
public GridColumnDataIndexedDb(IJSRuntime jsRuntime, IndexedDbOptions options)
:base(jsRuntime, options)
{
}
}
```
--------------------------------
### Using Open Iconic Icon Font with Bootstrap
Source: https://github.com/amuste/dnetindexeddb/blob/master/samples/ServerSide/wwwroot/css/open-iconic/README.md
Illustrates how to integrate Open Iconic's icon font with Bootstrap. This involves linking the Bootstrap-specific stylesheet and using span elements with 'oi' and 'oi-icon-name' classes.
```html
```
```html
```
--------------------------------
### GetRange - Retrieve Records by Key Range
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Retrieves records within a specified key range (inclusive bounds). Supports explicit store name or inferred store name.
```APIDOC
## GetRange - Retrieve Records by Key Range
### Description
Retrieves records within a specified key range (inclusive bounds). Supports explicit store name or inferred store name.
### Method
GET (Conceptual - actual implementation is via C# method call)
### Endpoint
N/A (Client-side IndexedDB operation)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```csharp
// Get records with keys between 15 and 20 (inclusive)
// Option 1: Explicit store name
var records = await GridColumnDataIndexedDb.GetRange("TableFieldDtos", 15, 20);
// Option 2: Store name inferred from class
var records2 = await GridColumnDataIndexedDb.GetRange(15, 20);
```
### Response
#### Success Response (200)
- **List** (List of records of type T) - A list of records whose keys fall within the specified range.
#### Response Example
```json
[
{
"TableFieldId": 15,
"FieldVisualName": "Field 15",
"Width": 110
},
{
"TableFieldId": 16,
"FieldVisualName": "Field 16",
"Width": 110
}
]
```
```
--------------------------------
### Inject and Use IndexedDB Service in Blazor Component (C#)
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Illustrates how to inject an IndexedDB service instance into a Blazor component using the `@inject` directive. This makes the service's methods available for interacting with the IndexedDB database within the component.
```CSharp
@inject GridColumnDataIndexedDb GridColumnDataIndexedDb
```
--------------------------------
### Attribute-Based Database Schema Configuration in C#
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Configures the IndexedDB schema by decorating entity classes with attributes like IndexDbKey and IndexDbIndex. This allows the library to automatically infer the database structure from the class definition.
```csharp
using DnetIndexedDb;
public class TableFieldDto
{
[IndexDbKey(AutoIncrement = true)]
public int? TableFieldId { get; set; }
[IndexDbIndex]
public string TableName { get; set; }
[IndexDbIndex]
public string FieldVisualName { get; set; }
[IndexDbIndex]
public string AttachedProperty { get; set; }
[IndexDbIndex]
public bool IsLink { get; set; }
[IndexDbIndex]
public int MemberOf { get; set; }
[IndexDbIndex]
public int Width { get; set; }
[IndexDbIndex]
public string TextAlignClass { get; set; }
[IndexDbIndex]
public bool Hide { get; set; }
[IndexDbIndex]
public string Type { get; set; }
}
// Register with attribute-based configuration
var indexedDbDatabaseModel = new IndexedDbDatabaseModel()
.WithName("TestAttributes")
.WithVersion(1);
indexedDbDatabaseModel.AddStore();
```
--------------------------------
### GetAll - Retrieve All Records
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Retrieves all records from a specified data store. This method can infer the store name from the class type or accept an explicit store name.
```APIDOC
## GetAll - Retrieve All Records
### Description
Retrieves all records from a specified data store. This method can infer the store name from the class type or accept an explicit store name.
### Method
GET (Conceptual - actual implementation is via C# method call)
### Endpoint
N/A (Client-side IndexedDB operation)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```csharp
// Option 1: Explicit store name
var allRecords = await GridColumnDataIndexedDb.GetAll("TableFieldDtos");
// Option 2: Store name inferred from class
var allRecordsInferred = await GridColumnDataIndexedDb.GetAll();
```
### Response
#### Success Response (200)
- **List** (List of records of type T) - A list containing all records from the data store.
#### Response Example
```json
[
{
"TableFieldId": 1,
"FieldVisualName": "Example Field",
"Width": 100
}
]
```
```
--------------------------------
### GetByKey
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Retrieves a single item from an object store by its primary key.
```APIDOC
## GetByKey
### Description
Retrieves an entity from the store matching the provided key.
### Method
ValueTask
### Parameters
#### Path Parameters
- **objectStoreName** (string) - Optional - The name of the store.
- **key** (TKey) - Required - The primary key value to search for.
### Request Example
await GridColumnDataIndexedDb.GetByKey(11);
### Response
#### Success Response (200)
- **result** (TEntity) - The retrieved entity or null if not found.
```
--------------------------------
### Define IndexedDbDatabaseModel Structure in C#
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Illustrates the structure of the IndexedDbDatabaseModel class used for configuring IndexedDB databases. This class defines the database name, version, and a list of stores it contains. It's a core component for setting up your IndexedDB.
```csharp
public class IndexedDbDatabaseModel
{
public string Name { get; set; }
public int Version { get; set; }
public List Stores { get; set; } = new List();
public int DbModelId { get; set; }
}
```
--------------------------------
### Retrieve Records by Key Range
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Retrieves a subset of records within defined inclusive key bounds. This method is useful for pagination or filtering by ID ranges.
```csharp
@inject GridColumnDataIndexedDb GridColumnDataIndexedDb
@code {
private async Task GetRecordsInRange()
{
var records = await GridColumnDataIndexedDb.GetRange("TableFieldDtos", 15, 20);
var records2 = await GridColumnDataIndexedDb.GetRange(15, 20);
Console.WriteLine($"Found {records.Count} records in range 15-20");
}
}
```
--------------------------------
### Perform Simultaneous Operations on Multiple IndexedDB Databases
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
This snippet illustrates how to inject multiple database service classes and execute CRUD operations on each independently. It highlights the requirement to manage database connections separately to ensure data integrity across distinct storage contexts.
```csharp
@inject GridColumnDataIndexedDb GridColumnDataIndexedDb
@inject SecuritySuiteDataIndexedDb SecuritySuiteDataIndexedDb
@code {
private async Task MultipleDatabaseOperations()
{
var tableFieldService = new TableFieldService();
var items = tableFieldService.GetTableFields();
var db1Result = await GridColumnDataIndexedDb.OpenIndexedDb();
var db2Result = await SecuritySuiteDataIndexedDb.OpenIndexedDb();
if (db1Result != -1) {
await GridColumnDataIndexedDb.DeleteAll("TableFieldDtos");
}
if (db2Result != -1) {
await SecuritySuiteDataIndexedDb.DeleteAll("TableFieldDtos");
}
await GridColumnDataIndexedDb.AddItems("TableFieldDtos", items);
await SecuritySuiteDataIndexedDb.AddItems("TableFieldDtos", items);
var db1Records = await GridColumnDataIndexedDb.GetAll("TableFieldDtos");
var db2Records = await SecuritySuiteDataIndexedDb.GetAll("TableFieldDtos");
Console.WriteLine($"Database 1 records: {db1Records.Count}");
Console.WriteLine($"Database 2 records: {db2Records.Count}");
foreach (var record in db1Records) {
record.FieldVisualName += " (DB1)";
}
foreach (var record in db2Records) {
record.FieldVisualName += " (DB2)";
}
await GridColumnDataIndexedDb.UpdateItems("TableFieldDtos", db1Records);
await SecuritySuiteDataIndexedDb.UpdateItems("TableFieldDtos", db2Records);
await GridColumnDataIndexedDb.DeleteIndexedDb();
await SecuritySuiteDataIndexedDb.DeleteIndexedDb();
}
}
```
--------------------------------
### Retrieve All Items from IndexedDB Store
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Retrieves all items from a specified IndexedDB object store. The object store name can be provided explicitly or inferred from the entity type.
```CSharp
var result = await GridColumnDataIndexedDb.GetAll("tableField");
OR
var result = await GridColumnDataIndexedDb.GetAll();
```
--------------------------------
### Retrieve Range of Items by Key in IndexedDB
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Retrieves a range of items from an IndexedDB object store based on a key range. The object store name can be specified explicitly or inferred.
```CSharp
var result = await GridColumnDataIndexedDb.GetRange("tableField", 15, 20);
OR
var result = await GridColumnDataIndexedDb.GetRange(15, 20);
```
--------------------------------
### Retrieve Minimum Key from IndexedDB
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Retrieves the minimum key from an IndexedDB object store. The object store name can be explicitly provided or inferred from the entity type.
```CSharp
var result = await GridColumnDataIndexedDb.GetMinKey("tableField");
OR
var result = await GridColumnDataIndexedDb.GetMinKey();
```
--------------------------------
### Retrieve Minimum Value by Index in IndexedDB
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Retrieves the minimum value associated with a specific index in an IndexedDB object store. Supports explicit object store naming or inference.
```CSharp
var result = await GridColumnDataIndexedDb.GetMinIndex("tableField", "fieldVisualName");
OR
var result = await GridColumnDataIndexedDb.GetMinIndex("fieldVisualName");
```
--------------------------------
### Retrieve Range of Items by Index in IndexedDB
Source: https://github.com/amuste/dnetindexeddb/blob/master/README.md
Retrieves a range of items from an IndexedDB object store using a specific index and key range. Supports explicit object store naming or inference.
```CSharp
var result = await GridColumnDataIndexedDb.GetByIndex("tableField", "Name", null, "fieldVisualName", false);
OR
var result = await GridColumnDataIndexedDb.GetByIndex("Name", null, "fieldVisualName", false);
```
--------------------------------
### Update Records in IndexedDB
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Updates existing records in the data store by matching their primary key values. Requires fetching the records first, modifying them, and then passing them back to the update method.
```csharp
@inject GridColumnDataIndexedDb GridColumnDataIndexedDb
@code {
private async Task UpdateRecords()
{
var records = await GridColumnDataIndexedDb.GetAll("TableFieldDtos");
foreach (var record in records)
{
record.FieldVisualName = record.FieldVisualName + " (Updated)";
}
var result = await GridColumnDataIndexedDb.UpdateItems("TableFieldDtos", records);
var result2 = await GridColumnDataIndexedDb.UpdateItems(records);
}
}
```
--------------------------------
### Using Open Iconic SVG Sprite
Source: https://github.com/amuste/dnetindexeddb/blob/master/samples/ServerSide/wwwroot/css/open-iconic/README.md
Shows how to use Open Iconic's SVG sprite for efficient icon display. This method involves referencing an icon within the sprite using the xlink:href attribute and applying CSS for sizing and coloring.
```html
```
```css
.icon {
width: 16px;
height: 16px;
}
```
```css
.icon-account-login {
fill: #f00;
}
```
--------------------------------
### Query Records by Index
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Performs lookups using specific index fields. It supports both exact matches and range-based queries by toggling the isRange parameter.
```csharp
@inject GridColumnDataIndexedDb GridColumnDataIndexedDb
@code {
private async Task QueryByIndex()
{
var exactMatch = await GridColumnDataIndexedDb.GetByIndex("TableFieldDtos", "Username", null, "fieldVisualName", false);
var rangeResults = await GridColumnDataIndexedDb.GetByIndex("TableFieldDtos", 11, 18, "tableFieldId", true);
var exactMatch2 = await GridColumnDataIndexedDb.GetByIndex("Username", null, "fieldVisualName", false);
}
}
```
--------------------------------
### Delete Records and Clear Stores in DNetIndexedDb
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Provides methods to delete a single record by primary key or clear an entire object store. These operations support both explicit store names and class-inferred store names.
```csharp
@inject GridColumnDataIndexedDb GridColumnDataIndexedDb
@code {
private async Task DeleteRecord(int keyToDelete)
{
var result = await GridColumnDataIndexedDb.DeleteByKey("TableFieldDtos", keyToDelete);
var result2 = await GridColumnDataIndexedDb.DeleteByKey(keyToDelete);
}
private async Task ClearStore()
{
var result = await GridColumnDataIndexedDb.DeleteAll("TableFieldDtos");
var result2 = await GridColumnDataIndexedDb.DeleteAll();
}
}
```
--------------------------------
### GetByIndex - Query Records by Index
Source: https://context7.com/amuste/dnetindexeddb/llms.txt
Retrieves records using an index field. Supports both exact match and range queries.
```APIDOC
## GetByIndex - Query Records by Index
### Description
Retrieves records using an index field. Supports both exact match and range queries based on the `isRange` parameter. Can infer store name or accept explicit name.
### Method
GET (Conceptual - actual implementation is via C# method call)
### Endpoint
N/A (Client-side IndexedDB operation)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```csharp
// Exact match query (isRange = false)
// Option 1: Explicit store name
var exactMatch = await GridColumnDataIndexedDb.GetByIndex(
"TableFieldDtos",
"Username", // lowerBound (exact value to match)
null, // upperBound (null for exact match)
"fieldVisualName", // index name
false // isRange = false for exact match
);
// Range query (isRange = true)
var rangeResults = await GridColumnDataIndexedDb.GetByIndex(
"TableFieldDtos",
11, // lowerBound
18, // upperBound
"tableFieldId", // index name
true // isRange = true for range query
);
// Option 2: Store name inferred from class
var exactMatch2 = await GridColumnDataIndexedDb.GetByIndex(
"Username", null, "fieldVisualName", false);
```
### Response
#### Success Response (200)
- **List** (List of records of type T) - A list of records matching the index query criteria.
#### Response Example
```json
[
{
"TableFieldId": 11,
"FieldVisualName": "Field 11",
"Width": 110
}
]
```
```