Documentation
¶
Overview ¶
Package params provides parameter collection and placeholder generation for parameterized SQL output from the jsonlogic2sql transpiler.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindQuotedPlaceholderRef ¶
func FindQuotedPlaceholderRef(sql string, params []QueryParam, style PlaceholderStyle) (string, bool)
FindQuotedPlaceholderRef scans SQL string literals and returns the first placeholder token found inside a quoted string, if any.
This helps catch custom operators that accidentally quote placeholders (e.g. "'@p1'"), which breaks bind semantics.
func ValidatePlaceholderRefs ¶
func ValidatePlaceholderRefs(sql string, params []QueryParam, style PlaceholderStyle) error
ValidatePlaceholderRefs is a best-effort safety guard that scans the final SQL for each collected placeholder using style-specific boundary patterns. It returns E350 ErrUnreferencedPlaceholder if any placeholder is not found, indicating a custom operator may have dropped an argument.
This is NOT a strict SQL token parser. It may produce false positives if a custom operator emits SQL containing placeholder-like text inside string literals (e.g., '@p1') or SQL comments (e.g., -- @p1, /* $1 */). In normal usage this does not occur because the parameterized pipeline replaces all user-originated literals with placeholders.
Types ¶
type ParamCollector ¶
type ParamCollector struct {
// contains filtered or unexported fields
}
ParamCollector accumulates bind parameters and generates placeholder tokens during parameterized SQL generation. It is created per-call and passed through method parameters to ensure thread-safety.
func NewParamCollector ¶
func NewParamCollector(style PlaceholderStyle) *ParamCollector
NewParamCollector creates a ParamCollector for the given placeholder style.
func (*ParamCollector) Add ¶
func (pc *ParamCollector) Add(value interface{}) string
Add registers a new bind parameter and returns the dialect-appropriate placeholder token to embed in the SQL string.
func (*ParamCollector) Count ¶
func (pc *ParamCollector) Count() int
Count returns the number of collected parameters.
func (*ParamCollector) Params ¶
func (pc *ParamCollector) Params() []QueryParam
Params returns the collected parameters in insertion order.
func (*ParamCollector) Style ¶
func (pc *ParamCollector) Style() PlaceholderStyle
Style returns the placeholder style used by this collector.
func (*ParamCollector) ValueForPlaceholder ¶
func (pc *ParamCollector) ValueForPlaceholder(placeholder string) (interface{}, bool)
ValueForPlaceholder returns the stored value for a given placeholder string. Returns the value and true if found, or nil and false otherwise. This allows callers to inspect the Go type of a parameterized value when the placeholder token alone is insufficient to determine semantics (e.g., distinguishing string containment from array membership in the "in" operator).
type PlaceholderStyle ¶
type PlaceholderStyle int
PlaceholderStyle controls the placeholder token format in generated SQL.
const ( // PlaceholderNamed uses @p1, @p2, ... (BigQuery, Spanner, ClickHouse). PlaceholderNamed PlaceholderStyle = iota // PlaceholderPositional uses $1, $2, ... (PostgreSQL, DuckDB). PlaceholderPositional // PlaceholderQuestion uses sequential ? placeholders. // Reserved for future opt-in; no dialect maps here by default. PlaceholderQuestion )
func StyleForDialect ¶
func StyleForDialect(d dialect.Dialect) PlaceholderStyle
StyleForDialect returns the default PlaceholderStyle for a SQL dialect.
type QueryParam ¶
type QueryParam struct {
Name string
Value interface{}
}
QueryParam represents a single bind parameter collected during parameterized transpilation.