Repository navigation
feat(rds): joins, subquery sources and column aliases in select - #352
Merged
Merged
Conversation
rds.select() now renders the join keys (all fifteen kinds, with `on` or `using`), a subquery aliased in `from` (a select or a sql template), and alias objects in `columns` and `returning`. Joins were previously dropped from the generated SQL without an error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
@aws-appsync/utils/rdsdeclares threeselect()inputs we did not handle:columns, e.g.columns: [{ sys_i: 'item.sys_i' }], rejected withInvalid type in column array.from, e.g.from: { item: select(...) }, rejected withTable alias value is expected to be a string.join,leftJoin, …,fullOuterJoinNatural), silently dropped: the SQL had no JOIN and no error was raised, so a resolver relying on a join returned wrong dataWhat this does
Behaviour recorded from
EvaluateCode:{ n: 'p.name' }→"p"."name" as "n". Only a string value is accepted; an aliased*is quoted.returningandusingshare the column list, so they accept aliases too.from: { s: select(...) }orfrom: { s: sql...}renders(...) as "s", with the subquery's variables numbered first. A bare statement asfrom, an insert as the aliased value, or a statement undertableare rejected with AWS's messages.FROMandWHERE. Each item takestableorfrom(same rules as the select's own), andon(asqltemplate or a condition object) orusing. AWS quirks reproduced:oncondition object binds its values as variables, likewhere, and accepts only strings and type hints (ON expects a string value comparisons.), so{ 'u.x': { eq: 't.x' } }compares against the string't.x'using: []rendersUSING (); only the applied kind is validatedrenderSelectis split out of the statement switch so a subquery can render inline with shared variable numbering.Not covered here:
rds.aggaggregates,groupByandhaving, which follow in the next PR along with the version bump and changelog.Tests
New
__tests__/rds-select.test.js, 100 cases recorded against AWS: each alias, source and join kind, the precedence chain as adjacent pairs, variable ordering across source, joins and where, and the validation errors. The full suite passes.🤖 Generated with Claude Code