Help us shape the future of Go! Take the 2026 Go Developer Survey

query

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: MIT Imports: 2 Imported by: 13

Documentation

Index

Constants

View Source
const (
	FILTER = "filter"
	SORT   = "sort"
	PAGE   = "pagination"
	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
}

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 {
	Filters map[string]interface{} `json:"filter"`
	Sort    []Sorting              `json:"sort"`
	Page    Pagination             `json:"page"`

	// derived from Filters
	Filter Filter
}

func (*Query) UnmarshalJSON

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

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