filter

package
v0.0.0-...-418145e Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FilterQueryFieldConditions = "conditions"
	FilterQueryFieldAll        = "all"
)
View Source
const (
	FilterObjectTypeString  = "string"
	FilterObjectTypeNumber  = "number"
	FilterObjectTypeBoolean = "boolean"
)
View Source
const (
	FilterOpNotSet           = "ns"
	FilterOpContains         = "c"
	FilterOpNotContains      = "nc"
	FilterOpRegex            = "r"
	FilterOpEqual            = "eq"
	FilterOpNotEqual         = "ne"
	FilterOpIn               = "in"
	FilterOpNotIn            = "nin"
	FilterOpGreaterThan      = "gt"
	FilterOpLessThan         = "lt"
	FilterOpGreaterThanEqual = "gte"
	FilterOpLessThanEqual    = "lte"
	FilterOpSearch           = "s"
)
View Source
const (
	ASCENDING  = "asc"
	DESCENDING = "dsc"
)
View Source
const (
	SortQueryField = "sort"
)

Variables

View Source
var ErrorFilterInvalidOperation = NewFilterError("invalid operation")
View Source
var ErrorFilterUnableToParseQuery = NewFilterError("unable to parse query")

Functions

func FilterToQuery

func FilterToQuery(f IFilter) (q map[string]interface{}, err error)

FilterToQuery Translate entity.Filter to bson.M

func GetFilterAll

func GetFilterAll(getKeyFn func(key string) string) (res bool, err error)

GetFilterAll Get all

func GetFilterQuery

func GetFilterQuery(getKeyFn func(key string) string, opts ...GetFilterQueryOption) (q map[string]interface{}, err error)

GetFilterQuery Get bson.M

func GetSorts

func GetSorts(getKeyFn func(key string) string) (sorts []entity.Sort, err error)

GetSorts Get entity.Sort

func GetSortsOption

func GetSortsOption(getKeyFn func(key string) string) (sort bson.D, err error)

GetSortsOption Get entity.Sort

func MustGetFilterAll

func MustGetFilterAll(getKeyFn func(key string) string) (res bool)

func MustGetFilterQuery

func MustGetFilterQuery(getKeyFn func(key string) string, opts ...GetFilterQueryOption) (q map[string]interface{})

func MustGetSortOption

func MustGetSortOption(getKeyFn func(key string) string) (sort bson.D)

func NewFilterError

func NewFilterError(msg string) (err error)

func SortsToOption

func SortsToOption(sorts []entity.Sort) (sort bson.D, err error)

SortsToOption Translate entity.Sort to bson.D

Types

type Condition

type Condition struct {
	Key   string      `json:"key"`
	Op    string      `json:"op"`
	Value interface{} `json:"value"`
}

func (*Condition) GetKey

func (c *Condition) GetKey() (key string)

func (*Condition) GetOp

func (c *Condition) GetOp() (op string)

func (*Condition) GetValue

func (c *Condition) GetValue() (value interface{})

func (*Condition) SetKey

func (c *Condition) SetKey(key string)

func (*Condition) SetOp

func (c *Condition) SetOp(op string)

func (*Condition) SetValue

func (c *Condition) SetValue(value interface{})

type FieldSpecification

type FieldSpecification struct {
	TypeIsString bool
}

type Filter

type Filter struct {
	IsOr       bool         `form:"is_or" url:"is_or"`
	Conditions []*Condition `json:"conditions"`
}

func GetFilter

func GetFilter(getKeyFn func(key string) string, opts ...GetFilterQueryOption) (f *Filter, err error)

GetFilter Get entity.Filter

func (*Filter) GetConditions

func (f *Filter) GetConditions() (conditions []FilterCondition)

func (*Filter) GetIsOr

func (f *Filter) GetIsOr() (isOr bool)

func (*Filter) IsNil

func (f *Filter) IsNil() (ok bool)

func (*Filter) SetConditions

func (f *Filter) SetConditions(conditions []FilterCondition)

func (*Filter) SetIsOr

func (f *Filter) SetIsOr(isOr bool)

type FilterCondition

type FilterCondition interface {
	GetKey() (key string)
	SetKey(key string)
	GetOp() (op string)
	SetOp(op string)
	GetValue() (value interface{})
	SetValue(value interface{})
}

type GetFilterQueryOption

type GetFilterQueryOption = func(options *GetFilterQueryOptions)

func GetFilterQueryOptionWithTypeIsString

func GetFilterQueryOptionWithTypeIsString(fieldName string, fieldIsString bool) GetFilterQueryOption

force specify field type is string

type GetFilterQueryOptions

type GetFilterQueryOptions struct {
	SpecificationList map[string]*FieldSpecification
}

func (*GetFilterQueryOptions) FieldIsString

func (o *GetFilterQueryOptions) FieldIsString(fieldName string) bool

func (*GetFilterQueryOptions) FieldSpecification

func (o *GetFilterQueryOptions) FieldSpecification(fieldName string) *FieldSpecification

type IFilter

type IFilter interface {
	GetIsOr() (isOr bool)
	SetIsOr(isOr bool)
	GetConditions() (conditions []FilterCondition)
	SetConditions(conditions []FilterCondition)
	IsNil() (ok bool)
}

Jump to

Keyboard shortcuts

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