CodeLogic.SQLite
4.6.72
dotnet add package CodeLogic.SQLite --version 4.6.72
NuGet\Install-Package CodeLogic.SQLite -Version 4.6.72
<PackageReference Include="CodeLogic.SQLite" Version="4.6.72" />
<PackageVersion Include="CodeLogic.SQLite" Version="4.6.72" />
<PackageReference Include="CodeLogic.SQLite" />
paket add CodeLogic.SQLite --version 4.6.72
#r "nuget: CodeLogic.SQLite, 4.6.72"
#:package CodeLogic.SQLite@4.6.72
#addin nuget:?package=CodeLogic.SQLite&version=4.6.72
#tool nuget:?package=CodeLogic.SQLite&version=4.6.72
CodeLogic.SQLite
An embedded SQLite data-access layer for CodeLogic 4 — connection pooling, WAL, attribute-driven table sync, a repository, and a fluent LINQ-shaped query builder.
Map a plain class with attributes and the library keeps the live table in shape, then read and write through a Repository<T> or a fluent QueryBuilder<T>. It builds on Microsoft.Data.Sqlite, pools connections per database, and enables Write-Ahead Logging by default. Every fallible operation returns a Result / Result<T> — no exceptions for the expected failure paths.
Install
dotnet add package CodeLogic.SQLite
Quick start
using CL.SQLite;
await Libraries.LoadAsync<SQLiteLibrary>(); // register before ConfigureAsync()
await CodeLogic.ConfigureAsync();
await CodeLogic.StartAsync();
var db = Libraries.Get<SQLiteLibrary>();
// 1. Reconcile the table from the entity (CREATE / ALTER to match the class)
await db.TableSync.SyncTableAsync<NoteRecord>();
// 2. CRUD via the repository — every call returns a Result
var repo = db.GetRepository<NoteRecord>();
var insert = await repo.InsertAsync(new NoteRecord { Title = "Hello", Body = "World" });
if (insert.IsSuccess)
Console.WriteLine($"new rowid = {insert.Value}");
// 3. Fluent queries via the query builder
var notes = await db.GetQueryBuilder<NoteRecord>()
.Where(n => n.Title.Contains("Hello"))
.OrderByDescending(n => n.CreatedUtc)
.Take(20)
.ToListAsync();
if (notes.IsSuccess)
foreach (var note in notes.Value!)
Console.WriteLine(note.Title);
The entity is plain C# annotated with [SQLiteTable] / [SQLiteColumn]:
using CL.SQLite.Models;
[SQLiteTable("notes")]
public sealed class NoteRecord
{
[SQLiteColumn(IsPrimaryKey = true, IsAutoIncrement = true)]
public long Id { get; set; }
[SQLiteColumn(ColumnName = "title", IsNotNull = true, IsIndexed = true)]
public string Title { get; set; } = "";
[SQLiteColumn(ColumnName = "body")]
public string Body { get; set; } = "";
[SQLiteColumn(ColumnName = "created_utc")]
public DateTime CreatedUtc { get; set; } = DateTime.UtcNow;
}
Only properties marked with [SQLiteColumn] are mapped. The connection id defaults to "Default" on every entry point, so GetRepository<NoteRecord>() equals GetRepository<NoteRecord>("Default").
Features
- Named connection pools — a map of databases keyed by connection id, each with its own per-database pool (default
MaxPoolSize10) and a 5-minute idle timeout. - WAL by default —
journal_mode=WALis set on every connection for better read/write concurrency. - Repository CRUD — insert / upsert / update / delete, by-id and composite-key lookups, paging, LINQ
Find, count, and raw SQL — all returningResult. - Fluent query builder —
Where/OrderBy/ThenBy/Select/GroupBy, aggregates, paging, and bulk predicate update / delete translated to SQL. - Attribute-driven schema sync —
TableSynccreates tables, adds missing columns, and builds indexes to match the entity class; batch-sync by type set or namespace. - Migration ledger —
MigrationTrackerrecords and inspects applied migration ids in a JSON history file. - Type conversion —
bool,DateTime,DateTimeOffset,Guid, andenumare converted automatically on read and write.
Configuration
Auto-generated on first run as config.sqlite.json (section sqlite). The config is a Databases map — each key is a connection id you pass to the entry points; Default is created automatically.
{
"databases": {
"Default": {
"enabled": true,
"databasePath": "database.db",
"connectionTimeoutSeconds": 30,
"commandTimeoutSeconds": 120,
"skipTableSync": false,
"cacheMode": "Default",
"useWAL": true,
"enableForeignKeys": true,
"maxPoolSize": 10,
"slowQueryThresholdMs": 500
}
}
}
| Setting | Default | Description |
|---|---|---|
enabled |
true |
Disable a database without removing it. |
databasePath |
database.db |
Absolute, or relative to the library data directory. |
connectionTimeoutSeconds |
30 |
Connection open timeout. |
commandTimeoutSeconds |
120 |
Per-command timeout. |
skipTableSync |
false |
Turn off automatic schema sync for this database. |
cacheMode |
Default |
Default / Private / Shared. |
useWAL |
true |
Write-Ahead Logging — better concurrency, recommended. |
enableForeignKeys |
true |
Enforce foreign-key constraints. |
maxPoolSize |
10 |
Maximum pooled connections per database. |
slowQueryThresholdMs |
500 |
Slow-query warning threshold. |
A database with enabled: false is skipped at startup; if no database is enabled the library initializes disabled and the health check reports healthy-but-disabled.
Documentation
Full guide: CL.SQLite documentation
Requirements
- CodeLogic 4 · .NET 10
- Microsoft.Data.Sqlite 9.x
License
MIT — see LICENSE.
| 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
- CodeLogic (>= 4.0.0 && < 5.0.0)
- Microsoft.Data.Sqlite (>= 9.0.17)
- SQLitePCLRaw.bundle_e_sqlite3 (>= 3.0.3)
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 |
|---|---|---|
| 4.6.72 | 47 | 6/20/2026 |
| 4.6.69-preview | 37 | 6/20/2026 |
| 4.5.2 | 108 | 5/24/2026 |
| 4.5.2-preview.68 | 62 | 6/20/2026 |
| 4.5.1 | 106 | 5/24/2026 |
| 4.5.1-preview.56 | 61 | 5/24/2026 |
| 4.4.2-preview.53 | 58 | 5/24/2026 |
| 4.4.1 | 104 | 5/24/2026 |
| 4.0.5 | 101 | 5/15/2026 |
| 4.0.4 | 112 | 5/9/2026 |
| 4.0.3 | 103 | 5/9/2026 |
| 4.0.1 | 114 | 4/19/2026 |
| 3.3.1 | 113 | 4/18/2026 |
| 3.3.0 | 103 | 4/18/2026 |
| 3.2.11 | 105 | 4/18/2026 |
| 3.2.10 | 105 | 4/18/2026 |
| 3.2.9 | 108 | 4/18/2026 |
| 3.2.8 | 106 | 4/18/2026 |
| 3.2.7 | 102 | 4/18/2026 |
| 3.2.6 | 109 | 4/18/2026 |
# CL.SQLite — Changelog
All notable changes to **CodeLogic.SQLite** are documented here. Versions follow
[Semantic Versioning](https://semver.org/).
## 2026-06-20
### Fixed
- Query-builder parameter re-keying could corrupt SQL when a predicate emitted
11+ parameters (`@p1` substring-collided with `@p10`/`@p11`); parameters are
now renamed longest-name-first.
- WHERE-clause column names are now quoted, so entity properties mapped to SQL
reserved words (e.g. `Order`, `Group`, `Index`) generate valid SQL.
- The connection pool now caps the number of concurrently live connections at
`MaxPoolSize` (previously only the *returned* count was capped, allowing
unbounded open connections under load).
- `GetPagedAsync` / `ToPagedListAsync` now validate that `page` and `pageSize`
are >= 1 instead of generating a negative `OFFSET`.
### Documentation
- Full README and multi-page docs rewrite to house style. The README is now a
concise NuGet/GitHub-friendly page (badges, tagline, install, quick start,
features, configuration table + JSON, docs link, requirements, license). The
docs site moves from a single `sqlite.md` page to a two-page set under
`docs/libs/sqlite/`: an **Overview** (connection pool + WAL, entity attributes,
schema sync, repository CRUD incl. composite keys, configuration, migration
ledger, health check, events) and a **Query Builder** deep-dive (`Where`,
ordering with `ThenBy`, projections, `GroupBy` aggregates, paging, terminals,
bulk update/delete, raw SQL). Examples now use the library's actual `Result`
surface (`.IsSuccess` / `.Value`). Navigation and the docs landing card were
updated to point at the new pages. No API changes — documentation only.
## [4.5.2] — 2026-06-20
### Documentation
- Corrected the README to match the shipping API: the query builder is obtained
via `GetQueryBuilder<T>()` (there is no `sqlite.Query<T>()`), all data
operations return `Result` / `Result<T>`, and entities require
`[SQLiteTable]` / `[SQLiteColumn]` annotations. The previous Quick Start no
longer compiled.
- Documented the configuration as the real `databases` map (per-named-database
`databasePath`, `useWAL`, `cacheMode`, `maxPoolSize`, `slowQueryThresholdMs`,
timeouts, `skipTableSync`, `enableForeignKeys`), replacing the inaccurate
`connections` array with `journalMode`/`poolSize`.
- Documented previously undocumented user-facing surface that already shipped:
the full query builder (`Select`, `GroupBy`, `Sum`/`Max`/`Min`, predicate
`DeleteAsync`/`UpdateAsync`, `ToPagedListAsync`), repository `UpsertAsync`,
composite-key (`GetByKeysAsync`/`DeleteByKeysAsync`), `GetPagedAsync`, raw SQL
(`RawQueryAsync`/`RawExecuteAsync`), attribute-driven schema sync
(`SyncTableAsync`/`SyncTablesAsync`/`SyncNamespaceAsync` with
`[SQLiteIndex]`/`[SQLiteForeignKey]`), and the `MigrationTracker`. No code
changes — documentation only.
## [4.5.0] — 2026-05-24
### Changed
- **Unified versioning.** All CodeLogic.Libs now share a single version line
controlled by `version.txt` in the repo root. This is a version alignment
release — no functional changes to this library.
## [4.0.4] — 2026-04-16
### Changed
- README + manifest refresh for the v4 baseline. No functional changes vs 4.0.3.
- `LibraryManifest.Version` now reads from assembly metadata.
## [4.0.3] — 2026-04-16
### Fixed
- Added missing `<param name="connectionId">` XML doc tags so the public API
no longer trips doc-warning gates.
## [4.0.2] — 2026-04-09
### Changed
- Annotated SQLite configuration with `[ConfigField]` for the admin UI surface.
- Aligned with the v4 baseline across all libraries.
## [4.0.0] — 2026-04-09
Major rewrite. Republished as v4.0.0 to reset the version line under the
unified v4 baseline. Embedded-DB sibling of CL.MySQL2 with the same
repository pattern and attribute-driven schema sync.
### Notes
- The MySQL2 4.0 query-builder rewrite (projection pushdown, SQL aggregation,
smart-cache pools) has not been ported to CL.SQLite yet — repository
CRUD only.
- Earlier history is retained in the
[git log](https://github.com/Media2A/CodeLogic.Libs/commits/main/CL.SQLite).