Documentation
¶
Index ¶
- Variables
- func RegisterEntity(descriptor *EntityDescriptor) error
- type AnyOperator
- type CollectionOperator
- type Condition
- type EdgePredicate
- type EntityDescriptor
- func (this *EntityDescriptor) Aliases() []string
- func (this *EntityDescriptor) EdgePredicate(edgeName string) (EdgePredicate, error)
- func (this *EntityDescriptor) Entity() string
- func (this *EntityDescriptor) FieldType(field string) (reflect.Type, error)
- func (this *EntityDescriptor) MatchFieldType(field string, value any) (reflect.Type, error)
- func (this *EntityDescriptor) OrderByEdgeStep(edgeName string) (OrderByEdgeFn, error)
- type EntityDescriptorBuilder
- func (this *EntityDescriptorBuilder) Aliases(aliases ...string) *EntityDescriptorBuilder
- func (this *EntityDescriptorBuilder) Descriptor() *EntityDescriptor
- func (this *EntityDescriptorBuilder) Edge(name string, predicate EdgePredicate) *EntityDescriptorBuilder
- func (this *EntityDescriptorBuilder) Field(name string, field any) *EntityDescriptorBuilder
- func (this *EntityDescriptorBuilder) OrderByEdge(field string, stepFn OrderByEdgeFn) *EntityDescriptorBuilder
- type GenericPredicate
- type LogicalPredicateFn
- type NullOperator
- type Operator
- type Order
- type OrderByEdgeFn
- type OrderDirection
- type OrderOption
- type Predicate
- type SearchGraph
- type SearchNode
- type SearchOrder
- type SearchOrderItem
- func (this SearchOrderItem) Direction() OrderDirection
- func (this SearchOrderItem) Fields() (columnField string, subFields []string)
- func (this SearchOrderItem) ToOrderOption(entityName string, vErr *ft.ValidationErrors) OrderOption
- func (this SearchOrderItem) Validate(entityName string) *ft.ValidationErrorItem
- type StringOperator
Constants ¶
This section is empty.
Variables ¶
View Source
var AnyOperators = map[Operator]AnyOperator{ Equals: sql.FieldEQ, NotEquals: sql.FieldNEQ, GreaterThan: sql.FieldGT, GreaterEqual: sql.FieldGTE, LessThan: sql.FieldLT, LessEqual: sql.FieldLTE, }
View Source
var CollectionOperators = map[Operator]CollectionOperator{ In: sql.FieldIn[any], NotIn: sql.FieldNotIn[any], }
View Source
var NoopPredicate = func(*sql.Selector) {}
View Source
var NullOperators = map[Operator]NullOperator{ IsNotSet: sql.FieldIsNull, IsSet: sql.FieldNotNull, }
View Source
var StringOperators = map[Operator]StringOperator{ Contains: sql.FieldContainsFold, NotContains: func(field string, value string) Predicate { return sql.NotPredicates(sql.FieldContainsFold(field, value)) }, StartsWith: sql.FieldHasPrefixFold, NotStartsWith: func(field string, value string) Predicate { return sql.NotPredicates(sql.FieldHasPrefixFold(field, value)) }, EndsWith: sql.FieldHasSuffixFold, NotEndsWith: func(field string, value string) Predicate { return sql.NotPredicates(sql.FieldHasSuffixFold(field, value)) }, }
Functions ¶
func RegisterEntity ¶
func RegisterEntity(descriptor *EntityDescriptor) error
Types ¶
type AnyOperator ¶
type CollectionOperator ¶
type Condition ¶
type Condition []any
Condition expression is made of at least 3 parts: 1. Field: the field to search 2. Operator: the operator to use, it must be appropriate with the value type 3. Value: the value to search for 3,4,5,6: Values for collection operators
Eg: ["name", "*", "nikki"], ["age", ">", "30"], ["age", "in", "30", "40", "50"]
func (Condition) ToPredicate ¶
func (this Condition) ToPredicate(entityName string) (Predicate, ft.ValidationErrors)
ToPredicate converts a condition expression to a Predicate instance. Examples:
["first_name", "contains", "nikki"] => sql.FieldContainsFold(entUser.FieldFirstName, "nikki") ["age", ">", "30"] => sql.FieldGT(entUser.FieldAge, "30")
func (Condition) Validate ¶
func (this Condition) Validate() ft.ValidationErrors
type EdgePredicate ¶
func ToEdgePredicate ¶
func ToEdgePredicate[ TParam ~Predicate, TReturn ~Predicate, ](sourceFn GenericPredicate[TParam, TReturn]) EdgePredicate
type EntityDescriptor ¶
type EntityDescriptor struct {
EntityAliases []string
Edges map[string]EdgePredicate
Fields map[string]reflect.Type
OrderByEdge map[string]OrderByEdgeFn
}
func GetEntity ¶
func GetEntity(entity string) (*EntityDescriptor, bool)
func (*EntityDescriptor) Aliases ¶
func (this *EntityDescriptor) Aliases() []string
func (*EntityDescriptor) EdgePredicate ¶
func (this *EntityDescriptor) EdgePredicate(edgeName string) (EdgePredicate, error)
func (*EntityDescriptor) Entity ¶
func (this *EntityDescriptor) Entity() string
func (*EntityDescriptor) FieldType ¶
func (this *EntityDescriptor) FieldType(field string) (reflect.Type, error)
func (*EntityDescriptor) MatchFieldType ¶
func (*EntityDescriptor) OrderByEdgeStep ¶
func (this *EntityDescriptor) OrderByEdgeStep(edgeName string) (OrderByEdgeFn, error)
type EntityDescriptorBuilder ¶
type EntityDescriptorBuilder struct {
// contains filtered or unexported fields
}
func DescribeEntity ¶
func DescribeEntity(entity string) *EntityDescriptorBuilder
func (*EntityDescriptorBuilder) Aliases ¶
func (this *EntityDescriptorBuilder) Aliases(aliases ...string) *EntityDescriptorBuilder
func (*EntityDescriptorBuilder) Descriptor ¶
func (this *EntityDescriptorBuilder) Descriptor() *EntityDescriptor
func (*EntityDescriptorBuilder) Edge ¶
func (this *EntityDescriptorBuilder) Edge( name string, predicate EdgePredicate, ) *EntityDescriptorBuilder
func (*EntityDescriptorBuilder) Field ¶
func (this *EntityDescriptorBuilder) Field(name string, field any) *EntityDescriptorBuilder
func (*EntityDescriptorBuilder) OrderByEdge ¶
func (this *EntityDescriptorBuilder) OrderByEdge( field string, stepFn OrderByEdgeFn, ) *EntityDescriptorBuilder
type GenericPredicate ¶
type LogicalPredicateFn ¶
type NullOperator ¶
type Operator ¶
type Operator = string
const ( // Basic operators Equals Operator = "=" NotEquals Operator = "!=" GreaterThan Operator = ">" GreaterEqual Operator = ">=" LessThan Operator = "<" LessEqual Operator = "<=" // Text search operators Contains Operator = "*" NotContains Operator = "!*" StartsWith Operator = "^" NotStartsWith Operator = "!^" EndsWith Operator = "$" NotEndsWith Operator = "!$" // Container operators In Operator = "in" NotIn Operator = "not_in" // Null operators IsSet Operator = "is_set" IsNotSet Operator = "not_set" )
type Order ¶
type Order = OrderOption // Alias for backward compatibility
type OrderByEdgeFn ¶
type OrderDirection ¶
type OrderDirection string
const ( Asc OrderDirection = "asc" Desc OrderDirection = "desc" )
type OrderOption ¶
type SearchGraph ¶
type SearchGraph struct {
Condition *Condition `json:"if,omitempty"`
And []SearchNode `json:"and,omitempty"`
Or []SearchNode `json:"or,omitempty"`
Order SearchOrder `json:"order,omitempty"`
}
func (SearchGraph) ToPredicate ¶
func (this SearchGraph) ToPredicate(entityName string) (Predicate, ft.ValidationErrors)
type SearchNode ¶
type SearchNode struct {
Condition *Condition `json:"if,omitempty"`
And []SearchNode `json:"and,omitempty"`
Or []SearchNode `json:"or,omitempty"`
}
SearchNode represents a complex search criteria, its fields are mutually exclusive, which means only one field can be set at a time, the precedence is: Condition > NotCondition > And > Or
func (SearchNode) ToPredicate ¶
func (this SearchNode) ToPredicate(entityName string) (Predicate, ft.ValidationErrors)
type SearchOrder ¶
type SearchOrder []SearchOrderItem
func (SearchOrder) ToOrderOptions ¶
func (this SearchOrder) ToOrderOptions(entityName string) ([]OrderOption, ft.ValidationErrors)
func (SearchOrder) Validate ¶
func (this SearchOrder) Validate(entityName string) ft.ValidationErrors
type SearchOrderItem ¶
type SearchOrderItem []string
func (SearchOrderItem) Direction ¶
func (this SearchOrderItem) Direction() OrderDirection
func (SearchOrderItem) Fields ¶
func (this SearchOrderItem) Fields() (columnField string, subFields []string)
func (SearchOrderItem) ToOrderOption ¶
func (this SearchOrderItem) ToOrderOption(entityName string, vErr *ft.ValidationErrors) OrderOption
func (SearchOrderItem) Validate ¶
func (this SearchOrderItem) Validate(entityName string) *ft.ValidationErrorItem
type StringOperator ¶
Click to show internal directories.
Click to hide internal directories.