querycontext

package
v0.9.0-rc5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendSQLComment

func AppendSQLComment(ctx context.Context, sql string) string

AppendSQLComment 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.

func WithQueryContext

func WithQueryContext(ctx context.Context, qc QueryContext) context.Context

WithQueryContext attaches query context metadata to a Go context.

Types

type QueryContext

type QueryContext map[string]string

QueryContext 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.

func GetQueryContext

func GetQueryContext(ctx context.Context) QueryContext

GetQueryContext retrieves query context from a Go context. Returns nil if not set.

func (QueryContext) AsBigQueryLabels

func (qc QueryContext) AsBigQueryLabels() map[string]string

AsBigQueryLabels converts the query context to BigQuery-compatible job labels. Keys are lowercased and sanitized (non-alphanumeric/underscore/dash replaced with underscore). Keys and values are truncated to 63 characters.

func (QueryContext) FormatAsJSON

func (qc QueryContext) FormatAsJSON() string

FormatAsJSON returns the query context as a JSON string.

func (QueryContext) FormatAsSQLComment

func (qc QueryContext) FormatAsSQLComment() string

FormatAsSQLComment returns the query context as a SQL block comment suitable for appending to a query string: /* {"key":"value"} */

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL