Skip to content

Expose target table and parameter clause context for plugin queries#4318

Open
mrmeku wants to merge 3 commits intosqlc-dev:mainfrom
mrmeku:claude/expose-update-delete-target-tables
Open

Expose target table and parameter clause context for plugin queries#4318
mrmeku wants to merge 3 commits intosqlc-dev:mainfrom
mrmeku:claude/expose-update-delete-target-tables

Conversation

@mrmeku
Copy link

@mrmeku mrmeku commented Feb 25, 2026

Summary

  • Adds update_table and delete_from_table fields to the Query message in protos/plugin/codegen.proto, matching the existing insert_into_table field
  • Adds ParameterContext enum and context field to the Parameter message, surfacing which SQL clause each parameter belongs to (SET, WHERE, LIMIT, OFFSET, FUNCTION_ARG, etc.)
  • Wires the compiler's already-resolved information through to the plugin interface — no new analysis logic needed

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 = 9 and delete_from_table = 10 on the Query message).

Parameter clause context

In internal/compiler/resolve.go, resolveCatalogRefs already switches on the parent AST node type to determine how to resolve each parameter. The second commit tags each Parameter with a ParameterContext enum value corresponding to that dispatch:

Parent type Context
*ast.ResTarget SET
*ast.A_Expr WHERE
*ast.BetweenExpr WHERE
*ast.In WHERE
*ast.FuncCall FUNCTION_ARG
*limitCount LIMIT
*limitOffset OFFSET
*ast.TypeCast, *ast.ParamRef, default UNSPECIFIED

This 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

  • Added UpdateAuthorBio UPDATE query to codegen_json endtoend test
  • Verified update_table is populated for UPDATE queries
  • Verified delete_from_table is populated for DELETE queries
  • Verified insert_into_table unchanged for INSERT queries
  • Verified all three target table fields are null for SELECT queries
  • Verified parameter context values: SET for UPDATE SET params, WHERE for WHERE params
  • Regenerated golden files for codegen_json and process_plugin_sqlc_gen_json
  • Full go test ./... passes

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>
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 🔧 golang labels Feb 25, 2026
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>
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Feb 26, 2026
@mrmeku mrmeku changed the title Expose target table for UPDATE and DELETE queries in plugin proto Expose target table and parameter clause context for plugin queries Feb 26, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files. 🔧 golang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Expose target table for UPDATE and DELETE queries in plugin proto

1 participant