feat(query-builder): expression args (col/lit/param/fn) + computed SELECT columns#1353
Merged
Merged
Conversation
…LECT columns Function-call arguments can now be column references (col), SQL literals (lit), explicit params (param), or nested function calls (fn) — not just auto-parameterized values. Adds .selectCall()/.selectExpr() so a function call can be a computed SELECT column over a base table, enabling per-row getter projections like: SELECT s.name, priv.secrets_get(secret_name => s.name, ...) AS v FROM priv.secrets s WHERE ... Positional vs named is just the arg container (array vs object); both accept expressions or plain values. Fully backward compatible (plain values still auto-parameterize). Param numbering stays correct via lazy expr thunks.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
Extends
@constructive-io/query-builderso function-call arguments are no longer limited to auto-parameterized values, and so a function call can be a computed SELECT column over a base table. This unlocks per-row getter projections (e.g. calling a scope-aware SQL getter once per row) that previously had to be hand-built as SQL template strings.Motivation: downstream (
constructive-dbknative handlers) hand-writes SQL like the secrets/config projection, branching on scope to pick a getter signature. With this, that becomes programmatic: build a named-arg object, conditionally includeowner_id/database_id, and the scope branch collapses.New expression helpers
A function-call arg (
FnArg) is nowExpr | SqlValue— plain values still auto-parameterize (fully backward compatible). Positional vs named is just the container shape (arrayvsobject); both accept expressions.New builder methods
Example — the scope-switch shape it enables
Implementation note
Expressions are lazy thunks
(alloc: ParamAllocator) => AstNodeevaluated duringbuild()in statement order, so$nnumbering stays correct even when a computed column and the WHERE clause both bind params (target list is allocated before WHERE). No string concatenation — everything is stillpg-astnodes deparsed viapgsql-deparser.Testing
pnpm test— 74/74 pass (67 existing + 7 new covering column-ref args,lit(null), mixed args, schema-qualifiedfn(), the computed-column scope-switch shape, and param-ordering). No existing behavior changed; the only internal change is_columns: string[]→_selectItems: SelectItem[].Link to Devin session: https://app.devin.ai/sessions/f4e36ac1d5854101838e6825df191c99
Requested by: @pyramation