filter

package
v0.3.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	StringValueType = "string_value"
	DoubleValueType = "double_value"
	IntValueType    = "int_value"
	BoolValueType   = "bool_value"
	ArrayValueType  = "array_value"
)

Constants for property value types

Variables

This section is empty.

Functions

This section is empty.

Types

type AndExpression

type AndExpression struct {
	Left  *Term   `@@`
	Right []*Term `("AND" @@)*`
}

type Comparison

type Comparison struct {
	Left     *PropertyRef `@@`
	Operator string       `@("=" | "!=" | "<>" | ">=" | "<=" | ">" | "<" | "LIKE" | "ILIKE" | "IN")`
	Right    *Value       `@@`
}

type ConditionResult

type ConditionResult struct {
	Condition string
	Args      []any
}

type EntityMappingFunctions

type EntityMappingFunctions interface {
	GetMLMDEntityType(restEntityType RestEntityType) EntityType
	GetPropertyDefinitionForRestEntity(restEntityType RestEntityType, propertyName string) PropertyDefinition
	IsChildEntity(entityType RestEntityType) bool
}

EntityMappingFunctions defines the interface for entity type mapping functions. This allows different packages (like catalog) to provide their own entity mappings.

type EntityPropertyMap

type EntityPropertyMap map[string]PropertyDefinition

EntityPropertyMap maps property names to their definitions for each entity type

type EntityType

type EntityType string

EntityType represents the type of entity for proper query building

const (
	EntityTypeContext   EntityType = "context"
	EntityTypeArtifact  EntityType = "artifact"
	EntityTypeExecution EntityType = "execution"
)

type EqualityExpander

type EqualityExpander interface {
	GetEqualityExpansion(restEntityType RestEntityType, propertyName string, value any) (likeArg any, useExpansion bool)
}

EqualityExpander is an optional interface that EntityMappingFunctions may implement to expand equality conditions.

type Expression

type Expression struct {
	Or *OrExpression `@@`
}

type FilterExpression

type FilterExpression struct {
	Left     *FilterExpression
	Right    *FilterExpression
	Operator string
	Property string
	Value    any
	IsLeaf   bool
}

func Parse

func Parse(input string) (*FilterExpression, error)

type OrExpression

type OrExpression struct {
	Left  *AndExpression   `@@`
	Right []*AndExpression `("OR" @@)*`
}

type PropertyDefinition

type PropertyDefinition struct {
	Location  PropertyLocation
	ValueType string
	Column    string

	RelatedEntityType RelatedEntityType
	RelatedProperty   string
	JoinTable         string
}

PropertyDefinition defines how a property should be handled

func GetPropertyDefinition

func GetPropertyDefinition(entityType EntityType, propertyName string) PropertyDefinition

GetPropertyDefinition returns the property definition for a given entity type and property name

type PropertyLocation

type PropertyLocation int

PropertyLocation indicates where a property is stored

const (
	EntityTable   PropertyLocation = iota // Property is a column in the main entity table
	PropertyTable                         // Property is stored in the entity's property table
	Custom                                // Property is a custom property in the property table
	RelatedEntity                         // Property is in a related entity (requires JOIN)
)

type PropertyRef

type PropertyRef struct {
	EscapedName string   `@EscapedIdent`
	Name        string   `| @Ident`
	Path        []string `("." @Ident)*`
	Type        string   `("." @("string_value" | "double_value" | "int_value" | "bool_value"))?`
}

type PropertyReference

type PropertyReference struct {
	Name         string
	IsCustom     bool
	ValueType    string
	ExplicitType string
	IsEscaped    bool
	PropertyDef  PropertyDefinition
}

type QueryBuilder

type QueryBuilder struct {
	// contains filtered or unexported fields
}

QueryBuilder builds GORM queries from filter expressions

func NewQueryBuilderForRestEntity

func NewQueryBuilderForRestEntity(restEntityType RestEntityType, mappingFuncs EntityMappingFunctions) *QueryBuilder

NewQueryBuilderForRestEntity creates a new query builder for the specified REST entity type. mappingFuncs must not be nil - callers must provide their own EntityMappingFunctions.

func (*QueryBuilder) BuildConditionString

func (qb *QueryBuilder) BuildConditionString(expr *FilterExpression) ConditionResult

BuildConditionString builds a SQL condition string from a FilterExpression.

func (*QueryBuilder) BuildPropertyReference

func (qb *QueryBuilder) BuildPropertyReference(expr *FilterExpression) *PropertyReference

BuildPropertyReference is exported for test use.

func (*QueryBuilder) BuildQuery

func (qb *QueryBuilder) BuildQuery(db *gorm.DB, expr *FilterExpression) *gorm.DB

func (*QueryBuilder) ConvertStateValue

func (qb *QueryBuilder) ConvertStateValue(propertyName string, value any) any

ConvertStateValue converts string state values to integers based on entity type

func (*QueryBuilder) EntityType

func (qb *QueryBuilder) EntityType() EntityType

EntityType returns the entity type for the query builder (exported for test use).

func (*QueryBuilder) RestEntityType

func (qb *QueryBuilder) RestEntityType() RestEntityType

RestEntityType returns the REST entity type for the query builder (exported for test use).

func (*QueryBuilder) TablePrefix

func (qb *QueryBuilder) TablePrefix() string

TablePrefix returns the table prefix for the query builder (exported for test use).

type RelatedEntityType

type RelatedEntityType string

RelatedEntityType indicates the type of related entity

const (
	RelatedEntityArtifact  RelatedEntityType = "artifact"
	RelatedEntityContext   RelatedEntityType = "context"
	RelatedEntityExecution RelatedEntityType = "execution"
)

type RestEntityType

type RestEntityType string

RestEntityType represents the specific REST API entity type

type SingleValue

type SingleValue struct {
	String  *string  `@String`
	Integer *int64   `| @Int`
	Float   *float64 `| @Float`
	Boolean *string  `| @("true" | "false" | "TRUE" | "FALSE")`
}

type Term

type Term struct {
	Group      *Expression `"(" @@ ")"`
	Comparison *Comparison `| @@`
}

type Value

type Value struct {
	String    *string    `@String`
	Integer   *int64     `| @Int`
	Float     *float64   `| @Float`
	Boolean   *string    `| @("true" | "false" | "TRUE" | "FALSE")`
	ValueList *ValueList `| @@`
}

type ValueList

type ValueList struct {
	Values []*SingleValue `"(" (@@  ("," @@)*)? ")"`
}

type WhereClause

type WhereClause struct {
	Expression *Expression `@@`
}

Jump to

Keyboard shortcuts

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