Cirreum.Persistence.SQLite
1.0.3
See the version list below for details.
dotnet add package Cirreum.Persistence.SQLite --version 1.0.3
NuGet\Install-Package Cirreum.Persistence.SQLite -Version 1.0.3
<PackageReference Include="Cirreum.Persistence.SQLite" Version="1.0.3" />
<PackageVersion Include="Cirreum.Persistence.SQLite" Version="1.0.3" />
<PackageReference Include="Cirreum.Persistence.SQLite" />
paket add Cirreum.Persistence.SQLite --version 1.0.3
#r "nuget: Cirreum.Persistence.SQLite, 1.0.3"
#:package Cirreum.Persistence.SQLite@1.0.3
#addin nuget:?package=Cirreum.Persistence.SQLite&version=1.0.3
#tool nuget:?package=Cirreum.Persistence.SQLite&version=1.0.3
Cirreum.Persistence.SQLite
SQLite provider for Cirreum.Persistence.Sql
Overview
Cirreum.Persistence.SQLite is a SQLite-specific implementation of the ISqlConnectionFactory interface from the Cirreum.Persistence.Sql abstraction layer. It provides:
- SQLite connection factory with Dapper integration
- Health check support for service monitoring
- Integration with the Cirreum Service Provider framework
For query extensions, pagination, transaction chaining, and constraint handling, see the Cirreum.Persistence.Sql documentation.
Installation
dotnet add package Cirreum.Persistence.SQLite
Quick Start
Basic Registration
builder.AddSqlite("default", "Data Source=mydb.sqlite");
With In-Memory Database
builder.AddSqlite("default", "Data Source=:memory:");
With Full Configuration
builder.AddSqlite("default", settings =>
{
settings.ConnectionString = "Data Source=mydb.sqlite;Cache=Shared";
settings.CommandTimeoutSeconds = 60;
}, healthOptions =>
{
healthOptions.Query = "SELECT 1";
healthOptions.Timeout = TimeSpan.FromSeconds(5);
});
Configuration Options
SqliteInstanceSettings
| Property | Type | Default | Description |
|---|---|---|---|
ConnectionString |
string |
- | SQLite connection string |
CommandTimeoutSeconds |
int |
30 |
Default command timeout in seconds |
SqliteHealthCheckOptions
| Property | Type | Default | Description |
|---|---|---|---|
Query |
string |
"SELECT 1" |
SQL query to execute for health checks |
Timeout |
TimeSpan |
5s |
Health check timeout |
Usage
Inject ISqlConnectionFactory and use the query/command extensions from Cirreum.Persistence.Sql:
public class OrderRepository(ISqlConnectionFactory db)
{
public async Task<Result<OrderDto>> GetOrderAsync(Guid orderId, CancellationToken ct)
{
await using var conn = await db.CreateConnectionAsync(ct);
return await conn.GetAsync<OrderDto>(
"SELECT * FROM Orders WHERE OrderId = @Id",
new { Id = orderId },
key: orderId,
ct);
}
public async Task<Result<Guid>> CreateOrderAsync(CreateOrder cmd, CancellationToken ct)
{
await using var conn = await db.CreateConnectionAsync(ct);
var orderId = Guid.CreateVersion7();
return await conn.InsertAndReturnAsync(
"""
INSERT INTO Orders (OrderId, CustomerId, Amount, CreatedAt)
VALUES (@OrderId, @CustomerId, @Amount, @CreatedAt)
""",
new { OrderId = orderId, cmd.CustomerId, cmd.Amount, CreatedAt = DateTime.UtcNow },
() => orderId,
uniqueConstraintMessage: "Order already exists",
ct: ct);
}
}
Multiple Instances
Register multiple SQLite instances with different keys:
builder.AddSqlite("primary", "Data Source=primary.sqlite");
builder.AddSqlite("cache", "Data Source=cache.sqlite");
// Inject with [FromKeyedServices]
public class CacheService([FromKeyedServices("cache")] ISqlConnectionFactory db)
{
// ...
}
DateOnly and TimeOnly Support
This package includes built-in Dapper type handlers for DateOnly and TimeOnly, allowing you to use these types directly in your models and queries:
public record Appointment(int Id, DateOnly Date, TimeOnly StartTime, TimeOnly EndTime);
// Query with DateOnly/TimeOnly parameters
var appointments = await conn.QueryAsync<Appointment>(
"SELECT * FROM Appointments WHERE Date = @Date AND StartTime > @MinTime",
new { Date = new DateOnly(2026, 1, 15), MinTime = new TimeOnly(9, 0) });
// Insert with DateOnly/TimeOnly values
await conn.ExecuteAsync(
"INSERT INTO Appointments (Date, StartTime, EndTime) VALUES (@Date, @StartTime, @EndTime)",
new { Date = DateOnly.FromDateTime(DateTime.Today), StartTime = new TimeOnly(9, 30), EndTime = new TimeOnly(10, 0) });
The type handlers are registered automatically when the package is loaded.
SQLite Connection Strings
Common SQLite connection string patterns:
| Pattern | Description |
|---|---|
Data Source=mydb.sqlite |
File-based database |
Data Source=:memory: |
In-memory database (single connection) |
Data Source=mydb.sqlite;Cache=Shared |
Shared cache mode |
Data Source=mydb.sqlite;Mode=ReadOnly |
Read-only mode |
Data Source=mydb.sqlite;Password=secret |
Encrypted database |
Related Packages
| Package | Description |
|---|---|
| Cirreum.Persistence.Sql | Database-agnostic SQL abstraction layer |
| Cirreum.Persistence.SqlServer | SQL Server provider |
| Cirreum.Persistence.MySql | MySQL provider (coming soon) |
| Cirreum.Persistence.PostgreSql | PostgreSQL provider (coming soon) |
License
This project is licensed under the MIT License - see the LICENSE file for details.
Cirreum Foundation Framework Layered simplicity for modern .NET
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Cirreum.Core (>= 1.0.38)
- Cirreum.Persistence.Sql (>= 1.0.6)
- Cirreum.ServiceProvider (>= 1.0.7)
- Dapper (>= 2.1.66)
- Microsoft.Data.Sqlite (>= 10.0.2)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Cirreum.Persistence.SQLite:
| Package | Downloads |
|---|---|
|
Cirreum.Runtime.Persistence
The Runtime Persistence service configuration. |
|
|
Cirreum.Runtime.Persistence.SQLite
The Runtime Persistence service configuration for SQLite. |
GitHub repositories
This package is not used by any popular GitHub repositories.