{"modulePath":"github.com/getsynq/dwhsupport","version":"v0.28.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package querycontext\n\n## Functions\n\n```go\nfunc AppendSQLComment(ctx context.Context, sql string) string\n```\nAppendSQLComment appends a query context SQL comment to the given SQL string if query context is present in the context. Returns the original SQL unchanged if no query context is set.\n\n```go\nfunc AppendSQLLineComment(ctx context.Context, sql string) string\n```\nAppendSQLLineComment is AppendSQLComment with the context as a line comment (FormatAsSQLLineComment), for a statement whose parser rejects a trailing block comment. Prefer AppendSQLComment everywhere else: it is the form a query log reader looks for.\n\n```go\nfunc WithQueryContext(ctx context.Context, qc QueryContext) context.Context\n```\nWithQueryContext attaches query context metadata to a Go context.\n\n## Types\n\n```go\ntype QueryContext map[string]string\n```\nQueryContext holds key-value metadata to attach to database queries. It is used to track query provenance (e.g., originating from SYNQ, associated monitor or model) across all supported data warehouses.\n\n```go\nfunc GetQueryContext(ctx context.Context) QueryContext\n```\nGetQueryContext retrieves query context from a Go context. Returns nil if not set.\n\n```go\nfunc (qc QueryContext) FormatAsJSON() string\n```\nFormatAsJSON returns the query context as a JSON string.\n\n```go\nfunc (qc QueryContext) FormatAsSQLComment() string\n```\nFormatAsSQLComment returns the query context as a SQL block comment suitable for appending to a query string: /\\* {\"key\":\"value\"} \\*/\n\nThe JSON payload is sanitized to prevent SQL injection: any occurrence of the comment-close sequence \"\\*/\" is neutralised by replacing \"/\" with its JSON Unicode escape \"\\\\u002f\". The result is still valid, parseable JSON but cannot prematurely close the SQL block comment.\n\n```go\nfunc (qc QueryContext) FormatAsSQLLineComment() string\n```\nFormatAsSQLLineComment returns the query context as a SQL line comment on a line of its own, for a parser that rejects a block comment after the statement: \\\\n-- {\"key\":\"value\"}\n\nThe comment cannot end early: JSON escapes every line break in a key or a value, so the payload stays on one line.\n\n","path":"github.com/getsynq/dwhsupport/exec/querycontext","name":"querycontext","synopsis":"","isRedistributable":true}
