Documentation
¶
Index ¶
- func ApplyFilters(filter *Filter, sortField string, sort apitype.Sort, limit int, ...) (*gorm.DB, error)
- func Compare(a, b Filterable, sortField string) bool
- func FilterableDBResult(dbClient *gorm.DB, filterOpts *FilterOptions, filterable Filterable) (*gorm.DB, error)
- type BQFilterResult
- type Filter
- type FilterItem
- type FilterOptions
- type Filterable
- type LinkOperator
- type Operator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyFilters ¶
func Compare ¶
func Compare(a, b Filterable, sortField string) bool
func FilterableDBResult ¶
func FilterableDBResult(dbClient *gorm.DB, filterOpts *FilterOptions, filterable Filterable) (*gorm.DB, error)
Types ¶
type BQFilterResult ¶
type BQFilterResult struct {
SQL string
Parameters []bigquery.QueryParameter
}
BQFilterResult contains the WHERE clause SQL and the BigQuery parameters to use with it. The Parameters slice contains bigquery.QueryParameter structs that can be directly assigned to a BigQuery query.
type Filter ¶
type Filter struct {
Items []FilterItem `json:"items"`
LinkOperator LinkOperator `json:"linkOperator"`
}
Filter is a collection of FilterItem, with a link operator. It is used to chain filters together, for example: where name contains aws and runs > 10.
func ExtractFilters ¶
TODO: merge with FilterOptionsFromRequest
func (Filter) Filter ¶
func (filters Filter) Filter(item Filterable) (bool, error)
Filter applies the selected filters to a filterable item.
func (Filter) Split ¶
Split extracts certain filter items into their own filter. Can be used for rare occurrences when filters need to be applied separately, i.e. as part of pre and post-processing.
func (Filter) ToBQStr ¶
func (filters Filter) ToBQStr(filterable Filterable, paramIndex *int) BQFilterResult
ToBQStr generates a parameterized BigQuery WHERE clause with safe parameter binding to prevent SQL injection. Returns the SQL string and BigQuery parameters ready to use.
type FilterItem ¶
type FilterItem struct {
Field string `json:"columnField"`
Not bool `json:"not"`
Operator Operator `json:"operatorValue"`
Value string `json:"value"`
}
FilterItem is an individual filter consisting of a field, operator, value and a not boolean that negates the operator. For example: name contains aws, or name not contains aws.
type FilterOptions ¶
type Filterable ¶
type Filterable interface {
GetFieldType(param string) apitype.ColumnType
GetStringValue(param string) (string, error)
GetNumericalValue(param string) (float64, error)
GetArrayValue(param string) ([]string, error)
}
Filterable interface is for anything that can be filtered, it needs to support querying the type and value of fields.
type LinkOperator ¶
type LinkOperator string
LinkOperator determines how to chain multiple filters together, 'AND' and 'OR' are supported.
const ( LinkOperatorAnd LinkOperator = "and" LinkOperatorOr LinkOperator = "or" )
type Operator ¶
type Operator string
Operator defines an operator used for filter items such as equals, contains, etc, as well as the arithmetic operators like ==, !=, >, etc.
const ( OperatorContains Operator = "contains" OperatorEquals Operator = "equals" OperatorStartsWith Operator = "starts with" OperatorEndsWith Operator = "ends with" OperatorHasEntry Operator = "has entry" OperatorHasEntryContaining Operator = "has entry containing" OperatorIsEmpty Operator = "is empty" OperatorIsNotEmpty Operator = "is not empty" OperatorArithmeticEquals Operator = "=" OperatorArithmeticNotEquals Operator = "!=" OperatorArithmeticGreaterThan Operator = ">" OperatorArithmeticGreaterThanOrEquals Operator = ">=" OperatorArithmeticLessThan Operator = "<" OperatorArithmeticLessThanOrEquals Operator = "<=" )