Query

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OperatorIn                 Operator = "IN"
	OperatorNotIn              Operator = "NOT IN"
	OperatorLike               Operator = "LIKE"
	OperatorNotLike            Operator = "NOT LIKE"
	OperatorEqual              Operator = "="
	OperatorGreaterThan        Operator = ">"
	OperatorLessThan           Operator = "<"
	OperatorGreaterThanOrEqual Operator = ">="
	OperatorLessThanOrEqual    Operator = "<="
	OperatorNotEqual           Operator = "<>"
	OperatorJSONBContains      Operator = "@>"

	ConnectorAND Connector = " AND "
	ConnectorOR  Connector = " OR "
)
View Source
const DefaultPaginationLimit = 100

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	IDB            bun.IDB
	Model          any
	Pagination     *Pagination
	DefaultOrderBy []OrderBy
	Filterables    []Filterable
	Columns        []string
	Relations      []string
}

func (*Config) Validate

func (c *Config) Validate() error

type Connector

type Connector string

type Filter

type Filter struct {
	Column   string
	Operator Operator
	Value    any
}

func (*Filter) ApplyTo

func (f *Filter) ApplyTo(q *bun.SelectQuery) *bun.SelectQuery

func (*Filter) Validate

func (f *Filter) Validate() error

type FilterGroup

type FilterGroup struct {
	Filters   []Filter
	Connector Connector
}

func (*FilterGroup) ApplyTo

func (f *FilterGroup) ApplyTo(q *bun.SelectQuery) *bun.SelectQuery

type Filterable

type Filterable interface {
	ApplyTo(q *bun.SelectQuery) *bun.SelectQuery
}

Filterable is an interface for types that can be applied to a Bun query

type Operator

type Operator string

type OrderBy

type OrderBy struct {
	Column    string         `json:"column"`
	Direction OrderDirection `json:"direction"`
}

func (*OrderBy) String

func (ob *OrderBy) String() string

func (*OrderBy) Validate

func (ob *OrderBy) Validate() error

type OrderDirection

type OrderDirection string
const (
	OrderAscending  OrderDirection = "ASC"
	OrderDescending OrderDirection = "DESC"
)

type Pagination

type Pagination struct {
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
	Total  int `json:"total"`
}

func DefaultPagination added in v1.2.0

func DefaultPagination() *Pagination

DefaultPagination returns a Pagination with offset 0 and the default limit.

func (*Pagination) Validate

func (p *Pagination) Validate() error

type Query

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

func New

func New(ctx context.Context, conf *Config) (*Query, error)

func (*Query) Scan

func (q *Query) Scan(ctx context.Context) error

func (*Query) TotalCount

func (q *Query) TotalCount() int

type StringQueryInfo

type StringQueryInfo struct {
	Patterns   []string
	IsWildcard bool
	UseOR      bool
}

func (*StringQueryInfo) ToFilterable

func (info *StringQueryInfo) ToFilterable(col string) Filterable

Jump to

Keyboard shortcuts

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