Brief: EF Core 10 relational provider for DuckDB (for Cedric)¶
You are Cedric Jones-Gaffney (Codex), implementing. Clahadore (Claude) orchestrates and reviews.
Goal¶
A reusable C# library, EFCore.DuckDB (NuGet id JonesGaffney.EntityFrameworkCore.DuckDB, root namespace
JonesGaffney.EntityFrameworkCore.DuckDB). It is a real read/write EF Core relational provider for
DuckDB, built on the ADO.NET driver DuckDB.NET.Data.Full 1.5.6.1 (bundles DuckDB 1.5.6).
Target net10.0, EF Core 10.0.14 (Microsoft.EntityFrameworkCore.Relational). Its first consumer is
Verse4Verse (accounts, annotations, moderation decisions, studies, catalog, Scripture metadata). The
database is reached either as a local file, in memory, or through DuckDB's Quack remote protocol.
Must have (v0.1, in this order)¶
UseDuckDB(connectionString, o => ...)options extension, plus service registration (AddEntityFrameworkDuckDB),DuckDBOptionsExtension, connection (DuckDBRelationalConnection) andDuckDBDatabaseCreator(Exists/Create/Delete for file + in-memory; HasTables).- Type mappings: bool, sbyte/short/int/long, byte/ushort/uint/ulong (UTINYINT..UBIGINT), float, double, decimal(p,s), string (VARCHAR), byte[] (BLOB), Guid (UUID), DateTime (TIMESTAMP), DateTimeOffset (TIMESTAMPTZ), DateOnly (DATE), TimeOnly (TIME), TimeSpan (INTERVAL), enums via value conversion. Literal generation for each type must round-trip.
- SQL generation (
DuckDBQuerySqlGenerator,DuckDBSqlGenerationHelper): double-quoted identifiers,LIMIT/OFFSET,||concat,ILIKEnot needed, boolean literalsTRUE/FALSE, parameters$1-style or?(match whatever DuckDB.NET supports; check its docs/tests),CAST(x AS type). - Method/member translators: string Contains/StartsWith/EndsWith/ToLower/ToUpper/Trim/Length/Substring/
Replace/IsNullOrEmpty, Math Abs/Round/Floor/Ceiling/Max/Min, DateTime.Now/UtcNow/Year/Month/Day,
Guid.NewGuid →
uuid(),EF.Functions.Like. - Updates (
DuckDBUpdateSqlGenerator): INSERT/UPDATE/DELETE withRETURNINGfor store-generated values; identity viaSEQUENCE+DEFAULT nextval('seq')(DuckDB has no SERIAL/IDENTITY), generated per key in migrations. Optimistic concurrency tokens must work (rows-affected check). Transactions: DuckDB MVCC; savepoints are NOT supported by DuckDB — disable them cleanly (SupportsSavepoints => false/ override so SaveChanges doesn't emit SAVEPOINT). - Migrations:
DuckDBMigrationsSqlGenerator(CreateTable, DropTable, AddColumn, DropColumn, RenameColumn, RenameTable, CreateIndex, DropIndex, EnsureSchema, sequences, AddForeignKey as part of CREATE TABLE only — DuckDB cannot ALTER TABLE ADD CONSTRAINT FK; throw a clear NotSupportedException otherwise),DuckDBHistoryRepository(__EFMigrationsHistory), and a migrations lock compatible with EF 10 (IMigrationsDatabaseLock; use a lock table, since DuckDB has no advisory locks). Note: Verse4Verse will ALSO keep forward-only versioned SQL migrations in git; EF migrations must be scriptable (dotnet ef migrations script --idempotent) so they can be reviewed and run as a job. - Quack support: a documented way to point a context at a Quack server. Approach: open an in-memory
DuckDB connection, then run
ATTACH 'quack:<host>' AS app (TOKEN '<token>'); USE app;on open via aDbConnectionInterceptorexposed aso.UseQuack(uri, token). Token never logged. Integration test it only if a local Quack server is available (QUACK_TEST_URIenv); skip otherwise.
Tests (xunit, in tests/)¶
- Unit tests for type mapping literals and SQL generation (golden SQL strings).
- Functional tests against in-memory DuckDB: a small blog/posts/tags model covering CRUD, includes,
owned types, value conversions, concurrency token conflict, transactions, migrations up from empty,
EnsureCreated, and LINQ translations listed above. Assert real results, not just "no exception". - If time permits, wire a subset of
Microsoft.EntityFrameworkCore.Relational.Specification.Testsand report the pass rate.
Rules¶
- C#. No other language. Small, readable classes mirroring the structure of the Npgsql/Sqlite providers.
- Check DuckDB SQL facts against the DuckDB docs (https://duckdb.org/docs/) when unsure; don't guess.
- Don't run anything that opens a visible window. Builds/tests with
dotnet build/dotnet test. - This PC is under memory pressure: build serially,
-m:1, no parallel test hosts beyond default. git initis done; commit in small logical commits on branchmainwith messagesEFCore.DuckDB: <what>. Do NOT push, do NOT create a GitHub repo.- License header: none yet (license is Andrew's decision); add
LICENSE-PENDING.mdnoting that.
Done means¶
dotnet build -c Release and dotnet test -c Release pass, and README.md documents usage, the type
map, what is and isn't supported (savepoints, FK alter), and the Quack setup. End your run with a summary:
commits, test counts (passed/failed/skipped), and the not-yet-supported list.