Skip to content

Expand query DSL with CTEs, windows, pattern matching, and broader join support#81

Merged
Araq merged 12 commits intoAraq:masterfrom
elcritch:add-outer-expressions
Apr 16, 2026
Merged

Expand query DSL with CTEs, windows, pattern matching, and broader join support#81
Araq merged 12 commits intoAraq:masterfrom
elcritch:add-outer-expressions

Conversation

@elcritch
Copy link
Copy Markdown
Contributor

Summary

This PR extends the Ormin query DSL with several common SQL features and improves
test coverage around the newer syntax.

Added DSL features

  • CTE support via:

    query:
      with recent(select Post(id, author) where id <= 3)
      select recent(author)
    
  • Window expressions via:

    over(row_number(), partitionby(author), orderby(id))

  • Pattern predicates:

    • name like ?pattern
    • name ilike ?pattern
    • not (name \like ?pattern)
  • Additional join keywords:

    • leftjoin, leftouterjoin
    • rightjoin, rightouterjoin
    • fulljoin, fullouterjoin
    • crossjoin
    • legacy outerjoin still accepted

Refactoring

  • Generalized source/column handling so CTEs and base tables share the same
    column-resolution path.
  • Reworked join rendering so explicit join aliases and CTE-backed sources behave
    consistently.

Tests and docs

  • Added CTE tests:
    • single CTE
    • chained CTEs
    • CTEs used inside subqueries
  • Added window-function tests:
    • row_number()
    • running sum(...)
  • Added pattern-matching tests for like, ilike, and negated like
  • Expanded join coverage in tests/tfeature.nim
  • Updated README examples and supported-feature docs

Notes

  • ilike is lowered portably on SQLite using lower(lhs) like lower(rhs).
  • rightjoin / fulljoin are DSL-supported and compile-covered here, but not
    runtime-validated in the SQLite suite.

Comment thread ormin/queries.nim Outdated
Comment thread ormin/queries.nim Outdated
Co-authored-by: Andreas Rumpf <araq4k@proton.me>
@Araq Araq merged commit 2706d62 into Araq:master Apr 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants