SQLCute — Fluent SQL Query Builder for Delphi
🌍 Language: English | Español
Build SQL queries with a clean, type-safe fluent API. No string concatenation, no raw SQL juggling — just method chains that compile to parameterized SQL.
Concepts
| Concept | Description |
|---|---|
IQuery |
Fluent builder interface — every method returns IQuery for chaining |
TQuery.New |
Factory entry point — creates a ref-counted query, no Free needed |
TSQLResult |
Output: SQL string + Bindings array of positional parameters |
IQueryCompiler |
Strategy for dialect SQL generation (ANSI default, or a dialect compiler) |
Quick Start
uses Daf.SQLCute;
var Q := TQuery.New
.From('orders')
.Select(['id', 'total', 'status'])
.Where('status', 'pending')
.Where('total', '>', 100)
.OrderByDesc('created_at')
.Limit(20);
var R := TAnsiSqlCompiler.Create.Compile(Q);
// R.SQL → 'SELECT id, total, status FROM orders WHERE status = ? AND total > ? ORDER BY created_at DESC LIMIT 20'
// R.Bindings → ['pending', 100]Common Patterns
Filter and paginate
TQuery.New
.From('users')
.Where('active', True)
.ForPage(Page, 25) // LIMIT 25 OFFSET (Page-1)*25JOIN
TQuery.New
.From('orders')
.Join('customers', 'orders.customer_id', 'customers.id')
.Select(['orders.id', 'customers.name'])Aggregate
TQuery.New
.From('sales')
.GroupBy('product_id')
.SelectCount('*', 'qty')
.SelectSum('amount', 'total')
.Having('count(*)', '>', 10)DML
// INSERT
TQuery.New.From('logs')
.AsInsert(['level', 'message'], ['error', 'disk full']);
// UPDATE
TQuery.New.From('users')
.Where('id', 42)
.AsUpdate(['email'], ['new@example.com']);
// DELETE
TQuery.New.From('sessions')
.Where('expired', True)
.AsDelete;Dialect compiler
uses Daf.SQLCute.Compiler.Postgres;
var R := TPostgresCompiler.Create.Compile(Q);
// identifiers quoted with "", placeholders $1 $2 …Documentation
| Resource | Description |
|---|---|
| Usage Guide | Complete API reference with all methods |
| SELECT & FROM | Columns, DISTINCT, aggregates, ORDER BY, LIMIT |
| WHERE | Conditions, IN, EXISTS, groups, LIKE, date ops |
| JOINs | All join types and callbacks |
| GROUP BY / HAVING | Aggregation and HAVING |
| Set Operations | UNION, INTERSECT, EXCEPT, pagination |
| DML | INSERT, UPDATE, DELETE |
| Subqueries & CTEs | Derived tables, WITH, recursive CTEs |
| String Operations | LIKE, starts/ends/contains |
| Date Operations | WhereDate, dialect casting |
| Dialect Compilers | Postgres, MySQL, SQLite, SQL Server, Oracle, Firebird |
| Compilers Package | Dialect compiler classes |
Compilers
SQLCute.Compilers — Dialect Compilers
🌍 Language: English | Español
Dialect-specific SQL compilers for SQLCute. Each compiler extends the ANSI base with database-native identifier quoting, parameter placeholders, date casting, and pagination.
Available Compilers
| Class | Unit | Quote | Placeholder | Notes |
|---|---|---|---|---|
TPostgresCompiler |
Daf.SQLCute.Compiler.Postgres |
" |
$1, $2… |
::date casting |
TMySqlCompiler |
Daf.SQLCute.Compiler.MySql |
` |
? |
DATE(col) casting |
TSQLiteCompiler |
Daf.SQLCute.Compiler.SQLite |
" |
? |
date(col) / strftime |
TSqlServerCompiler |
Daf.SQLCute.Compiler.SqlServer |
[…] |
@p1, @p2… |
FETCH NEXT pagination |
TOracleCompiler |
Daf.SQLCute.Compiler.Oracle |
" |
:p1, :p2… |
TRUNC(col) date, FETCH pagination |
TFirebirdCompiler |
Daf.SQLCute.Compiler.Firebird |
" |
? |
EXTRACT date parts |
The ANSI base compiler (TAnsiSqlCompiler) lives in the SQLCute core package (Daf.SQLCute.Compiler).
Quick Example
uses
Daf.SQLCute,
Daf.SQLCute.Compiler.Postgres;
var Q := TQuery.New
.From('orders')
.Join('customers', 'orders.customer_id', 'customers.id')
.Where('orders.status', 'pending')
.WhereDate('orders.created_at', '2024-06-01')
.OrderByDesc('orders.created_at')
.Limit(50);
var R := TPostgresCompiler.Create.Compile(Q);
// R.SQL →
// SELECT * FROM "orders"
// INNER JOIN "customers" ON "orders"."customer_id" = "customers"."id"
// WHERE "orders"."status" = $1
// AND "orders"."created_at"::date = $2
// ORDER BY "orders"."created_at" DESC
// LIMIT 50Documentation
- Dialect Compilers Guide — full reference, DI pattern, custom compiler
- Date Operations — dialect date-cast matrix