Skip to content

[Feature] Add query metadata comments#4444

Open
DerekTBrown wants to merge 1 commit into
sqlc-dev:mainfrom
DerekTBrown:codex/query-metadata-comments
Open

[Feature] Add query metadata comments#4444
DerekTBrown wants to merge 1 commit into
sqlc-dev:mainfrom
DerekTBrown:codex/query-metadata-comments

Conversation

@DerekTBrown
Copy link
Copy Markdown

@DerekTBrown DerekTBrown commented May 14, 2026

Problem Statement

Database monitoring and tracing tools (ex. Datadog) rely on metadata comments to trace SQL statements. I am looking for an easy way to inject these into SQLC-generated statements, improving traceability and auditability of SQL queries.

Proposal

This adds a query_comments config block that prepends generated SQL with structured metadata comments in either sqlcommenter or marginalia format based on the tags specified in the SQLC comment:

version: "2"
sql:
  - schema: "schema.sql"
    query_comments:
      enabled: true
      format: "sqlcommenter"
      tags:
        - name
        - filename

All generated SQL statements will then contain the tracking comment:

/*sqlc_name='GetAuthor',sqlc_filename='query.sql'*/
-- name: GetAuthor :one
SELECT id, name FROM authors WHERE id = $1

@DerekTBrown DerekTBrown changed the title [codex] Add query metadata comments [Feature] Add query metadata comments May 14, 2026
@DerekTBrown DerekTBrown marked this pull request as ready for review May 14, 2026 16:37
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.

1 participant