CSharpDB.Engine
2.0.0
Prefix Reserved
See the version list below for details.
dotnet add package CSharpDB.Engine --version 2.0.0
NuGet\Install-Package CSharpDB.Engine -Version 2.0.0
<PackageReference Include="CSharpDB.Engine" Version="2.0.0" />
<PackageVersion Include="CSharpDB.Engine" Version="2.0.0" />
<PackageReference Include="CSharpDB.Engine" />
paket add CSharpDB.Engine --version 2.0.0
#r "nuget: CSharpDB.Engine, 2.0.0"
#:package CSharpDB.Engine@2.0.0
#addin nuget:?package=CSharpDB.Engine&version=2.0.0
#tool nuget:?package=CSharpDB.Engine&version=2.0.0
CSharpDB.Engine
Lightweight embedded SQL database engine for .NET with single-file storage, WAL durability, concurrent readers, and a typed Collection<T> NoSQL API.
Overview
CSharpDB.Engine is the main entry point for embedding CSharpDB in your .NET application. It combines the SQL parser, query planner, and B+tree storage engine into a single Database class with two access paths: a full SQL engine and a zero-SQL Collection<T> document API. You can run against a normal on-disk database file or open the engine fully in memory and explicitly save/load snapshots when needed.
Features
- SQL engine: DDL, DML, JOINs, aggregates, GROUP BY, HAVING, CTEs,
UNION/INTERSECT/EXCEPT, scalar subqueries,IN (SELECT ...),EXISTS (SELECT ...), views, triggers, indexes,ANALYZE, andsys.*catalogs includingsys.table_statsandsys.column_stats - NoSQL Collection API: Typed
Collection<T>withPut/Get/Delete/Scan/Find - Single-file storage: All data in one
.dbfile with 4 KB B+tree pages - In-memory mode: Open empty in memory, load an existing
.db+.walinto memory, then save back to disk - WAL durability: Write-ahead log with crash recovery
- Concurrent readers: Snapshot-isolated readers alongside a single writer
- Statement + plan caching: bounded caches for parsed SQL statements and SELECT plan reuse
- Fast-path lookups: Direct B+tree access for
SELECT ... WHERE pk = value - Persisted statistics: Exact row counts maintained on write,
ANALYZE-refreshed column distinct/min/max stats, stale tracking after writes, and reuse of fresh stats forCOUNT(*)and selective lookup planning - Async-first: All APIs are
async/awaitfrom top to bottom
Current boundary:
- Correlated subqueries are supported in
WHERE, non-aggregate projection expressions, andUPDATE/DELETEexpressions. - Correlated subqueries in
JOIN ON,GROUP BY,HAVING,ORDER BY, and aggregate projections remain unsupported. UNION ALLremains planned.
Usage
SQL API
using CSharpDB.Engine;
// Open or create a database
await using var db = await Database.OpenAsync("myapp.db");
// Create a table
await db.ExecuteAsync("""
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT,
email TEXT
)
""");
// Insert data
await db.ExecuteAsync("INSERT INTO users VALUES (1, 'Alice', 'alice@example.com')");
// Query data
var result = await db.ExecuteAsync("SELECT name, email FROM users WHERE id = 1");
while (await result.MoveNextAsync())
{
Console.WriteLine($"{result.Current[0].AsText} - {result.Current[1].AsText}");
}
// Transactions
await db.BeginTransactionAsync();
await db.ExecuteAsync("INSERT INTO users VALUES (2, 'Bob', 'bob@example.com')");
await db.CommitAsync();
In-Memory Open, Load, and Save
using CSharpDB.Engine;
// Start with an empty in-memory database
await using var db = await Database.OpenInMemoryAsync();
await db.ExecuteAsync("CREATE TABLE cache (id INTEGER PRIMARY KEY, value TEXT)");
await db.ExecuteAsync("INSERT INTO cache VALUES (1, 'hot data')");
// Persist the current committed state to disk
await db.SaveToFileAsync("cache.db");
// Load an existing on-disk database into memory, including committed WAL state
await using var imported = await Database.LoadIntoMemoryAsync("cache.db");
NoSQL Collection API
// Get a typed collection
var users = await db.GetCollectionAsync<User>("users");
// Put a document
await users.PutAsync("alice", new User { Name = "Alice", Age = 30 });
// Get a document
var alice = await users.GetAsync("alice");
// Scan all documents
await foreach (var user in users.ScanAsync())
{
Console.WriteLine(user.Name);
}
// Find with predicate
var adults = await users.FindAsync(u => u.Age >= 18);
Concurrent Readers
// Create a snapshot-isolated reader session
using var reader = db.CreateReaderSession();
var result = await reader.ExecuteReadAsync("SELECT * FROM users");
// Reads from a consistent snapshot while the writer continues
Reuse the same ReaderSession for a burst of related reads when possible. The current file-backed tuning benchmarks show that reusing a snapshot is materially cheaper than creating a new reader session for every single query.
Installation
dotnet add package CSharpDB.Engine
For the recommended all-in-one package:
dotnet add package CSharpDB
Dependencies
CSharpDB.Primitives- shared type systemCSharpDB.Sql- SQL parserCSharpDB.Storage- B+tree storage engineCSharpDB.Execution- query planner and operators
Related Packages
| Package | Description |
|---|---|
| CSharpDB.Data | ADO.NET provider built on this engine |
| CSharpDB.Client | Authoritative client SDK over direct and remote transports |
| CSharpDB.Storage.Diagnostics | Storage inspection and integrity checking |
License
MIT - see LICENSE for details.
| 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
- CSharpDB.Execution (>= 2.0.0)
- CSharpDB.Primitives (>= 2.0.0)
- CSharpDB.Sql (>= 2.0.0)
- CSharpDB.Storage (>= 2.0.0)
- CSharpDB.Storage.Diagnostics (>= 2.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on CSharpDB.Engine:
| Package | Downloads |
|---|---|
|
CSharpDB.Data
ADO.NET provider for CSharpDB. Standard DbConnection, DbCommand, and DbDataReader with parameterized queries and transactions. |
|
|
CSharpDB.Client
Unified CSharpDB client SDK with pluggable transports (Direct, HTTP, gRPC, TCP, Named Pipes). |
|
|
CSharpDB
All-in-one package for CSharpDB application development. Includes the unified client, engine, ADO.NET provider, and diagnostics. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 91 | 4/8/2026 |
| 2.9.1 | 109 | 4/7/2026 |
| 2.8.1 | 106 | 4/6/2026 |
| 2.8.0 | 97 | 4/4/2026 |
| 2.7.0 | 98 | 3/31/2026 |
| 2.6.0 | 100 | 3/29/2026 |
| 2.5.0 | 202 | 3/28/2026 |
| 2.4.0 | 100 | 3/24/2026 |
| 2.3.0 | 99 | 3/22/2026 |
| 2.2.0 | 94 | 3/21/2026 |
| 2.0.1 | 114 | 3/14/2026 |
| 2.0.0 | 97 | 3/13/2026 |
| 1.9.0 | 119 | 3/12/2026 |
| 1.8.0 | 118 | 3/11/2026 |
| 1.7.0 | 118 | 3/8/2026 |
| 1.6.0 | 105 | 3/8/2026 |
| 1.5.0 | 107 | 3/7/2026 |
| 1.4.0 | 106 | 3/7/2026 |
| 1.3.0 | 106 | 3/6/2026 |
| 1.2.0 | 106 | 3/5/2026 |