feat(orm): select_sub / add_select subquery-as-column + table() setter#170
Open
tmgbedu wants to merge 1 commit into
Open
feat(orm): select_sub / add_select subquery-as-column + table() setter#170tmgbedu wants to merge 1 commit into
tmgbedu wants to merge 1 commit into
Conversation
Add subquery-as-column support to the async query builder: - select_sub(builder, alias) and add_select(alias, subquery) render a subquery as an aliased column, (subquery) AS alias, with bindings emitted in SELECT position (before WHERE). add_select also accepts a callable that builds the subquery on a fresh builder. - table(name) sets the target table on a bare builder; this is the setter the *Through/BelongsToMany with-count query paths already reference, so it resolves those dangling calls, and it backs the callable form of add_select. Existing string-based select() is unchanged. Covered by grammar-level to_sql()/to_qmark() with binding-order assertions across all four dialects (SQLite, MySQL, Postgres, MSSQL, incl. MSSQL TOP n), plus a real sqlite-backed suite.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
✅ Code Review Verdict: APPROVE (posted as comment — GH blocks self-approval)Reviewed for correctness, binding order, alias emission, and regression. All gates reproduced locally on the PR branch. Verified
Gates reproduced (PR worktree)
Non-blocking notes
No correctness bugs found. Recommend merge (per split order #168 → #169 → this). |
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.
Summary
Follow-up B from splitting #168. Adds subquery-as-column support to the async query builder:
select_sub(builder, alias)andadd_select(alias, subquery)render a subquery as an aliased column —(subquery) AS alias— with bindings emitted in SELECT position (beforeWHERE).add_selectalso accepts a callable that builds the subquery on a fresh builder.table(name)sets the target table on a bare builder. This is the setter the*Through/BelongsToManywith-count query paths already reference (previously dangling), so it resolves those calls and backs the callable form ofadd_select.Existing string-based
select()is unchanged.Tests
tests/masoniteorm/query/grammars/test_select_sub_grammar.py— grammar-levelto_sql()/to_qmark()+ binding-order assertions across all 4 dialects (incl. MSSQLTOP n); covers builder-instance and callable forms and the non-builderTypeError.tests/masoniteorm/sqlite/builder/test_sqlite_select_sub.py— real sqlite-backed correlated-column reads plus thetable()setter.Gates
uv run pytest --ignore=tests/masoniteorm/postgres --cov→ 1808 passed / 7 skipped, coverage 78.88% (≥ fail_under 68).ruff check+ruff format --checkclean.select().Relationship to other PRs
Independent of #168 and #169 (correlated subqueries here use the 2-arg
where_columnalready onmain). Recommended overall order: #168 → #169 → this.