Documentation ¶
Index ¶
- Constants
- func New(logger logr.Logger, ent *db.Client) persistence.Service
- type Filter
- func (f *Filter[Q, O, P]) AddDateRange(column string, r *timerange.Range)
- func (f *Filter[Q, O, P]) Apply() (page, whole Q)
- func (f *Filter[Q, O, P]) Equals(column string, value any)
- func (f *Filter[Q, O, P]) In(column string, values []any)
- func (f *Filter[Q, O, P]) OrderBy(sort persistence.Sort)
- func (f *Filter[Q, O, P]) Page(limit, offset int)
- type OrderOption
- type Predicate
- type Querier
- type SortableField
- type SortableFields
Constants ¶
const ( DefaultPageSize int = 20 MaxPageSize int = 50_000 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Filter ¶
type Filter[Q Querier[P, O, Q], O OrderOption, P Predicate] struct { // contains filtered or unexported fields }
Filter provides a mechanism to filter, order and paginate using Ent queries. Invoke the Apply method last to apply the remaining filters.
func NewFilter ¶
func NewFilter[Q Querier[P, O, Q], O OrderOption, P Predicate](query Q, sf SortableFields) *Filter[Q, O, P]
NewFilter returns a new Filter. It panics if orderingFields is empty.
func (*Filter[Q, O, P]) AddDateRange ¶
func (*Filter[Q, O, P]) Apply ¶
func (f *Filter[Q, O, P]) Apply() (page, whole Q)
Apply filters, returning queriers of the filtered subset and the page.
func (*Filter[Q, O, P]) Equals ¶
Equals adds a filter on column being equal to value. If value implements the validator interface, value is validated before the filter is added.
func (*Filter[Q, O, P]) In ¶
In adds a filter on column being equal to one of the given values. Each element in values that implements validator is validated before being added to the list of filter values.
func (*Filter[Q, O, P]) OrderBy ¶
func (f *Filter[Q, O, P]) OrderBy(sort persistence.Sort)
OrderBy sets the query sort order.
func (*Filter[Q, O, P]) Page ¶
Page sets the query limit and offset criteria.
The actual query limit will be set to a value between one and MaxPageSize based on the input limit (x) as follows: (x < 0) -> MaxPageSize (x == 0) -> DefaultPageSize (0 < x < MaxPageSize) -> x (x >= MaxPageSize) -> MaxPageSize
The actual query offset will be set based on the input offset (y) as follows: (y <= 0) -> 0 (y > 0) -> y
type OrderOption ¶
OrderOption (O) is the constraint for all Ent ordering options, e.g. batch.OrderOption, transfer.OrderOption and so on.
type Predicate ¶
Predicate (P) is the constraint for all Ent predicates, e.g. predicate.Batch, predicate.Transfer and so on.
type Querier ¶
type Querier[P Predicate, O OrderOption, Q any] interface { Where(ps ...P) Q Limit(int) Q Offset(int) Q Order(...O) Q Clone() Q }
Querier (Q) wraps queriers methods provided by Ent queries.
type SortableField ¶
type SortableFields ¶
type SortableFields map[string]SortableField
SortableFields maps column names to Ent type field names. Usage examples: batchOrderingFields, transferOrderingFields...
func (SortableFields) Columns ¶
func (sf SortableFields) Columns() []string
func (SortableFields) Default ¶
func (sf SortableFields) Default() SortableField
Default returns the default sort field.