Quarry

Quarry

Type-safe SQL builder for .NET 10. Write C# — the compiler emits SQL. Zero reflection. AOT compatible.


Explore the Documentation

Getting Started

Install Quarry and write your first compile-time query in minutes.

Schema Definition

Define tables as C# classes with typed column properties.

Context Definition

Configure your QuarryContext with dialect, schema, and connection settings.

Switching Dialects

Change one enum value to retarget your entire project to a different database.

Querying

Select, filter, join, aggregate — all compiled to SQL at build time.

Prepared Queries

Compile once, execute multiple ways with zero overhead.

Modifications

Insert, update, and delete with initializer-aware compile-time analysis.

Migrations

Code-first migration diffing via the CLI tool.

Scaffolding

Reverse-engineer an existing database into schema classes.

Diagnostics

Inspect generated SQL, parameters, and optimization metadata.

Logging

Structured logging with sensitive parameter redaction and slow query detection.

Analyzer Rules

Compile-time SQL analysis rules and code fixes.

Migrating to Quarry

Migrate from Dapper, EF Core, SqlKata, or raw ADO.NET.

Benchmarks

Performance comparison against Dapper, EF Core, and SqlKata.


See It in Action

You write a query in C#:

var activeUsers = await db.Users()
    .Select(u => new { u.UserName, u.Email })
    .Where(u => u.IsActive)
    .OrderBy(u => u.UserName)
    .Limit(10)
    .ExecuteFetchAllAsync();

At compile time, the source generator emits this SQL as a string literal — no runtime translation:

SELECT "UserName", "Email" FROM "users" WHERE "IsActive" = 1 ORDER BY "UserName" LIMIT 10

Quick Install

<PackageReference Include="Quarry" Version="1.0.0" />

The source generator is included automatically. Enable interceptors in your .csproj:

<PropertyGroup>
  <InterceptorsNamespaces>$(InterceptorsNamespaces);MyApp.Data</InterceptorsNamespaces>
</PropertyGroup>

Why Quarry?

Compile-Time SQL

All SQL is generated at build time by a Roslyn source generator. No runtime query building, no surprises.

Zero Reflection

Ordinal-based readers and pre-allocated parameter arrays. Fully NativeAOT compatible.

Switch Dialects Instantly

Change one enum value and rebuild. SQLite, PostgreSQL, MySQL, SQL Server — all SQL re-emits automatically. Run multiple dialects side by side.

Conditional Branches

Build queries with if/else — the generator emits all SQL variants and dispatches via bitmask.

Type-Safe Schema

Define tables as C# classes. Columns, foreign keys, indexes, and navigations — all checked at compile time.

Migrations & Scaffolding

Code-first migration diffing via CLI. Reverse-engineer existing databases into schema classes.