Documentation
¶
Overview ¶
Package filter compiles the CEL filter expressions accepted by the list endpoints into an intermediate representation and renders that IR into SQL for each database driver. The schema of filterable memo and user fields lives here.
Layering: filter imports only third-party packages and internal. It must not import store, core, or server; the SQL drivers import filter, not the other way round.
Index ¶
- func AppendConditions(ctx context.Context, engine *Engine, filters []string, dialect DialectName, ...) error
- type Column
- type ComparisonCondition
- type ComparisonOperator
- type ComprehensionKind
- type Condition
- type ConstantCondition
- type ContainsPredicate
- type DialectName
- type ElementInCondition
- type EndsWithPredicate
- type Engine
- type EqualsPredicate
- type Field
- type FieldAccessorValue
- type FieldKind
- type FieldPredicateCondition
- type FieldRef
- type FieldType
- type FunctionValue
- type InCondition
- type ListComprehensionCondition
- type LiteralValue
- type LogicalCondition
- type LogicalOperator
- type NotCondition
- type PredicateExpr
- type Program
- type RegexCondition
- type RenderOptions
- type Schema
- type StartsWithPredicate
- type Statement
- type TextMatchCondition
- type TextMatchMode
- type ValueExpr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendConditions ¶
func AppendConditions(ctx context.Context, engine *Engine, filters []string, dialect DialectName, where *[]string, args *[]any) error
AppendConditions compiles the provided filters and appends the resulting SQL fragments and args.
Types ¶
type ComparisonCondition ¶
type ComparisonCondition struct {
Left ValueExpr
Operator ComparisonOperator
Right ValueExpr
}
ComparisonCondition represents a binary comparison.
type ComparisonOperator ¶
type ComparisonOperator string
ComparisonOperator lists supported comparison operators.
const ( CompareEq ComparisonOperator = "=" CompareNeq ComparisonOperator = "!=" CompareLt ComparisonOperator = "<" CompareLte ComparisonOperator = "<=" CompareGt ComparisonOperator = ">" CompareGte ComparisonOperator = ">=" )
type ComprehensionKind ¶
type ComprehensionKind string
ComprehensionKind enumerates the types of list comprehensions.
const ( ComprehensionExists ComprehensionKind = "exists" ComprehensionAll ComprehensionKind = "all" ComprehensionExistsOne ComprehensionKind = "exists_one" )
type Condition ¶
type Condition interface {
// contains filtered or unexported methods
}
Condition represents a boolean expression derived from the CEL filter.
type ConstantCondition ¶
type ConstantCondition struct {
Value bool
}
ConstantCondition captures a literal boolean outcome.
type ContainsPredicate ¶
type ContainsPredicate struct {
Substring string
}
ContainsPredicate represents t.contains("substring").
type DialectName ¶
type DialectName string
DialectName enumerates supported SQL dialects.
const ( DialectSQLite DialectName = "sqlite" DialectMySQL DialectName = "mysql" DialectPostgres DialectName = "postgres" )
type ElementInCondition ¶
ElementInCondition represents the CEL syntax `"value" in field`.
type EndsWithPredicate ¶
type EndsWithPredicate struct {
Suffix string
}
EndsWithPredicate represents t.endsWith("suffix").
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine parses CEL filters into a dialect-agnostic condition tree.
func DefaultAttachmentEngine ¶
DefaultAttachmentEngine returns the process-wide attachment filter engine.
func DefaultEngine ¶
DefaultEngine returns the process-wide memo filter engine.
func (*Engine) CompileToStatement ¶
func (e *Engine) CompileToStatement(ctx context.Context, filter string, opts RenderOptions) (Statement, error)
CompileToStatement compiles and renders the filter in a single step.
type EqualsPredicate ¶
type EqualsPredicate struct {
Value string
}
EqualsPredicate represents t == "value".
type Field ¶
type Field struct {
Name string
Kind FieldKind
Type FieldType
Column Column
JSONPath []string
AliasFor string
SupportsContains bool
Expressions map[DialectName]string
AllowedComparisonOps map[ComparisonOperator]bool
}
Field captures the schema metadata for an exposed CEL identifier.
type FieldAccessorValue ¶
FieldAccessorValue captures a CEL timestamp accessor on a field, such as created_ts.getMonth(). It renders to a dialect-specific date-part extraction.
type FieldKind ¶
type FieldKind string
FieldKind describes how a field is stored.
const ( FieldKindScalar FieldKind = "scalar" FieldKindBoolColumn FieldKind = "bool_column" FieldKindJSONBool FieldKind = "json_bool" // FieldKindJSONExists represents a boolean derived from the presence of a non-null JSON value. FieldKindJSONExists FieldKind = "json_exists" FieldKindJSONList FieldKind = "json_list" FieldKindVirtualAlias FieldKind = "virtual_alias" )
type FieldPredicateCondition ¶
type FieldPredicateCondition struct {
Field string
}
FieldPredicateCondition asserts that a field evaluates to true.
type FunctionValue ¶
FunctionValue captures simple function calls like size(tags).
type InCondition ¶
InCondition represents an IN predicate with literal list values.
type ListComprehensionCondition ¶
type ListComprehensionCondition struct {
Kind ComprehensionKind
Field string // The list field to iterate over (e.g., "tags")
IterVar string // The iteration variable name (e.g., "t")
Predicate PredicateExpr // The predicate to evaluate for each element
}
ListComprehensionCondition represents CEL macros like exists(), all(), filter().
type LiteralValue ¶
type LiteralValue struct {
Value interface{}
}
LiteralValue holds a literal scalar.
type LogicalCondition ¶
type LogicalCondition struct {
Operator LogicalOperator
Left Condition
Right Condition
}
LogicalCondition composes two conditions with a logical operator.
type LogicalOperator ¶
type LogicalOperator string
LogicalOperator enumerates the supported logical operators.
const ( LogicalAnd LogicalOperator = "AND" LogicalOr LogicalOperator = "OR" )
type NotCondition ¶
type NotCondition struct {
Expr Condition
}
NotCondition negates a child condition.
type PredicateExpr ¶
type PredicateExpr interface {
// contains filtered or unexported methods
}
PredicateExpr represents predicates used in comprehensions.
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program stores a compiled filter condition.
func (*Program) ConditionTree ¶
ConditionTree exposes the underlying condition tree.
type RegexCondition ¶
RegexCondition models field.matches("pattern") on a string field.
type RenderOptions ¶
type RenderOptions struct {
Dialect DialectName
PlaceholderOffset int
DisableNullChecks bool
}
RenderOptions configure SQL rendering.
type Schema ¶
Schema collects CEL environment options and field metadata.
func NewAttachmentSchema ¶
func NewAttachmentSchema() Schema
NewAttachmentSchema constructs the attachment filter schema and CEL environment.
func NewSchema ¶
func NewSchema() Schema
NewSchema constructs the memo filter schema and CEL environment.
type StartsWithPredicate ¶
type StartsWithPredicate struct {
Prefix string
}
StartsWithPredicate represents t.startsWith("prefix").
type TextMatchCondition ¶
type TextMatchCondition struct {
Field string
Mode TextMatchMode
Value string
}
TextMatchCondition models a case-insensitive LIKE match on a scalar string field (content.contains/startsWith/endsWith).
type TextMatchMode ¶
type TextMatchMode string
TextMatchMode enumerates LIKE-based string match modes.
const ( TextMatchContains TextMatchMode = "contains" TextMatchPrefix TextMatchMode = "prefix" TextMatchSuffix TextMatchMode = "suffix" )