orm

package
v0.0.0-...-c78e9a6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: LGPL-2.1 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CollectionOperators = map[Operator]CollectionOperator{
	In:    sql.FieldIn[any],
	NotIn: sql.FieldNotIn[any],
}
View Source
var NoopPredicate = func(*sql.Selector) {}

Functions

func RegisterEntity

func RegisterEntity(descriptor *EntityDescriptor) error

Types

type AnyOperator

type AnyOperator = func(string, any) Predicate

type CollectionOperator

type CollectionOperator = func(string, ...any) Predicate

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 NewCondition

func NewCondition(field string, operator Operator, values ...any) Condition

func (Condition) Field

func (this Condition) Field() string

func (Condition) Operator

func (this Condition) Operator() Operator

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

func (Condition) Value

func (this Condition) Value() any

func (Condition) Values

func (this Condition) Values() []any

type EdgePredicate

type EdgePredicate = func(Predicate) Predicate

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 (this *EntityDescriptor) MatchFieldType(field string, value any) (reflect.Type, error)

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 GenericPredicate[TParam ~Predicate, TReturn ~Predicate] = func(...TParam) TReturn

type LogicalPredicateFn

type LogicalPredicateFn func(predicates ...Predicate) Predicate

type NullOperator

type NullOperator = func(string) Predicate

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 OrderByEdgeFn func() *sqlgraph.Step

type OrderDirection

type OrderDirection string
const (
	Asc  OrderDirection = "asc"
	Desc OrderDirection = "desc"
)

type OrderOption

type OrderOption = func(*sql.Selector)

type Predicate

type Predicate = func(*sql.Selector)

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

type StringOperator = func(string, string) Predicate

Jump to

Keyboard shortcuts

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