query

package
v1.10.0-rc.9 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: Apache-2.0 Imports: 2 Imported by: 8

Documentation

Index

Constants

View Source
const (
	FILTER = "filter"
	SORT   = "sort"
	PAGE   = "page"
	ASC    = "ASC"
	DESC   = "DESC"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AND

type AND struct {
	Filters []Filter
}

func (*AND) Parse

func (f *AND) Parse(obj interface{}) (err error)

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func NewQueryBuilder

func NewQueryBuilder(visitor Visitor) *Builder

func (*Builder) BuildQuery

func (h *Builder) BuildQuery(q *Query) error

type EQ

type EQ struct {
	Key string
	Val interface{}
}

func (*EQ) Parse

func (f *EQ) Parse(obj interface{}) error

type Filter

type Filter interface {
	Parse(interface{}) error
}

func ParseFilter added in v1.10.1

func ParseFilter(obj interface{}) (Filter, error)

ParseFilter parses a filter struct using the visitor pattern returning a built Filter interface.

type IN

type IN struct {
	Key  string
	Vals []interface{}
}

func (*IN) Parse

func (f *IN) Parse(obj interface{}) error

type OR

type OR struct {
	Filters []Filter
}

func (*OR) Parse

func (f *OR) Parse(obj interface{}) (err error)

type Pagination

type Pagination struct {
	Limit int    `json:"limit"`
	Token string `json:"token,omitempty"`
}

type Query

type Query struct {
	QueryFields `json:",inline"`

	// derived from Filters
	Filter Filter
}

func (*Query) UnmarshalJSON

func (q *Query) UnmarshalJSON(data []byte) error

type QueryFields added in v1.9.0

type QueryFields struct {
	Filters map[string]interface{} `json:"filter"`
	Sort    []Sorting              `json:"sort"`
	Page    Pagination             `json:"page"`
}

used only for intermediate query value.

type Sorting

type Sorting struct {
	Key   string `json:"key"`
	Order string `json:"order,omitempty"`
}

type Visitor

type Visitor interface {
	// returns "equal" expression
	VisitEQ(*EQ) (string, error)
	// returns "in" expression
	VisitIN(*IN) (string, error)
	// returns "and" expression
	VisitAND(*AND) (string, error)
	// returns "or" expression
	VisitOR(*OR) (string, error)
	// receives concatenated filters and finalizes the native query
	Finalize(string, *Query) error
}

Jump to

Keyboard shortcuts

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