entclient

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPageSize int = 20
	MaxPageSize     int = 50_000
)

Variables

This section is empty.

Functions

func New

func New(logger logr.Logger, ent *db.Client) persistence.Service

New returns a new ent client that implements the persistence service.

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 (f *Filter[Q, O, P]) AddDateRange(column string, r *timerange.Range)

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

func (f *Filter[Q, O, P]) Equals(column string, value any)

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

func (f *Filter[Q, O, P]) In(column string, values []any)

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

func (f *Filter[Q, O, P]) Page(limit, offset int)

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

type OrderOption interface {
	~func(s *sql.Selector)
}

OrderOption (O) is the constraint for all Ent ordering options, e.g. batch.OrderOption, transfer.OrderOption and so on.

type Predicate

type Predicate interface {
	~func(s *sql.Selector)
}

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 SortableField struct {
	Name    string
	Default bool
}

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.

Jump to

Keyboard shortcuts

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