Parameterized by default
Compile returns SQL with placeholders plus ordered bindings. A diagnostic preview with substituted values is a separate, explicit call.
FLUENT SQL FOR DELPHI 12+
QueryBuilder4Delphi builds parameterized SQL for six databases from one fluent Delphi API. Values become bindings, never concatenated text. A port of the .NET library SqlKata.
v2.0.0 adds object mapping, nullable DTOs and explicit NULL policies.
function SearchBooks(const Title, Author: string; PublishedOnly: Boolean;
Page, PageSize: Integer): IQuery;
begin
Result := TQuery.Create('Books as b')
.Join('Authors as a', 'a.Id', 'b.AuthorId')
.Select(['b.Id', 'b.Title', 'a.Name as AuthorName'])
.When(Title <> '',
function(Q: IQuery): IQuery
begin
Result := Q.WhereContains('b.Title', Title);
end)
.When(Author <> '',
function(Q: IQuery): IQuery
begin
Result := Q.WhereContains('a.Name', Author);
end)
.When(PublishedOnly,
function(Q: IQuery): IQuery
begin
Result := Q.WhereTrue('b.IsPublished');
end)
.OrderBy('b.Title').OrderBy('b.Id')
.ForPage(Page, PageSize);
end;SELECT [b].[Id], [b].[Title], [a].[Name] AS [AuthorName]
FROM [Books] AS [b]
INNER JOIN [Authors] AS [a] ON [a].[Id] = [b].[AuthorId]
WHERE [b].[Title] like @p0 AND [a].[Name] like @p1
AND [b].[IsPublished] = cast(1 as bit)
ORDER BY [b].[Title], [b].[Id]
OFFSET @p2 ROWS FETCH NEXT @p3 ROWS ONLYCompile returns SQL with placeholders plus ordered bindings. A diagnostic preview with substituted values is a separate, explicit call.
SQL Server, PostgreSQL, MySQL, SQLite, Oracle and Firebird. Quoting, placeholders and paging follow the selected compiler.
Map rows to classes with ToList, First or Single, write DTOs back, and execute through FireDAC or your own provider.
src to the Delphi search path. The core needs only the RTL; FireDAC is optional.QueryBuilder4Delphi.Query.Core and QueryBuilder4Delphi.Query.Execute with a provider.Paste a SELECT query and get fluent Delphi code. It runs entirely in your browser.