query

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

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

func (*Cursor) IsBackward

func (c *Cursor) IsBackward() bool

func (*Cursor) IsEmpty

func (c *Cursor) IsEmpty() bool

func (*Cursor) IsForward

func (c *Cursor) IsForward() bool

type CursorPagination

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

func ParseCursorPagination

func ParseCursorPagination(raw string, sort *Sort, maxLimit int, hasAutoIncrementID bool) *CursorPagination

func (*CursorPagination) Apply

func (p *CursorPagination) Apply(q *Query)

func (*CursorPagination) Limit

func (p *CursorPagination) Limit() int

func (*CursorPagination) Mods

func (p *CursorPagination) Mods(tn string) []qm.QueryMod

DESC = high to low | latests to oldest | new to old ASC = low to high | oldest to latests | old to new

func (*CursorPagination) SQL

func (p *CursorPagination) SQL() string

type CursorPaginationInput

type CursorPaginationInput struct {
	Cursor *string
	Limit  int
}

type Dialect

type Dialect struct {
	UseIndexPlaceholders bool
}

type Direction

type Direction string

type Driver

type Driver int
const (
	MySQL Driver = iota
	Postgres
)

func (Driver) Dialect

func (d Driver) Dialect() *Dialect

type Filter

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

func ParseFilter

func ParseFilter(raw string, allowedColumns TableColumns) *Filter

func (*Filter) Apply

func (f *Filter) Apply(q *Query)

func (*Filter) Mods

func (f *Filter) Mods(tn string) []qm.QueryMod

func (*Filter) SQL

func (f *Filter) SQL(tn string, indexPlaceholders bool) (string, []any)

type FilterColumn

type FilterColumn struct {
	Column string
	Where  []*FilterColumnWhere
	Or     *FilterColumn
}

type FilterColumnWhere

type FilterColumnWhere struct {
	Operator Operator
	Value    any
}

type FilterMap

type FilterMap map[string]json.RawMessage

{"name": {"eq": "test", "or": "test3"}, "age": {"gte": 34, "lte": 65}, "status": {"in": ["active", "paused"]}, "or": {"name":{"eq": "test2"}}}

type FilterMapColumn

type FilterMapColumn map[Operator]json.RawMessage

type OffsetPagination

type OffsetPagination struct {
	Page  int
	Limit int
}

func ParseOffsetPagination

func ParseOffsetPagination(raw string, maxLimit int) *OffsetPagination

func (*OffsetPagination) Apply

func (p *OffsetPagination) Apply(q *Query)

func (*OffsetPagination) Mods

func (p *OffsetPagination) Mods() []qm.QueryMod

func (*OffsetPagination) SQL

func (p *OffsetPagination) SQL() string

type Operator

type Operator string

func (Operator) AcceptValueKind

func (o Operator) AcceptValueKind(v reflect.Kind) bool

func (Operator) IsOr

func (o Operator) IsOr() bool

func (Operator) IsValid

func (o Operator) IsValid(v any) bool

func (Operator) SQL

func (o Operator) SQL(c string, v any) (string, any)

type PaginationResponse

type PaginationResponse struct {
	HasNextPage    bool   `json:"has_next_page"`
	NextPageCursor string `json:"next_page_cursor,omitempty"`
	HasPrevPage    bool   `json:"has_prev_page"`
	PrevPageCursor string `json:"prev_page_cursor,omitempty"`
}

func Paginate added in v1.1.1

func Paginate[T any](pt PaginationType, q *Query, d []*T) ([]*T, *PaginationResponse)

func PaginateCursorPagination

func PaginateCursorPagination[T any](p *CursorPagination, data []*T) ([]*T, *PaginationResponse)

func PaginateOffsetPagination

func PaginateOffsetPagination[T any](p *OffsetPagination, d []*T) ([]*T, *PaginationResponse)

type PaginationType added in v1.1.1

type PaginationType int
const (
	OffsetPaginationType PaginationType = iota
	CursorPaginationType
)

type Param

type Param struct {
	Value any
	// contains filtered or unexported fields
}

func ParseParam

func ParseParam(column string, value any) *Param

func (*Param) Apply

func (p *Param) Apply(q *Query)

func (*Param) Mods

func (p *Param) Mods(tn string) qm.QueryMod

func (*Param) SQL

func (p *Param) SQL(tn string) (string, any)

type Query

type Query struct {
	Filter           *Filter
	Sort             *Sort
	OffsetPagination *OffsetPagination
	CursorPagination *CursorPagination
	Relation         *Relation
	Param            *Param
	Search           *Search
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery(d Driver, mods ...QueryMod) *Query

func (*Query) BareMods

func (q *Query) BareMods(tn string) []qm.QueryMod

func (*Query) Mods

func (q *Query) Mods(tn string) []qm.QueryMod

func (*Query) SQL

func (q *Query) SQL(tn string) (string, []any)

type QueryMod

type QueryMod interface {
	Apply(q *Query)
}

type Relation

type Relation []string

["relation", "otherrelation"]

func ParseRelation

func ParseRelation(raw string) *Relation

func (*Relation) Apply

func (r *Relation) Apply(q *Query)

func (*Relation) Mods

func (r *Relation) Mods() []qm.QueryMod
type Search struct {
	// contains filtered or unexported fields
}

func ParseSearch

func ParseSearch(value string, columns []string) *Search

func (*Search) Apply

func (s *Search) Apply(q *Query)

func (*Search) Mods

func (s *Search) Mods(tn string) qm.QueryMod

func (*Search) SQL

func (s *Search) SQL(tn string) (string, any)

type Sort

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

func ParseSort

func ParseSort(raw string, allowedColumns TableColumns) *Sort

func (*Sort) Apply

func (s *Sort) Apply(q *Query)

func (*Sort) Mods

func (s *Sort) Mods(tn string) []qm.QueryMod

func (*Sort) SQL

func (s *Sort) SQL(tn string) string

func (*Sort) SetDefault

func (s *Sort) SetDefault(f func(o sql.Order) []SortColumn)

type SortColumn

type SortColumn struct {
	Column string
	Order  sql.Order
}

type SortColumnSlice

type SortColumnSlice []SortColumn

type TableColumns

type TableColumns map[string]bool

func (TableColumns) Has

func (c TableColumns) Has(column string) bool

Jump to

Keyboard shortcuts

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