DataMagic.LiteDatabase
9.0.0
dotnet add package DataMagic.LiteDatabase --version 9.0.0
NuGet\Install-Package DataMagic.LiteDatabase -Version 9.0.0
<PackageReference Include="DataMagic.LiteDatabase" Version="9.0.0" />
<PackageVersion Include="DataMagic.LiteDatabase" Version="9.0.0" />
<PackageReference Include="DataMagic.LiteDatabase" />
paket add DataMagic.LiteDatabase --version 9.0.0
#r "nuget: DataMagic.LiteDatabase, 9.0.0"
#:package DataMagic.LiteDatabase@9.0.0
#addin nuget:?package=DataMagic.LiteDatabase&version=9.0.0
#tool nuget:?package=DataMagic.LiteDatabase&version=9.0.0
DataMagic.LiteDatabase
I. Overview
DataMagic.LiteDatabase is an extension package of the DataMagic ecosystem that provides common functions and utilities for LiteDB database queries. This library simplifies working with LiteDB by offering extension methods for filtering, searching, and pagination operations on ILiteQueryable<T>, making it easier to build robust and maintainable data access layers.
The package integrates with the DataMagic.Abstractions library to provide a type-safe, fluent API for LiteDB operations including numeric filtering, date and date-time comparisons, result pagination, and applying partial updates to entities.
II. Functions
Extensions
DateFilterExtensions
Extension methods for filtering LiteDB queries based on date values.
Methods:
WithDateSearch<T, TValueType>(ILiteQueryable<T>, Expression<Func<T, TValueType>>, DateFilter)- Applies date filtering to an
ILiteQueryablecollection - Supports comparison operators: SmallerThan, SmallerThanEqualTo, GreaterThanEqualTo, GreaterThan, Equal
- Returns: Filtered
ILiteQueryable<T> - Usage: Filter entities by date fields with specific comparison operators
- Applies date filtering to an
WithDateRangeSearch<T, TValueType>(ILiteQueryable<T>, Expression<Func<T, TValueType>>, DateRangeFilter)- Applies date range filtering (From/To) to an
ILiteQueryablecollection - Combines multiple date filters for range queries
- Returns: Filtered
ILiteQueryable<T> - Usage: Filter entities within a specific date range
- Applies date range filtering (From/To) to an
DateTimeFilterExtensions
Extension methods for filtering LiteDB queries based on date-time values.
Methods:
WithDateTimeSearch<T, TValueType>(ILiteQueryable<T>, Expression<Func<T, TValueType>>, DateTimeFilter)- Applies date-time filtering to an
ILiteQueryablecollection - Supports comparison operators: SmallerThan, SmallerThanEqualTo, GreaterThanEqualTo, GreaterThan, Equal
- Returns: Filtered
ILiteQueryable<T> - Usage: Filter entities by date-time fields with specific comparison operators
- Applies date-time filtering to an
WithDateTimeRangeSearch<T, TValueType>(ILiteQueryable<T>, Expression<Func<T, TValueType>>, DateTimeRangeFilter)- Applies date-time range filtering (From/To) to an
ILiteQueryablecollection - Combines multiple date-time filters for range queries
- Returns: Filtered
ILiteQueryable<T> - Usage: Filter entities within a specific date-time range
- Applies date-time range filtering (From/To) to an
NumericSearchExtensions
Extension methods for filtering LiteDB queries based on numeric values.
Methods:
WithNumericSearch<T, TValueType>(ILiteQueryable<T>, Expression<Func<T, TValueType>>, NumericFilter<TValueType>)- Applies numeric filtering to an
ILiteQueryablecollection - Supports comparison operators: Equal, SmallerThan, SmallerThanEqualTo, GreaterThanEqualTo, GreaterThan
- Validates numeric types at runtime
- Returns: Filtered
ILiteQueryable<T> - Usage: Filter entities by numeric fields with specific comparison operators
- Applies numeric filtering to an
WithNumericRangeSearch<T, TValueType>(ILiteQueryable<T>, Expression<Func<T, TValueType>>, NumericRangeFilter<TValueType, TValueType>)- Applies numeric range filtering (From/To) to an
ILiteQueryablecollection - Combines multiple numeric filters for range queries
- Returns: Filtered
ILiteQueryable<T> - Usage: Filter entities within a specific numeric range
- Applies numeric range filtering (From/To) to an
SearchResultExtensions
Extension methods for paginating and converting LiteDB queries to search results.
Methods:
ToSearchResultAsync<T>(ILiteQueryable<T>, IPager, CancellationToken)- Converts an
ILiteQueryableto a paginatedISearchResult<T> - Handles total record counting and pagination using LiteDB
Offset/Limit - Returns all items when no pager is supplied
- Returns:
Task<ISearchResult<T>> - Usage: Paginate LiteDB queries
- Converts an
Models
EntityUpdateBuilder<T>
A builder class that collects field updates in a fluent manner and applies them to an entity instance. Since LiteDB updates whole documents, the builder sets the modified properties on the entity, which can then be saved with ILiteCollection<T>.Update.
Methods:
Update<TField>(Expression<Func<T, TField>>, IUpdatableProperty<TField>)- Adds an update operation using a lambda expression
- Only updates if the property has been modified
- Returns:
EntityUpdateBuilder<T>(for method chaining) - Usage: Build update operations with strongly-typed property selectors
Build(T)- Applies all collected updates to the given entity
- Does nothing if no updates were added
- Usage: Set the modified values on an entity before saving it
CountUpdatedFields()- Returns the number of fields that will be updated
- Returns:
int - Usage: Validate or log the number of fields being updated
III. Requirements
Dependencies
The DataMagic.LiteDatabase package requires the following dependencies:
DataMagic.Abstractions (Version 1.2.0)
- Provides core abstractions, interfaces, and models
- Includes filter models, operators, and pagination interfaces
LiteDB (Version 5.0.21)
- Embedded NoSQL document database for .NET
- Provides
LiteDatabase,ILiteCollection<T>andILiteQueryable<T>
Target Framework
- .NET 9.0 (
net9.0)
Installation
To install the package, add it to your project using:
dotnet add package DataMagic.LiteDatabase
Or add the following to your .csproj file:
<PackageReference Include="DataMagic.LiteDatabase" Version="9.0.0" />
Usage Examples
Numeric Filtering
using var database = new LiteDatabase("data.db");
var users = database.GetCollection<User>("users");
var numericFilter = new NumericFilter<int>(18, NumericComparisonOperators.GreaterThanEqualTo);
var query = users.Query()
.WithNumericSearch(x => x.Age, numericFilter);
Date-Time Range Filtering
var dateRangeFilter = new DateTimeRangeFilter
{
From = new DateTimeFilter(DateTime.Now.AddDays(-30), DateTimeComparisonOperators.GreaterThanEqualTo),
To = new DateTimeFilter(DateTime.Now, DateTimeComparisonOperators.SmallerThanEqualTo)
};
var query = users.Query()
.WithDateTimeRangeSearch(x => x.CreatedTime, dateRangeFilter);
Pagination
var pager = new DefaultPager(1, 20);
var result = await users.Query()
.OrderBy(x => x.Name)
.ToSearchResultAsync(pager);
// result.Items contains the paginated items
// result.TotalRecords contains the total count
Update Builder
var user = users.FindById(id);
var updateBuilder = new EntityUpdateBuilder<User>();
updateBuilder
.Update(x => x.Name, updatableNameProperty)
.Update(x => x.Email, updatableEmailProperty);
if (updateBuilder.CountUpdatedFields() > 0)
{
updateBuilder.Build(user);
users.Update(user);
}
License
Please refer to the repository license file for licensing information.
Contributing
Contributions are welcome! Please ensure all code follows the existing patterns and includes appropriate documentation.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net9.0
- DataMagic.Abstractions (>= 1.2.0)
- LiteDB (>= 5.0.21)
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 |
|---|---|---|
| 9.0.0 | 97 | 11/2/2026 |