Skip to content

[Feature] Add query metadata comments - #4490

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

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

Conversation

@DerekTBrown

Copy link
Copy Markdown

Fixes #4489

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant