Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ Versions follow [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Fixed

- SQL → Delphi converter: `A OR B AND C` was converted as `(A OR B) AND C` for
MySQL, PostgreSQL and SQLite input, because the parser groups AND/OR left to
right. The converter now restores SQL precedence (AND before OR) and keeps
explicit parentheses.

### Added

- Website landing page with an example, highlights, installation steps and a
link to the converter. The README is now the **Getting started** guide.
- Converter support for COUNT/SUM/AVG/MIN/MAX (`SelectCount` and so on),
aggregates in HAVING and ORDER BY (`HavingRaw`, `OrderByRaw`), subqueries in
IN, NOT IN, EXISTS, NOT EXISTS and comparisons, and `NOT (…)` groups.

### Changed

- The converter emits flat fluent chains for AND or OR sequences and nests a
callback only where the operator changes.
- Converter error messages quote the unsupported SQL fragment and suggest the
fluent or raw method to use instead, without internal parser terms.
- The convert button sits between the SQL input and the Delphi output. Page
transitions no longer fade content in from transparent.

## [2.0.0] - 2026-10-31

Object mapping, nullable DTO round trips, parameterized fluent compilation and
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ Current release: **[v2.0.0](https://github.com/auchri/QueryBuilder4Delphi/releas
See the [changelog](CHANGELOG.md) for release details and the
[migration guide](docs/MIGRATION.md) when upgrading from v1.0.0.

<!-- website:skip -->
**[Documentation website](https://auchri.github.io/QueryBuilder4Delphi/)** ·
**[SQL → Delphi converter](https://auchri.github.io/QueryBuilder4Delphi/converter.html)**
<!-- /website:skip -->

Version 2 adds fluent object mapping, nullable read/write DTOs and explicit SQL
NULL policies. `Compile` now returns parameterized SQL and bindings;
Expand Down
7 changes: 7 additions & 0 deletions docs/WEBSITE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ point back to GitHub. The generated pages include syntax highlighting, an
on-page contents list, and a link to their original Markdown source.
The generated `website/dist/` directory is ignored by Git.

The start page (`index.html`) is a short landing page built from
`website/index.html`. Its code example and generated SQL are read from the
README's `SearchBooks` example, so they stay checked against the compiler. The
README itself becomes `guide.html` (**Getting started**). README content that
only makes sense on GitHub, such as links to this website, is wrapped in
`<!-- website:skip -->` … `<!-- /website:skip -->` and left out of the guide.

The footer on every page links to the current GitHub release. Its version is
read from the `Current release` declaration in `README.md`, so updating that
declaration also updates the website. The changelog and
Expand Down
2 changes: 2 additions & 0 deletions website/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const examples = {
basic: 'SELECT Id, Title\nFROM Books\nWHERE AuthorId = 42\nORDER BY Title;',
join: "SELECT b.Id, b.Title, a.Name AS AuthorName\nFROM Books AS b\nLEFT JOIN Authors AS a ON a.Id = b.AuthorId\nWHERE b.Price >= 10\nORDER BY b.Title;",
group: "SELECT Id, Title\nFROM Books\nWHERE (AuthorId = 42 OR AuthorId = 7)\n AND Price BETWEEN 10 AND 50\n AND DeletedAt IS NULL\nORDER BY Title DESC;",
aggregate: 'SELECT AuthorId, COUNT(*) AS BookCount, AVG(Price) AS AveragePrice\nFROM Books\nWHERE DeletedAt IS NULL\nGROUP BY AuthorId\nHAVING COUNT(*) >= 5\nORDER BY BookCount DESC;',
subquery: "SELECT Id, Title\nFROM Books\nWHERE AuthorId IN (SELECT Id FROM Authors WHERE Country = 'AT')\n AND NOT EXISTS (SELECT 1 FROM Orders o WHERE o.BookId = Books.Id);",
paging: 'SELECT Id, Title\nFROM Books\nORDER BY Title, Id\nLIMIT 20 OFFSET 40;',
};
const editors = createEditors({
Expand Down
28 changes: 22 additions & 6 deletions website/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const release = (await readFile(path.join(root, 'README.md'), 'utf8')).match(/Cu
if (!release) throw new Error('README.md must declare the current release.');
const escape = s => String(s).replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;');
export const documents = ['README.md', 'CHANGELOG.md', ...(await readdir(path.join(root, 'docs'))).filter(f => f.endsWith('.md')).map(f => `docs/${f}`)];
const target = source => source === 'README.md' ? 'index.html' : source.replace(/\.md$/, '.html');
// index.html is the hand-written landing page; the README becomes the guide.
const target = source => source === 'README.md' ? 'guide.html' : source.replace(/\.md$/, '.html');
export function linkTo(href, source) {
if (!href || /^(?:[a-z][a-z0-9+.-]*:|\/\/|#)/i.test(href)) return href;
const match = href.match(/^([^?#]*)(.*)$/);
Expand All @@ -23,7 +24,7 @@ export function linkTo(href, source) {
return path.posix.relative(path.posix.dirname(target(source)), target(resolved)) + match[2];
}
const menu = [
['README.md', 'Overview'], ['converter.html', 'SQL → Delphi'],
['index.html', 'Home'], ['README.md', 'Getting started'], ['converter.html', 'SQL → Delphi'],
['docs/EXAMPLES.md', 'Examples'], ['docs/API.md', 'API reference'],
['docs/OBJECT_MAPPING.md', 'Object mapping'], ['docs/PORTING.md', 'Porting'],
['docs/MIGRATION.md', 'Upgrade to v2'],
Expand All @@ -36,22 +37,23 @@ function shell(title, body, source, toc = []) {
const prefix = path.posix.relative(path.posix.dirname(filename), '.') || '.';
const relative = to => path.posix.relative(path.posix.dirname(filename), to);
const navLink = ([file, label]) => `<a ${file === source ? 'aria-current="page"' : ''} href="${relative(target(file))}">${label}</a>`;
const advanced = menu.slice(5);
const advanced = menu.slice(6);
const expanded = advanced.some(([file]) => file === source);
return `<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<title>${escape(title)} · QueryBuilder4Delphi</title><meta name="description" content="Fluent, parameterized SQL for Delphi. Documentation and a browser-local SQL to Delphi converter.">
<link rel="stylesheet" href="${prefix}/assets/style.css"><link rel="icon" href="${prefix}/assets/favicon.svg" type="image/svg+xml"></head>
<body id="top"><a class="skip" href="#main">Skip to content</a><header><a class="brand" href="${relative('index.html')}"><span class="logo">Q<span>›</span></span>QueryBuilder<span class="muted">4Delphi</span></a><a href="${repo}">GitHub ↗</a></header>
<div class="layout"><aside class="sidebar"><p class="eyebrow">DEVELOPER GUIDE</p><div class="nav-scroll"><nav aria-label="Documentation">${menu.slice(0, 5).map(navLink).join('')}<details class="advanced-nav"${expanded ? ' open' : ''}><summary aria-expanded="${expanded}">Advanced</summary><div class="advanced-links">${advanced.map(navLink).join('')}</div></details></nav></div><div class="sidebar-note">Delphi 12+<br>Win32 & Win64<br><span>Six SQL dialects. One fluent API.</span></div></aside>
<main id="main" class="${source === 'converter.html' ? 'converter-page' : 'documentation'}">${body}<footer>QueryBuilder4Delphi · <a href="${repo}/releases/tag/${release}">${release}</a> · <a href="${repo}/blob/main/LICENSE">MIT license</a> · <a href="${prefix}/assets/third-party-licenses.txt">Third-party licenses</a>${source.endsWith('.md') ? ` · <a href="${repo}/blob/main/${source}">View Markdown source ↗</a>` : ''}</footer></main>
<div class="layout"><aside class="sidebar"><p class="eyebrow">DEVELOPER GUIDE</p><div class="nav-scroll"><nav aria-label="Documentation">${menu.slice(0, 6).map(navLink).join('')}<details class="advanced-nav"${expanded ? ' open' : ''}><summary aria-expanded="${expanded}">Advanced</summary><div class="advanced-links">${advanced.map(navLink).join('')}</div></details></nav></div><div class="sidebar-note">Delphi 12+<br>Win32 & Win64<br><span>Six SQL dialects. One fluent API.</span></div></aside>
<main id="main" class="${{ 'converter.html': 'converter-page', 'index.html': 'landing' }[source] || 'documentation'}">${body}<footer>QueryBuilder4Delphi · <a href="${repo}/releases/tag/${release}">${release}</a> · <a href="${repo}/blob/main/LICENSE">MIT license</a> · <a href="${prefix}/assets/third-party-licenses.txt">Third-party licenses</a>${source.endsWith('.md') ? ` · <a href="${repo}/blob/main/${source}">View Markdown source ↗</a>` : ''}</footer></main>
${toc.length ? `<aside class="toc"><p class="eyebrow">ON THIS PAGE</p><nav aria-label="On this page">${toc.map(h => `<a href="#${h.id}">${h.text}</a>`).join('')}</nav></aside>` : ''}</div>
<a class="back-to-top" href="#top" aria-label="Back to top" hidden><span aria-hidden="true">↑</span> Back to top</a>
<script type="module" src="${prefix}/assets/navigation.js"></script></body></html>`;
}
await mkdir(path.join(output, 'assets'), { recursive: true });
for (const source of documents) {
const markdown = await readFile(path.join(root, source), 'utf8');
// Website-only pages replace README content marked with website:skip, such as links to this site.
const markdown = (await readFile(path.join(root, source), 'utf8')).replace(/<!-- website:skip -->[\s\S]*?<!-- \/website:skip -->\r?\n?/g, '');
const slugger = new GithubSlugger();
const toc = [];
const marked = new Marked({ renderer: {
Expand All @@ -74,6 +76,20 @@ for (const source of documents) {
await mkdir(path.dirname(file), { recursive: true });
await writeFile(file, shell(title, body, source, toc));
}
// The landing page example comes from the README, whose generated SQL is checked
// against the compiler; the page only adds layout around it.
const readme = await readFile(path.join(root, 'README.md'), 'utf8');
function readmeBlock(after, language) {
const start = readme.indexOf(after);
const code = start < 0 ? null : readme.slice(start).match(new RegExp('```' + language + '\\r?\\n([\\s\\S]*?)```'))?.[1];
if (!code) throw new Error(`README.md must contain a ${language} block after ${after}`);
return hljs.highlight(code.replace(/\r\n/g, '\n').trimEnd(), { language }).value;
}
const landing = (await readFile(path.join(site, 'index.html'), 'utf8'))
.replaceAll('{{repo}}', repo).replaceAll('{{release}}', release)
.replace('{{example-delphi}}', readmeBlock('## Fluent search with optional filters', 'delphi'))
.replace('{{example-sql}}', readmeBlock('<!-- mssql:SearchBooks -->', 'sql'));
await writeFile(path.join(output, 'index.html'), shell('Fluent, parameterized SQL for Delphi', landing, 'index.html'));
const converter = await readFile(path.join(site, 'converter.html'), 'utf8');
await writeFile(path.join(output, 'converter.html'), shell('SQL to Delphi', converter, 'converter.html'));
await cp(path.join(site, 'style.css'), path.join(output, 'assets/style.css'));
Expand Down
11 changes: 6 additions & 5 deletions website/converter.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<p class="eyebrow">THE QUERY WORKBENCH</p>
<h1>SQL in. <span class="accent">Delphi out.</span></h1>
<p class="lead">Turn a SELECT query into fluent QueryBuilder4Delphi code. Everything runs in your browser; your SQL stays on your device.</p>
<div class="toolbar"><label for="dialect">Input dialect <select id="dialect"><option value="MySQL">MySQL</option><option value="PostgreSQL">PostgreSQL</option><option value="TransactSQL">SQL Server</option><option value="SQLite">SQLite</option></select></label><label for="example">Example <select id="example"><option value="basic">Book search</option><option value="join">Join & aliases</option><option value="group">Grouped conditions</option><option value="paging">Paging</option></select></label><button id="load-example" type="button">Load example</button></div>
<div class="editors"><section class="editor-panel"><div class="panel-heading"><span id="sql-label">01 <strong>SQL input</strong></span><span>SELECT</span></div><div id="sql" class="code-editor" aria-labelledby="sql-label"><script type="text/plain" id="initial-sql">SELECT Id, Title
<div class="toolbar"><label for="dialect">Input dialect <select id="dialect"><option value="MySQL">MySQL</option><option value="PostgreSQL">PostgreSQL</option><option value="TransactSQL">SQL Server</option><option value="SQLite">SQLite</option></select></label><label for="example">Example <select id="example"><option value="basic">Book search</option><option value="join">Join & aliases</option><option value="group">Grouped conditions</option><option value="aggregate">Counts per author</option><option value="subquery">Subqueries</option><option value="paging">Paging</option></select></label><button id="load-example" type="button">Load example</button></div>
<div class="editors"><div class="input-column"><section class="editor-panel"><div class="panel-heading"><span id="sql-label">01 <strong>SQL input</strong></span><span>SELECT</span></div><div id="sql" class="code-editor" aria-labelledby="sql-label"><script type="text/plain" id="initial-sql">SELECT Id, Title
FROM Books
WHERE AuthorId = 42
ORDER BY Title;</script></div></section><section class="editor-panel"><div class="panel-heading"><span id="delphi-label">02 <strong>Delphi output</strong></span><button type="button" id="copy" disabled>Copy code</button></div><div id="delphi" class="code-editor" aria-labelledby="delphi-label"></div></section></div>
ORDER BY Title;</script></div></section>
<p id="editor-help" class="editor-help">Ctrl+Enter (⌘Enter) to convert · Tab to indent · Escape, then Tab to leave the SQL editor.</p>
<div class="convert-actions"><button id="convert" type="button" class="primary">Convert to Delphi <span aria-hidden="true">→</span></button><p id="status" role="status" aria-live="polite">Ready to convert.</p></div>
<section class="support" id="support"><h2>What can I convert?</h2><p>One SELECT statement with table and column aliases, DISTINCT, INNER/LEFT/RIGHT JOIN with one column comparison, CROSS JOIN, grouped AND/OR conditions, column comparisons, LIKE, IN, BETWEEN, IS NULL, GROUP BY, simple HAVING, ORDER BY and literal paging values. SQL Server TOP and OFFSET/FETCH are also supported.</p><p>CTEs, unions, subqueries, aggregate/function expressions, complex JOIN conditions, placeholders, quoted identifiers containing spaces or punctuation, and dialect-specific extensions are rejected. No partial code or raw SQL fallback is emitted. Zero row limits and MySQL string literals with backslash escapes are rejected because their meaning cannot be preserved reliably.</p><p>Ordinary decimals produce natural Delphi literals such as 19.99, without BCD wrappers or extra imports. Decimals are limited to 15 significant digits (ignoring insignificant zeros) within the normal Double range; high-precision values, subnormal values and scientific notation are rejected. Binary floating-point parameters do not guarantee exact SQL DECIMAL semantics. Exact parameter types depend on your schema: choose Currency, TBcd or another Delphi type manually when needed. Signed integer values retain exact Integer/Int64 validation.</p><p>The output is a complete <code>BuildQuery: IQuery</code> function. Compile it with your chosen <code>TSqlDialect</code> in Delphi; the converter does not execute SQL or run the Delphi compiler. PostgreSQL unquoted identifiers are folded to lowercase. SQL comments are not included in the output.</p></section>
<div class="convert-actions"><button id="convert" type="button" class="primary">Convert to Delphi <span aria-hidden="true">→</span></button><p id="status" role="status" aria-live="polite">Ready to convert.</p></div></div>
<section class="editor-panel"><div class="panel-heading"><span id="delphi-label">02 <strong>Delphi output</strong></span><button type="button" id="copy" disabled>Copy code</button></div><div id="delphi" class="code-editor" aria-labelledby="delphi-label"></div></section></div>
<section class="support" id="support"><h2>What can I convert?</h2><p>One SELECT statement with table and column aliases, DISTINCT, INNER/LEFT/RIGHT JOIN with one column comparison, CROSS JOIN, AND/OR conditions with SQL precedence, NOT (…), column comparisons, LIKE, IN, BETWEEN, IS NULL, GROUP BY, HAVING, ORDER BY and literal paging values. SQL Server TOP and OFFSET/FETCH are also supported.</p><p>COUNT, SUM, AVG, MIN and MAX in the select list become <code>SelectCount</code>, <code>SelectSum</code> and so on; aggregates in HAVING and ORDER BY become <code>HavingRaw</code> and <code>OrderByRaw</code> with parameterized values. Subqueries work in IN, NOT IN, EXISTS, NOT EXISTS and comparisons, and are generated as nested <code>TQuery.Create</code> chains.</p><p>CTEs, unions, derived tables in FROM, other functions and expressions, COUNT(DISTINCT …), complex JOIN conditions, placeholders, quoted identifiers containing spaces or punctuation, and dialect-specific extensions are rejected. The message quotes the unsupported part and suggests the fluent or raw method to use instead; no partial code is emitted. Zero row limits and MySQL string literals with backslash escapes are rejected because their meaning cannot be preserved reliably.</p><p>Ordinary decimals produce natural Delphi literals such as 19.99, without BCD wrappers or extra imports. Decimals are limited to 15 significant digits (ignoring insignificant zeros) within the normal Double range; high-precision values, subnormal values and scientific notation are rejected. Binary floating-point parameters do not guarantee exact SQL DECIMAL semantics. Exact parameter types depend on your schema: choose Currency, TBcd or another Delphi type manually when needed. Signed integer values retain exact Integer/Int64 validation.</p><p>The output is a complete <code>BuildQuery: IQuery</code> function. Compile it with your chosen <code>TSqlDialect</code> in Delphi; the converter does not execute SQL or run the Delphi compiler. PostgreSQL unquoted identifiers are folded to lowercase. SQL comments are not included in the output.</p></section>
<script type="module" src="./assets/app.js"></script>
Loading
Loading