Documentation
¶
Index ¶
- Constants
- type ArrayOperator
- func (a *ArrayOperator) ToSQL(operator string, args []interface{}) (string, error)
- func (a *ArrayOperator) ToSQLAtPath(operator string, args []interface{}, path string) (string, error)
- func (a *ArrayOperator) ToSQLParam(operator string, args []interface{}, pc *params.ParamCollector) (string, error)
- func (a *ArrayOperator) ToSQLParamAtPath(operator string, args []interface{}, pc *params.ParamCollector, path string) (string, error)
- type ComparisonOperator
- type DataOperator
- type ExpressionParser
- type LogicalOperator
- type NumericOperator
- type OperatorConfig
- func (c *OperatorConfig) ArrayLengthFunc(expr string) string
- func (c *OperatorConfig) GetDialect() dialect.Dialect
- func (c *OperatorConfig) HasExpressionParser() bool
- func (c *OperatorConfig) HasParamExpressionParser() bool
- func (c *OperatorConfig) HasSchema() bool
- func (c *OperatorConfig) IsBigQuery() bool
- func (c *OperatorConfig) IsClickHouse() bool
- func (c *OperatorConfig) IsDuckDB() bool
- func (c *OperatorConfig) IsPostgreSQL() bool
- func (c *OperatorConfig) IsSpanner() bool
- func (c *OperatorConfig) ParseExpression(expr any, path string) (string, error)
- func (c *OperatorConfig) ParseExpressionParam(expr any, path string, pc *params.ParamCollector) (string, error)
- func (c *OperatorConfig) SetExpressionParser(parser ExpressionParser)
- func (c *OperatorConfig) SetParamExpressionParser(parser ParamExpressionParser)
- func (c *OperatorConfig) ValidateDialect(operator string) error
- type ParamExpressionParser
- type ProcessedValue
- type SchemaProvider
- type StringOperator
Constants ¶
const ( // ElemVar is the element variable name used in UNNEST subqueries. ElemVar = "elem" // ItemVar is the item variable name used in JSONLogic array operations. ItemVar = "item" // AccumulatorVar is the accumulator variable name used in reduce operations. AccumulatorVar = "accumulator" // CurrentVar is the current element variable name used in reduce operations. CurrentVar = "current" )
Element reference variable names used in array operations.
const ( // AggregateSUM is the SQL SUM aggregate function. AggregateSUM = "SUM" // AggregateMIN is the SQL MIN aggregate function. AggregateMIN = "MIN" // AggregateMAX is the SQL MAX aggregate function. AggregateMAX = "MAX" )
SQL aggregate function names.
const ( // OpVar is the variable access operator. OpVar = "var" // OpAnd is the logical AND operator. OpAnd = "and" // OpOr is the logical OR operator. OpOr = "or" // OpNot is the logical NOT operator. OpNot = "!" // OpDoubleBang is the boolean conversion operator. OpDoubleBang = "!!" // OpIf is the conditional operator. OpIf = "if" // OpMissing is the missing field check operator. OpMissing = "missing" // OpMissingSome is the missing some fields check operator. OpMissingSome = "missing_some" )
JSONLogic operator names.
const ( // OpAdd is the addition operator. OpAdd = "+" // OpSubtract is the subtraction operator. OpSubtract = "-" // OpMultiply is the multiplication operator. OpMultiply = "*" // OpDivide is the division operator. OpDivide = "/" // OpModulo is the modulo operator. OpModulo = "%" // OpMax is the maximum value operator. OpMax = "max" // OpMin is the minimum value operator. OpMin = "min" )
Arithmetic operator names.
const ( // OpEqual is the equality operator. OpEqual = "==" // OpStrictEqual is the strict equality operator. OpStrictEqual = "===" // OpNotEqual is the inequality operator. OpNotEqual = "!=" // OpStrictNotEqual is the strict inequality operator. OpStrictNotEqual = "!==" // OpGreaterThan is the greater than operator. OpGreaterThan = ">" // OpGreaterThanOrEqual is the greater than or equal operator. OpGreaterThanOrEqual = ">=" // OpLessThan is the less than operator. OpLessThan = "<" // OpLessThanOrEqual is the less than or equal operator. OpLessThanOrEqual = "<=" // OpIn is the membership/containment operator. OpIn = "in" )
Comparison operator names.
const ( // OpMap is the array map operator. OpMap = "map" // OpFilter is the array filter operator. OpFilter = "filter" // OpReduce is the array reduce operator. OpReduce = "reduce" // OpAll is the array all condition operator. OpAll = "all" // OpSome is the array some condition operator. OpSome = "some" // OpNone is the array none condition operator. OpNone = "none" // OpMerge is the array merge operator. OpMerge = "merge" )
Array operator names.
const ( // OpCat is the string concatenation operator. OpCat = "cat" // OpSubstr is the substring operator. OpSubstr = "substr" )
String operator names.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayOperator ¶
type ArrayOperator struct {
// contains filtered or unexported fields
}
ArrayOperator handles array operations like map, filter, reduce, all, some, none, merge.
func NewArrayOperator ¶
func NewArrayOperator(config *OperatorConfig) *ArrayOperator
NewArrayOperator creates a new ArrayOperator instance with optional config.
func (*ArrayOperator) ToSQL ¶
func (a *ArrayOperator) ToSQL(operator string, args []interface{}) (string, error)
ToSQL converts an array operation to SQL.
func (*ArrayOperator) ToSQLAtPath ¶ added in v1.0.10
func (a *ArrayOperator) ToSQLAtPath(operator string, args []interface{}, path string) (string, error)
ToSQLAtPath converts an array operation to SQL using the provided JSONPath as the operator context for nested expression error reporting.
func (*ArrayOperator) ToSQLParam ¶ added in v1.0.9
func (a *ArrayOperator) ToSQLParam(operator string, args []interface{}, pc *params.ParamCollector) (string, error)
ToSQLParam is the parameterized variant of ToSQL. Keep in sync.
func (*ArrayOperator) ToSQLParamAtPath ¶ added in v1.0.10
func (a *ArrayOperator) ToSQLParamAtPath(operator string, args []interface{}, pc *params.ParamCollector, path string) (string, error)
ToSQLParamAtPath is the parameterized variant of ToSQLAtPath. Keep in sync.
type ComparisonOperator ¶
type ComparisonOperator struct {
// contains filtered or unexported fields
}
ComparisonOperator handles comparison operators (==, ===, !=, !==, >, >=, <, <=).
func NewComparisonOperator ¶
func NewComparisonOperator(config *OperatorConfig) *ComparisonOperator
NewComparisonOperator creates a new comparison operator with optional config.
func (*ComparisonOperator) ToSQL ¶
func (c *ComparisonOperator) ToSQL(operator string, args []interface{}) (string, error)
ToSQL converts a comparison operator to SQL.
func (*ComparisonOperator) ToSQLParam ¶ added in v1.0.9
func (c *ComparisonOperator) ToSQLParam(operator string, args []interface{}, pc *params.ParamCollector) (string, error)
ToSQLParam is the parameterized variant of ToSQL. Keep in sync.
type DataOperator ¶
type DataOperator struct {
// contains filtered or unexported fields
}
DataOperator handles data access operators (var, missing, missing_some).
func NewDataOperator ¶
func NewDataOperator(config *OperatorConfig) *DataOperator
NewDataOperator creates a new data operator with optional config.
func (*DataOperator) ToSQL ¶
func (d *DataOperator) ToSQL(operator string, args []interface{}) (string, error)
ToSQL converts a data operator to SQL.
func (*DataOperator) ToSQLParam ¶ added in v1.0.9
func (d *DataOperator) ToSQLParam(operator string, args []interface{}, pc *params.ParamCollector) (string, error)
ToSQLParam is the parameterized variant of ToSQL. Keep in sync.
type ExpressionParser ¶ added in v1.0.4
ExpressionParser is a callback function type for parsing nested expressions. This allows operators to delegate expression parsing back to the parser, enabling support for custom operators in nested contexts. The path parameter is the JSONPath for error reporting.
type LogicalOperator ¶
type LogicalOperator struct {
// contains filtered or unexported fields
}
LogicalOperator handles logical operators (and, or, !, !!, if).
func NewLogicalOperator ¶
func NewLogicalOperator(config *OperatorConfig) *LogicalOperator
NewLogicalOperator creates a new logical operator with optional config.
func (*LogicalOperator) ToSQL ¶
func (l *LogicalOperator) ToSQL(operator string, args []interface{}) (string, error)
ToSQL converts a logical operator to SQL.
func (*LogicalOperator) ToSQLParam ¶ added in v1.0.9
func (l *LogicalOperator) ToSQLParam(operator string, args []interface{}, pc *params.ParamCollector) (string, error)
ToSQLParam is the parameterized variant of ToSQL. Keep in sync.
type NumericOperator ¶
type NumericOperator struct {
// contains filtered or unexported fields
}
NumericOperator handles numeric operations like +, -, *, /, %, max, min.
func NewNumericOperator ¶
func NewNumericOperator(config *OperatorConfig) *NumericOperator
NewNumericOperator creates a new NumericOperator instance with optional config.
func (*NumericOperator) ToSQL ¶
func (n *NumericOperator) ToSQL(operator string, args []interface{}) (string, error)
ToSQL converts a numeric operation to SQL.
func (*NumericOperator) ToSQLParam ¶ added in v1.0.9
func (n *NumericOperator) ToSQLParam(operator string, args []interface{}, pc *params.ParamCollector) (string, error)
ToSQLParam is the parameterized variant of ToSQL. Keep in sync.
type OperatorConfig ¶ added in v1.0.1
type OperatorConfig struct {
Schema SchemaProvider
Dialect dialect.Dialect
ExpressionParser ExpressionParser
ParamExpressionParser ParamExpressionParser
}
OperatorConfig holds shared configuration for all operators. By using a shared config object, all operators automatically see configuration changes without requiring individual SetSchema calls.
func NewOperatorConfig ¶ added in v1.0.1
func NewOperatorConfig(d dialect.Dialect, schema SchemaProvider) *OperatorConfig
NewOperatorConfig creates a new operator config with dialect and optional schema.
func (*OperatorConfig) ArrayLengthFunc ¶ added in v1.0.8
func (c *OperatorConfig) ArrayLengthFunc(expr string) string
ArrayLengthFunc returns the dialect-specific SQL function call for array length.
func (*OperatorConfig) GetDialect ¶ added in v1.0.2
func (c *OperatorConfig) GetDialect() dialect.Dialect
GetDialect returns the configured dialect.
func (*OperatorConfig) HasExpressionParser ¶ added in v1.0.4
func (c *OperatorConfig) HasExpressionParser() bool
HasExpressionParser returns true if an expression parser is configured.
func (*OperatorConfig) HasParamExpressionParser ¶ added in v1.0.9
func (c *OperatorConfig) HasParamExpressionParser() bool
HasParamExpressionParser returns true if a parameterized expression parser is configured.
func (*OperatorConfig) HasSchema ¶ added in v1.0.1
func (c *OperatorConfig) HasSchema() bool
HasSchema returns true if a schema is configured.
func (*OperatorConfig) IsBigQuery ¶ added in v1.0.2
func (c *OperatorConfig) IsBigQuery() bool
IsBigQuery returns true if the dialect is BigQuery.
func (*OperatorConfig) IsClickHouse ¶ added in v1.0.3
func (c *OperatorConfig) IsClickHouse() bool
IsClickHouse returns true if the dialect is ClickHouse.
func (*OperatorConfig) IsDuckDB ¶ added in v1.0.3
func (c *OperatorConfig) IsDuckDB() bool
IsDuckDB returns true if the dialect is DuckDB.
func (*OperatorConfig) IsPostgreSQL ¶ added in v1.0.3
func (c *OperatorConfig) IsPostgreSQL() bool
IsPostgreSQL returns true if the dialect is PostgreSQL.
func (*OperatorConfig) IsSpanner ¶ added in v1.0.2
func (c *OperatorConfig) IsSpanner() bool
IsSpanner returns true if the dialect is Spanner.
func (*OperatorConfig) ParseExpression ¶ added in v1.0.4
func (c *OperatorConfig) ParseExpression(expr any, path string) (string, error)
ParseExpression parses a nested expression using the configured parser. Returns an error if no parser is configured.
func (*OperatorConfig) ParseExpressionParam ¶ added in v1.0.9
func (c *OperatorConfig) ParseExpressionParam(expr any, path string, pc *params.ParamCollector) (string, error)
ParseExpressionParam parses a nested expression through the parameterized pipeline.
func (*OperatorConfig) SetExpressionParser ¶ added in v1.0.4
func (c *OperatorConfig) SetExpressionParser(parser ExpressionParser)
SetExpressionParser sets the callback for parsing nested expressions. This should be called by the parser after all operators are created.
func (*OperatorConfig) SetParamExpressionParser ¶ added in v1.0.9
func (c *OperatorConfig) SetParamExpressionParser(parser ParamExpressionParser)
SetParamExpressionParser sets the callback for parsing nested expressions in the parameterized pipeline. Called once in NewParser.
func (*OperatorConfig) ValidateDialect ¶ added in v1.0.2
func (c *OperatorConfig) ValidateDialect(operator string) error
ValidateDialect checks if the configured dialect is supported. Returns an error for unsupported or unspecified dialects. This should be called by operators to ensure dialect compatibility.
type ParamExpressionParser ¶ added in v1.0.9
ParamExpressionParser is the parameterized variant of ExpressionParser. It additionally receives a ParamCollector to register bind parameters.
type ProcessedValue ¶ added in v1.0.2
type ProcessedValue struct {
// Value is the string representation (either SQL expression or literal value)
Value string
// IsSQL indicates whether Value is a pre-processed SQL expression (true)
// or a literal value that may need quoting (false)
IsSQL bool
}
ProcessedValue represents a value that has been processed during transpilation. It carries metadata about whether the value is already SQL or a literal that needs quoting.
func LiteralResult ¶ added in v1.0.2
func LiteralResult(val string) ProcessedValue
LiteralResult creates a ProcessedValue marked as a literal. Use this when returning literal values that may need quoting.
func SQLResult ¶ added in v1.0.2
func SQLResult(sql string) ProcessedValue
SQLResult creates a ProcessedValue marked as SQL. Use this when returning generated SQL expressions from operators.
func (ProcessedValue) IsEmpty ¶ added in v1.0.2
func (p ProcessedValue) IsEmpty() bool
IsEmpty returns true if the value is empty.
func (ProcessedValue) String ¶ added in v1.0.2
func (p ProcessedValue) String() string
String returns the value as a string.
type SchemaProvider ¶ added in v1.0.1
type SchemaProvider interface {
// HasField checks if a field exists in the schema
HasField(fieldName string) bool
// GetFieldType returns the type of a field as a string, or empty string if not found
GetFieldType(fieldName string) string
// ValidateField checks if a field exists and returns an error if not
ValidateField(fieldName string) error
// IsArrayType checks if a field is of array type
IsArrayType(fieldName string) bool
// IsStringType checks if a field is of string type
IsStringType(fieldName string) bool
// IsNumericType checks if a field is of numeric type (integer or number)
IsNumericType(fieldName string) bool
// IsBooleanType checks if a field is of boolean type
IsBooleanType(fieldName string) bool
// IsEnumType checks if a field is of enum type
IsEnumType(fieldName string) bool
// GetAllowedValues returns the allowed values for an enum field
GetAllowedValues(fieldName string) []string
// ValidateEnumValue checks if a value is valid for an enum field
ValidateEnumValue(fieldName, value string) error
}
SchemaProvider provides schema information for field validation and type checking.
type StringOperator ¶
type StringOperator struct {
// contains filtered or unexported fields
}
StringOperator handles string operations like cat, substr.
func NewStringOperator ¶
func NewStringOperator(config *OperatorConfig) *StringOperator
NewStringOperator creates a new StringOperator instance with optional config.
func (*StringOperator) ToSQL ¶
func (s *StringOperator) ToSQL(operator string, args []interface{}) (string, error)
ToSQL converts a string operation to SQL.
func (*StringOperator) ToSQLParam ¶ added in v1.0.9
func (s *StringOperator) ToSQLParam(operator string, args []interface{}, pc *params.ParamCollector) (string, error)
ToSQLParam is the parameterized variant of ToSQL. Keep in sync.