Documentation
¶
Index ¶
- Variables
- func ApplyToQuery[F Filter, Q EntQuery[Q, P], P Predicate](q Q, f *F, field string) Q
- func ContainsPattern(value string) string
- func EscapeLikePattern(value string) string
- func ReverseContainsPattern(like *string) *string
- func SelectPredicate[P ~func(*sql.Selector)](f Filter, field string) *P
- type EntQuery
- type Filter
- type FilterBoolean
- type FilterFloat
- type FilterInteger
- type FilterString
- func (f FilterString) IsEmpty() bool
- func (f *FilterString) LoFilterPredicate() func(value string, _ int) (bool, error)
- func (f *FilterString) Match(value string) (bool, error)
- func (f FilterString) Select(field string) func(*sql.Selector)
- func (f FilterString) SelectWhereExpr(field string, q *sqlbuilder.SelectBuilder) string
- func (f FilterString) Validate() error
- func (f FilterString) ValidateWithComplexity(maxDepth int) error
- type FilterTime
- type FilterTimeUnix
- type FilterULID
- type Predicate
Constants ¶
This section is empty.
Variables ¶
var ( ErrFilterMultipleOperators = errors.New("filter is invalid: multiple operators are set") ErrFilterComplexityExceeded = errors.New("filter complexity exceeds maximum allowed depth") ErrFilterFormatMismatch = errors.New("filter is invalid: format mismatch") ErrOperationNotSupported = errors.New("filter is invalid: operation not supported") )
Functions ¶
func ApplyToQuery ¶
ApplyToQuery applies a filter to an Ent query if the filter is non-nil and non-empty.
func ContainsPattern ¶
ContainsPattern builds a LIKE pattern for a literal contains-match.
func EscapeLikePattern ¶
EscapeLikePattern escapes SQL LIKE metacharacters using the package's escape character.
func ReverseContainsPattern ¶
ReverseContainsPattern extracts the plain value from a LIKE pattern produced by ContainsPattern (e.g. "%foo%" → "foo").
Types ¶
type Filter ¶
type Filter interface {
// Validate validates the filter.
Validate() error
// ValidateWithComplexity validates the complexity of the filter.
ValidateWithComplexity(maxDepth int) error
// Select converts the filter to an Ent selector predicate.
Select(field string) func(*sql.Selector)
// SelectWhereExpr converts the filter to a SQL WHERE expression.
SelectWhereExpr(field string, q *sqlbuilder.SelectBuilder) string
// IsEmpty returns true if the filter is empty.
IsEmpty() bool
}
Filter is a filter for a field.
type FilterBoolean ¶
type FilterBoolean struct {
Eq *bool `json:"$eq,omitempty"`
}
FilterBoolean is a filter for a boolean field.
func (FilterBoolean) IsEmpty ¶
func (f FilterBoolean) IsEmpty() bool
IsEmpty returns true if the filter is empty.
func (FilterBoolean) Select ¶
func (f FilterBoolean) Select(field string) func(*sql.Selector)
Select converts the filter to an Ent selector predicate.
func (FilterBoolean) SelectWhereExpr ¶
func (f FilterBoolean) SelectWhereExpr(field string, q *sqlbuilder.SelectBuilder) string
SelectWhereExpr converts the filter to a SQL WHERE expression.
func (FilterBoolean) Validate ¶
func (f FilterBoolean) Validate() error
Validate validates the filter.
func (FilterBoolean) ValidateWithComplexity ¶
func (f FilterBoolean) ValidateWithComplexity(maxDepth int) error
ValidateWithComplexity validates the filter complexity.
type FilterFloat ¶
type FilterFloat struct {
Eq *float64 `json:"$eq,omitempty"`
Ne *float64 `json:"$ne,omitempty"`
Gt *float64 `json:"$gt,omitempty"`
Gte *float64 `json:"$gte,omitempty"`
Lt *float64 `json:"$lt,omitempty"`
Lte *float64 `json:"$lte,omitempty"`
And *[]FilterFloat `json:"$and,omitempty"`
Or *[]FilterFloat `json:"$or,omitempty"`
}
FilterFloat is a filter for a float field.
func (FilterFloat) IsEmpty ¶
func (f FilterFloat) IsEmpty() bool
IsEmpty returns true if the filter is empty.
func (FilterFloat) Select ¶
func (f FilterFloat) Select(field string) func(*sql.Selector)
Select converts the filter to an Ent selector predicate.
func (FilterFloat) SelectWhereExpr ¶
func (f FilterFloat) SelectWhereExpr(field string, q *sqlbuilder.SelectBuilder) string
SelectWhereExpr converts the filter to a SQL WHERE expression.
func (FilterFloat) Validate ¶
func (f FilterFloat) Validate() error
func (FilterFloat) ValidateWithComplexity ¶
func (f FilterFloat) ValidateWithComplexity(maxDepth int) error
ValidateWithComplexity validates the filter complexity.
type FilterInteger ¶
type FilterInteger struct {
Eq *int `json:"$eq,omitempty"`
Ne *int `json:"$ne,omitempty"`
Gt *int `json:"$gt,omitempty"`
Gte *int `json:"$gte,omitempty"`
Lt *int `json:"$lt,omitempty"`
Lte *int `json:"$lte,omitempty"`
And *[]FilterInteger `json:"$and,omitempty"`
Or *[]FilterInteger `json:"$or,omitempty"`
}
FilterInteger is a filter for an integer field.
func (FilterInteger) IsEmpty ¶
func (f FilterInteger) IsEmpty() bool
IsEmpty returns true if the filter is empty.
func (FilterInteger) Select ¶
func (f FilterInteger) Select(field string) func(*sql.Selector)
Select converts the filter to an Ent selector predicate.
func (FilterInteger) SelectWhereExpr ¶
func (f FilterInteger) SelectWhereExpr(field string, q *sqlbuilder.SelectBuilder) string
SelectWhereExpr converts the filter to a SQL WHERE expression.
func (FilterInteger) Validate ¶
func (f FilterInteger) Validate() error
Validate validates the filter.
func (FilterInteger) ValidateWithComplexity ¶
func (f FilterInteger) ValidateWithComplexity(maxDepth int) error
ValidateWithComplexity validates the filter complexity.
type FilterString ¶
type FilterString struct {
Eq *string `json:"$eq,omitempty"`
Ne *string `json:"$ne,omitempty"`
Exists *bool `json:"$exists,omitempty"`
In *[]string `json:"$in,omitempty"`
Nin *[]string `json:"$nin,omitempty"`
Like *string `json:"$like,omitempty"`
Nlike *string `json:"$nlike,omitempty"`
Ilike *string `json:"$ilike,omitempty"`
Nilike *string `json:"$nilike,omitempty"`
Contains *string `json:"$contains,omitempty"`
Ncontains *string `json:"$ncontains,omitempty"`
Gt *string `json:"$gt,omitempty"`
Gte *string `json:"$gte,omitempty"`
Lt *string `json:"$lt,omitempty"`
Lte *string `json:"$lte,omitempty"`
And *[]FilterString `json:"$and,omitempty"`
Or *[]FilterString `json:"$or,omitempty"`
}
FilterString is a filter for a string field.
func (FilterString) IsEmpty ¶
func (f FilterString) IsEmpty() bool
IsEmpty returns true if the filter is empty.
func (*FilterString) LoFilterPredicate ¶
func (f *FilterString) LoFilterPredicate() func(value string, _ int) (bool, error)
LoFilterPredicate returns an lo.Filter-compatible predicate that evaluates the filter against a string field value.
func (*FilterString) Match ¶
func (f *FilterString) Match(value string) (bool, error)
Match reports whether the filter matches the given string value. A nil receiver and an empty filter match every value. Semantics mirror Select / SelectWhereExpr: Contains/Ncontains are case-insensitive; Like/Ilike treat the pattern as SQL LIKE (% and _ wildcards); Exists checks for a non-empty value.
func (FilterString) Select ¶
func (f FilterString) Select(field string) func(*sql.Selector)
Select converts the filter to an Ent selector predicate.
func (FilterString) SelectWhereExpr ¶
func (f FilterString) SelectWhereExpr(field string, q *sqlbuilder.SelectBuilder) string
SelectWhereExpr converts the filter to a SQL WHERE expression.
func (FilterString) Validate ¶
func (f FilterString) Validate() error
Validate validates the filter.
func (FilterString) ValidateWithComplexity ¶
func (f FilterString) ValidateWithComplexity(maxDepth int) error
ValidateWithComplexity validates the filter complexity.
type FilterTime ¶
type FilterTime struct {
Eq *time.Time `json:"$eq,omitempty"`
Exists *bool `json:"$exists,omitempty"`
Gt *time.Time `json:"$gt,omitempty"`
Gte *time.Time `json:"$gte,omitempty"`
Lt *time.Time `json:"$lt,omitempty"`
Lte *time.Time `json:"$lte,omitempty"`
And *[]FilterTime `json:"$and,omitempty"`
Or *[]FilterTime `json:"$or,omitempty"`
}
FilterTime is a filter for a time field.
func (FilterTime) IsEmpty ¶
func (f FilterTime) IsEmpty() bool
IsEmpty returns true if the filter is empty.
func (FilterTime) Select ¶
func (f FilterTime) Select(field string) func(*sql.Selector)
Select converts the filter to an Ent selector predicate.
func (FilterTime) SelectWhereExpr ¶
func (f FilterTime) SelectWhereExpr(field string, q *sqlbuilder.SelectBuilder) string
SelectWhereExpr converts the filter to a SQL WHERE expression.
func (FilterTime) ValidateWithComplexity ¶
func (f FilterTime) ValidateWithComplexity(maxDepth int) error
ValidateWithComplexity validates the filter complexity.
type FilterTimeUnix ¶
type FilterTimeUnix struct {
FilterTime
}
FilterTimeUnix is a filter for a time, but the generated SQL is using the unix timestamp in seconds.
func (FilterTimeUnix) Select ¶
func (f FilterTimeUnix) Select(field string) func(*sql.Selector)
Select converts the filter to an Ent selector predicate.
func (FilterTimeUnix) SelectWhereExpr ¶
func (f FilterTimeUnix) SelectWhereExpr(field string, q *sqlbuilder.SelectBuilder) string
SelectWhereExpr converts the filter to a SQL WHERE expression.
type FilterULID ¶
type FilterULID struct {
FilterString
And *[]FilterULID `json:"$and,omitempty"`
Or *[]FilterULID `json:"$or,omitempty"`
}
FilterULID is a filter for a string field.
func (FilterULID) IsEmpty ¶
func (f FilterULID) IsEmpty() bool
IsEmpty returns true if the filter is empty.
func (FilterULID) Select ¶
func (f FilterULID) Select(field string) func(*sql.Selector)
Select converts the filter to an Ent selector predicate.
func (FilterULID) SelectWhereExpr ¶
func (f FilterULID) SelectWhereExpr(field string, q *sqlbuilder.SelectBuilder) string
SelectWhereExpr converts the filter to a SQL WHERE expression.
func (FilterULID) ValidateWithComplexity ¶
func (f FilterULID) ValidateWithComplexity(maxDepth int) error
ValidateWithComplexity validates the filter complexity.