Skip to content

[Feature] Add query metadata comments#4444

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

[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
@kyleconroy kyleconroy closed this May 15, 2026
@kyleconroy
Copy link
Copy Markdown
Collaborator

@DerekTBrown please open up an issue or a discussion with your feature request before submitting any code. Thanks.

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.

2 participants