Repository navigation
feat(rds): agg aggregates, groupBy, having and not conditions - #353
Merged
Merged
Conversation
Add the rds.agg helpers (max, min, count, avg, sum and their Distinct variants), usable as select columns or aliased columns, and the groupBy and having select clauses, with aggregate conditions accepted in having only. Bumps to v0.1.11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Condition objects accept a `not` group, rendering `NOT (...)` with its
items ANDed, in WHERE, ON and HAVING. `and`/`or`/`not` are matched in any
casing, like AWS. A group item with several columns is now grouped as a
whole, so `or: [{ a, b }, { c }]` renders `(a AND b) OR (c)` instead of
ORing every column.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bentsku
marked this pull request as ready for review
November 18, 2026 16:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #352.
Problem
@aws-appsync/utils/rdsdeclares anagghelper, thegroupByandhavingselect keys and anotcondition group, none of which we provide:rds.aggis undefined,groupBy/havingwere dropped from the generated SQL without an error, andnotwas read as a column name.Separately, an
oritem with several columns ORed every column:or: [{ a, b }, { c }]rendered(a) OR (b) OR (c), where AWS renders(a AND b) OR (c).What this does
Behaviour recorded from
EvaluateCode:rds.agg:max,min,count,avg,sumand their*Distinctvariants renderMAX("a"),COUNT(DISTINCT "a"), etc. The column is validated when the helper is called: onlyCOUNTtakes*, a distinct aggregate never does, a nullish column renders an empty argument list, and a non-string column raises theClassCastExceptionAWS leaks, reproduced verbatim.returningrefuses a bare aggregate but lets an aliased one through, andusingaccepts both, like AWS. An aggregate used as a statement,fromsource or bound value is rejected.groupByrenders afterWHERE: strings are quoted (a star too), 32-bit integers render as column positions, and an empty list is rejected.havingtakes asqltemplate or a condition object, renders afterGROUP BY(even without one) and beforeORDER BY. Its condition object accepts aggregate conditions,{ price: { sum: { gt: 100 } } }→SUM("price") > :P0, witheq/ne/gt/lt/ge/leonly (AWS refusesbetweenalthough the typings allow it) and a nullish value inlined asNULL. Aggregate conditions inWHEREorONare rejected.notgroups renderNOT (...)with their items ANDed, inWHERE,ONandHAVING. Unlike an emptyand/or, an emptynotstill renders, asNOT ().orcase above.and/or/notare matched in any casing (OR,And), with messages naming the key as written. Operators and aggregate keys stay case-sensitive.The WHERE builder becomes
buildConditionParts(keyword, condition), shared by WHERE, ON and HAVING; it records which clause is rendering, which is how ON's string-only rule and the aggregate rules are applied.The logical-group rendering is rewritten around that item grouping, dropping the grouping parameters
buildWhereClauseandbuildWhereStatementthreaded through.Bumps to v0.1.11, with a changelog line covering #352 as well.
Tests
New
__tests__/rds-aggregates.test.js, 92 cases recorded against AWS: each aggregate as a column and as ahavingcondition, the argument validation,groupByitem types, clause ordering and validation order, and the aggregate rejections inWHERE,ONandreturning.New
__tests__/rds-conditions.test.js, 38 cases recorded against AWS:notalone, nested and in each clause, its empty forms and validation, the logical key casing, and multi-column group items. The full suite passes.🤖 Generated with Claude Code