Skip to content

#129 - throw an error when selectExactlyOne retrieves 0 rows when used in lateral#189

Draft
lukeramsden wants to merge 6 commits intojawj:masterfrom
lukeramsden:luke/fix-select-exactly-one
Draft

#129 - throw an error when selectExactlyOne retrieves 0 rows when used in lateral#189
lukeramsden wants to merge 6 commits intojawj:masterfrom
lukeramsden:luke/fix-select-exactly-one

Conversation

@lukeramsden
Copy link
Copy Markdown

Has the commits from #188 too but see the final commit for the actual change

@lukeramsden lukeramsden marked this pull request as draft June 4, 2025 17:30
Comment thread src/db/core.ts
const copy = new SQLFragment<RunResult, Constraint>(literals, expressions);

// copy across relevant flags that aren’t part of the constructor
if (this.expectExactlyOne !== undefined) (copy as any).expectExactlyOne = this.expectExactlyOne;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can we not instead add expectExactlyOne to the set of properties copied across via Object.assign, just below?

Comment thread src/db/shortcuts.ts

query.runResultTransform =

// ---- runtime transform -------------------------------------------------
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Sorry, only a stylistic preference, but can we cut all the hyphens? :)

Comment thread src/db/shortcuts.ts

// If there are any lateral subqueries that themselves expected exactly one
// row, we need to verify those expectations here (their own transforms will
// not run, because only the outermost query's transform executes).
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Just wondering if it would be more elegant to have the nested transforms run, rather than doing a separate recurrsive transform from the top down? Would that make sense here?

@jawj
Copy link
Copy Markdown
Owner

jawj commented Jun 10, 2025

Thanks so much for working on this PR — and the beginning of a test suite! And sorry it's taken me a while to look at it.

I haven't had time for any deep thinking on this so far, but I have added a few comments, as you'll have seen.

My main worry is that it just seems like quite a lot of code and complication to support this. Is there any possible way this could be simplified? Is there even some simple change we could make to the SQL to have Postgres do the checking??

@lukeramsden
Copy link
Copy Markdown
Author

Busy today but will have a think about what you said + your comments and get back to you! Agree on all of what you're saying though.

lukeramsden added a commit to architect-eng/sapatos that referenced this pull request Nov 23, 2025
…it does when used standalone

See PR in upstream for more context: jawj/zapatos#189
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