Expose target table and parameter clause context for plugin queries#4318
Open
mrmeku wants to merge 3 commits intosqlc-dev:mainfrom
Open
Expose target table and parameter clause context for plugin queries#4318mrmeku wants to merge 3 commits intosqlc-dev:mainfrom
mrmeku wants to merge 3 commits intosqlc-dev:mainfrom
Conversation
Add update_table and delete_from_table fields to the Query message in the plugin codegen proto, matching the existing insert_into_table field. The compiler already resolves the target table for UPDATE and DELETE queries internally; this change wires that information through to plugins. Closes sqlc-dev#4317 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Surface the AST clause context (SET, WHERE, LIMIT, OFFSET, etc.) for each query parameter through the plugin proto. The compiler already dispatches on parent node type to resolve parameters — this commit tags each Parameter with that context so plugins can distinguish e.g. WHERE params from SET params without reparsing query text. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update the golden file for the process plugin test to include the new parameter context field values. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mrmeku
added a commit
to mrmeku/plugin-sdk-go
that referenced
this pull request
Feb 26, 2026
Sync codegen.pb.go with sqlc-dev/sqlc#4318 which exposes: - ParameterContext enum (SET, VALUES, WHERE, HAVING, FUNCTION_ARG, LIMIT, OFFSET) - Parameter.context field (field 3) - Query.update_table field (field 9) - Query.delete_from_table field (field 10)
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
update_tableanddelete_from_tablefields to theQuerymessage inprotos/plugin/codegen.proto, matching the existinginsert_into_tablefieldParameterContextenum andcontextfield to theParametermessage, surfacing which SQL clause each parameter belongs to (SET, WHERE, LIMIT, OFFSET, FUNCTION_ARG, etc.)Closes #4317
Details
Target tables for UPDATE/DELETE
The compiler already resolves the target table for UPDATE and DELETE queries internally (it needs to for column type resolution in SET clauses and WHERE conditions). The first commit simply exposes that information to plugins via two new proto fields (
update_table = 9anddelete_from_table = 10on theQuerymessage).Parameter clause context
In
internal/compiler/resolve.go,resolveCatalogRefsalready switches on the parent AST node type to determine how to resolve each parameter. The second commit tags eachParameterwith aParameterContextenum value corresponding to that dispatch:*ast.ResTargetSET*ast.A_ExprWHERE*ast.BetweenExprWHERE*ast.InWHERE*ast.FuncCallFUNCTION_ARG*limitCountLIMIT*limitOffsetOFFSET*ast.TypeCast,*ast.ParamRef, defaultUNSPECIFIEDThis lets plugins distinguish WHERE params from SET params without reparsing
q.Text— which is especially valuable for audit-logging, row-level security, and change-data-capture plugins that need to reconstruct pre-mutation SELECT queries.Both changes are additive to protobuf (new fields default to zero/UNSPECIFIED) and have no impact on existing Go codegen output.
Test plan
UpdateAuthorBioUPDATE query to codegen_json endtoend testupdate_tableis populated for UPDATE queriesdelete_from_tableis populated for DELETE queriesinsert_into_tableunchanged for INSERT queriescontextvalues: SET for UPDATE SET params, WHERE for WHERE paramsgo test ./...passes