query

package
v0.0.0-...-7578c0e Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchIfDate

func MatchIfDate(dateValueStr string, filterValueStr string, filter FilterOption) (match bool, err error)

func MatchesFilters

func MatchesFilters(v interface{}, filterOptions []FilterOption) (bool, error)

func RequestedFields

func RequestedFields(fields []FieldsOption, resource string) map[string]bool

func SortFiltersByOperator

func SortFiltersByOperator(a []FilterOption)

func SplitFilters

func SplitFilters(options []FilterOption, keys map[string]bool) ([]FilterOption, []FilterOption)

func ValidateFieldsOptions

func ValidateFieldsOptions(fieldOptions []FieldsOption, supportedFields map[string]map[string]bool) errors2.APIErrors

func ValidateFilterOptions

func ValidateFilterOptions(fo []FilterOption, supportedFields map[string]bool) errors2.APIErrors

func ValidateListOptions

func ValidateListOptions(lo *ListOptions, supportedSorts map[string]bool, supportedFilters map[string]bool, supportedFields map[string]map[string]bool, paginationConfig *PaginationConfig) error

ValidateListOptions when supportedFields is nil, the fields options are disabled and will not be validated or used, same for pagination

func ValidatePagination

func ValidatePagination(pagination *Pagination, config *PaginationConfig) errors2.APIErrors

func ValidateRetrieveOptions

func ValidateRetrieveOptions(lo *RetrieveOptions, supportedFields map[string]map[string]bool) error

func ValidateSortOptions

func ValidateSortOptions(so []SortOption, supportedFields map[string]bool) errors2.APIErrors

Types

type FieldsOption

type FieldsOption struct {
	Resource string
	Fields   []string
}

func ParseFieldsOptions

func ParseFieldsOptions(values url.Values) []FieldsOption

type FilterLogicalOperator

type FilterLogicalOperator string
const (
	FilterLogicalOperatorTypeOR  FilterLogicalOperator = "or"
	FilterLogicalOperatorTypeAND FilterLogicalOperator = "and"
)

type FilterOperatorType

type FilterOperatorType string
const (
	FilterOperatorTypeEQ    FilterOperatorType = "eq"
	FilterOperatorTypeGT    FilterOperatorType = "gt"
	FilterOperatorTypeLT    FilterOperatorType = "lt"
	FilterOperatorTypeSince FilterOperatorType = "since"
	FilterOperatorTypeUntil FilterOperatorType = "until"
)

func (FilterOperatorType) Code

func (fot FilterOperatorType) Code() string

type FilterOption

type FilterOption struct {
	Column                []string
	Operator              FilterOperatorType
	Values                []string // Values are [ValuesLogicalOperator]ed together (only AND, OR, default OR)
	ValuesLogicalOperator FilterLogicalOperator
}

func ParseFilterOptions

func ParseFilterOptions(values url.Values) []FilterOption

func (FilterOption) String

func (fo FilterOption) String() string

type ListOptions

type ListOptions struct {
	Sorts      []SortOption
	Filters    []FilterOption
	Fields     []FieldsOption
	Pagination *Pagination
}

func GetListOptions

func GetListOptions(req *http.Request) *ListOptions

func NewOptions

func NewOptions(req *http.Request, sortsDefault map[string][]string, filtersDefault map[string][]string, fieldsDefault map[string][]string) *ListOptions

type Pagination

type Pagination struct {
	Limit  string
	Offset string

	ValidatedLimit  int
	ValidatedOffset int
}

func NewPagination

func NewPagination(limit, offset int) *Pagination

func ParsePagination

func ParsePagination(values url.Values) *Pagination

func (Pagination) GetStartEnd

func (p Pagination) GetStartEnd(totalCount int) (int, int)

type PaginationConfig

type PaginationConfig struct {
	MaxLimit     int
	DefaultLimit int
}

type RequestInfo

type RequestInfo struct {
	URL string
}

func ParseRequestInfo

func ParseRequestInfo(req *http.Request) *RequestInfo

type RetrieveOptions

type RetrieveOptions struct {
	Fields []FieldsOption
}

func GetRetrieveOptions

func GetRetrieveOptions(req *http.Request) *RetrieveOptions

type SQLConverter

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

func NewSQLConverter

func NewSQLConverter(dbDriverName string) *SQLConverter

NewSQLConverter converts query parameters into SQL language

func (*SQLConverter) AddOrderBy

func (c *SQLConverter) AddOrderBy(sortOptions []SortOption, q string) string

func (*SQLConverter) AddWhere

func (c *SQLConverter) AddWhere(filterOptions []FilterOption, q string, params []interface{}) (string, []interface{})

func (*SQLConverter) AppendOptionsToQuery

func (c *SQLConverter) AppendOptionsToQuery(o *ListOptions, q string, params []interface{}) (string, []interface{})

func (*SQLConverter) ConvertListOptionsToQuery

func (c *SQLConverter) ConvertListOptionsToQuery(lo *ListOptions, q string) (qOut string, params []interface{})

func (*SQLConverter) ConvertRetrieveOptionsToQuery

func (c *SQLConverter) ConvertRetrieveOptionsToQuery(ro *RetrieveOptions, q string) string

func (*SQLConverter) ReplaceStarSelect

func (c *SQLConverter) ReplaceStarSelect(fieldOptions []FieldsOption, q string) string

type SortOption

type SortOption struct {
	Column string
	IsASC  bool
}

func ParseSortOptions

func ParseSortOptions(values url.Values) []SortOption

Jump to

Keyboard shortcuts

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