query

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpNone               = ""
	OpEqual              = "=="
	OpNotEqual           = "!="
	OpGreaterThan        = ">"
	OpGreaterThanOrEqual = ">="
	OpLessThan           = "<"
	OpLessThanOrEqual    = "<="
	OpIn                 = "IN"
)

Enumeration of possible operators.

View Source
const (
	DirNone       = ""
	DirAscending  = "asc"
	DirDescending = "desc"
)

Enumeration of possible order directions.

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction string

Direction defines a direction of ordering.

type Filter

type Filter struct {
	Operator  Operator
	FieldName string
	Operand   interface{}
}

Filter defines a single filter.

func NewFilter

func NewFilter(fieldName string, op Operator, operand interface{}) *Filter

NewFilter creates a new filter composed of the specified fieldName, op, and operand arguments.

type Operator

type Operator string

Operator defines a logical operator, eg. equal, greater than, or in.

type Option

type Option func(q *Query)

Option defines a way to pass build options to a new query.

func WithFilter

func WithFilter(filter *Filter) Option

WithFilter adds the specified filter to the query.

func WithFilterArgs

func WithFilterArgs(fieldName string, op Operator, operand interface{}) Option

WithFilterArgs builds a new Filter instance composed of the specified fieldName, op, and operand arguments, and adds it to the query.

func WithFilters

func WithFilters(filters ...*Filter) Option

WithFilters adds the specified filters to the query.

func WithOrder

func WithOrder(order *Order) Option

WithOrder adds the specified order to the query.

func WithOrderArgs

func WithOrderArgs(fieldName string, dir Direction) Option

WithOrderArgs builds a new Order instance composed of the specified fieldName and dir arguments, and adds it to the query.

func WithOrders

func WithOrders(orders ...*Order) Option

WithOrders adds the specified orders to the query.

func WithPage

func WithPage(page *Page) Option

WithPage sets the specified page to the query.

func WithPageArgs

func WithPageArgs(startIndex, capacity int) Option

WithPageArgs builds a new Page instance composed of the specified startIndex and capacity arguments, and adds it to the query.

type Order

type Order struct {
	Direction Direction
	FieldName string
}

Order defines a single order.

func NewOrder

func NewOrder(fieldName string, dir Direction) *Order

NewOrder creates an order composed of the specified fieldName and dir arguments.

type Page

type Page struct {
	StartIndex int
	Capacity   int
}

Page defines pagination configs in a collection of items.

func NewPage

func NewPage(startIndex, capacity int) *Page

NewPage creates a page composed of the specified startIndex and capacity arguments.

type Query

type Query struct {
	Filters []*Filter
	Orders  []*Order
	Page    *Page
}

Query defines a group of modifiers that can change the way resources are retrieved and displayed.

func NewQuery

func NewQuery(options ...Option) *Query

NewQuery creates a new query. Options can be specified to provide initial values to the query.

The following example shows how different types of options can be used:

NewQuery(
    WithFilters(
        NewFilter("FieldName1", OpEqual, "operand1"),
        NewFilter("FieldName2", OpNotEqual, "operand2"),
    ),
    WithOrder(NewOrder("FieldName1", DirAscending)),
    WithOrder(NewOrder("FieldName2", DirDescending)),
    WithPageArgs(10, 20),
)

func (*Query) AddFilters

func (q *Query) AddFilters(filters ...*Filter) *Query

AddFilters adds the specified filters to the query.

func (*Query) AddOrders

func (q *Query) AddOrders(orders ...*Order) *Query

AddOrders adds the specified orders to the query.

func (*Query) SetPage

func (q *Query) SetPage(page *Page) *Query

SetPage sets the specified page to the query. This will override the current page.

Jump to

Keyboard shortcuts

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