Skip to content

Add SQL-to-Lightweight documentation with test-backed examples#516

Merged
Yaraslaut merged 4 commits into
masterfrom
docs/sql-to-lightweight-cookbook
Jul 1, 2026
Merged

Add SQL-to-Lightweight documentation with test-backed examples#516
Yaraslaut merged 4 commits into
masterfrom
docs/sql-to-lightweight-cookbook

Conversation

@Yaraslaut

Copy link
Copy Markdown
Member

Closes #368.

What

A new documentation page, docs/sql-to-lightweight.md, that presents how common SQL queries map to the Lightweight API across all three layers — raw SqlStatement, the query builder, and the high-level DataMapper — so users can pick the style that fits. Sections: SELECT (WHERE / AND-OR / IN / NULL / conditional filters / ORDER BY / LIMIT-TOP / pagination / DISTINCT / COUNT + aggregates / GROUP BY), JOINs (inner / left / multi-condition), INSERT (+ bulk), UPDATE, DELETE, relationships (BelongsTo / HasMany), CREATE TABLE / migrations, transactions, and custom result shapes.

Examples are test-backed and kept in sync

Every C++ block in the doc is compiled and executed against a real database by src/tests/DocExampleTests.cpp (11 test cases, 74 assertions). Each block carries a <!-- snippet: id --> tag whose code is identical to the //! [id] region in the test. scripts/check-doc-snippets.py enforces that equality and fails CI on any drift (with a unified diff); it also has a --fix mode that regenerates the doc blocks from the tested regions. The check runs in the existing check_docs CI job, and the contract is documented in AGENT.md.

Workflow to change an example: edit the //! [id] region in the test, copy the lines into the matching doc block, run python3 scripts/check-doc-snippets.py.

Testing

  • SQLite3 and MS SQL Server 2022 (Docker) locally — all 74 assertions pass.
  • PostgreSQL — covered by the CI dbms_test_matrix; no local ODBC driver was available to run it here.
  • clang-format clean; the new test file is registered in src/tests/CMakeLists.txt so it runs in the full per-DBMS matrix.

Notes

Risk

Low — additive. New doc page, one new test translation unit (additive to LightweightTest), one CI step, and registration lines. No library/runtime code changed.

🤖 Generated with Claude Code

Adds docs/sql-to-lightweight.md (issue #368): a SQL -> Lightweight cookbook
showing each common SQL operation in all three layers (raw SqlStatement,
query builder, DataMapper) so users can choose how to write it. Covers SELECT
(WHERE/IN/NULL/ORDER BY/LIMIT/pagination/DISTINCT/aggregates/GROUP BY), JOINs,
INSERT (+bulk), UPDATE, DELETE, relationships, CREATE TABLE/migrations,
transactions, and custom result shapes.

Every C++ example is compiled and executed by src/tests/DocExampleTests.cpp
against a real database. The examples and tests are kept in sync by
scripts/check-doc-snippets.py, which pairs each `<!-- snippet: id -->` doc block
with its `//! [id]` test region and fails on drift (with a unified diff and a
`--fix` mode). Wired into the check_docs CI job.

Tested: sqlite3 and mssql2022 (Docker) locally, 74 assertions in 11 cases.
PostgreSQL covered by the CI matrix (no local ODBC driver available).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Yaraslaut Yaraslaut requested a review from a team as a code owner June 26, 2026 17:00
@github-actions github-actions Bot added documentation Improvements or additions to documentation CI pipeline tests labels Jun 26, 2026
Yaraslaut and others added 2 commits June 26, 2026 19:08
Explain the problem If/ThenWhere solves (optional filter criteria without
manual if-branching), the present/empty semantics of each call, and show a
table of how the same builder emits different WHERE clauses as inputs vary.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Remove a stray </content> tag at end of file (unsupported html tag).
- Link to sql-migrations.md via its doxygen page id (#sql-migrations); it
  declares an explicit {#sql-migrations} anchor, so a filename ref does not
  resolve under WARN_AS_ERROR.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@christianparpart christianparpart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

The new DocExampleTests.cpp (mirroring docs/sql-to-lightweight.md) broke two
CI jobs:

* clang-tidy (23 warnings-as-errors): resolved every finding at the source —
  added `{}` default member initializers to the doc schema (silences
  -Wmissing-designated-field-initializers at the partial-init call sites, and
  matches the test suite's own Entities.hpp convention), initialised
  DepartmentHeadcount::headcount, used `std::ignore =` on the nodiscard
  ExecuteBatch, switched SeededCompany to designated init, and reworked the
  unchecked std::optional accesses into guarded forms. The guarded DataMapper
  load/update/relationship snippets now also demonstrate proper not-found
  handling, which is better documentation.

* C++26 reflection build: the snippet regions must show the stable C++20
  member-pointer API (&Employee::salary) that users write and that
  check-doc-snippets.py pins byte-for-byte, so they cannot use the
  reflection-only Member(...) test macro. Excluded this translation unit from
  the experimental LIGHTWEIGHT_CXX26_REFLECTION build; it is still compiled and
  executed against every DBMS in all other builds.

Doc snippet blocks updated to stay in sync (scripts/check-doc-snippets.py: OK).

Databases tested: sqlite3, mssql2022 (Docker) — both green (81 assertions,
11 test cases). PostgreSQL not runnable locally (no PG ODBC driver in this
env); emitted SQL is unchanged by these test-only edits and the PostgreSQL
job was already green in CI.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Yaraslaut Yaraslaut merged commit 4601129 into master Jul 1, 2026
28 checks passed
@Yaraslaut Yaraslaut deleted the docs/sql-to-lightweight-cookbook branch July 1, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI pipeline documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add example of SQL to Lightweight mapping in documentation

2 participants