Documentation
¶
Index ¶
Constants ¶
View Source
const (
TypeUUID = "uuid" // UUID columns: eq/ne use value as-is; LIKE uses CAST(column AS TEXT)
)
Field type constants for AllowedFields
Variables ¶
View Source
var AllowedOperators = map[Operator]bool{ OperatorEQ: true, OperatorNE: true, OperatorGT: true, OperatorGTE: true, OperatorLT: true, OperatorLTE: true, OperatorLIKE: true, OperatorIN: true, OperatorNOTIN: true, }
AllowedOperators is a map of all allowed operators
Functions ¶
func ApplyFilters ¶
ApplyFilters applies filters to a GORM query
Types ¶
type Config ¶
type Config struct {
// AllowedFields maps field names to types: "string", "int", "time", TypeUUID, etc.
// Use TypeUUID for UUID columns so that LIKE is applied as CAST(column AS TEXT) LIKE ?.
// If empty, all fields are allowed.
AllowedFields map[string]string
// FieldMapping maps query parameter names to database column names
// If empty, field names are used as-is
FieldMapping map[string]string
// CustomValidators allows custom validation for specific fields
CustomValidators map[string]func(value string) error
}
Config holds filter configuration
type Filter ¶
type Filter struct {
Field string
Operator Operator
Value interface{}
FieldType string // from Config.AllowedFields; used e.g. for UUID LIKE cast
}
Filter represents a single filter condition
type Operator ¶
type Operator string
Operator represents a filter operator
const ( // OperatorEQ equals OperatorEQ Operator = "eq" // OperatorNE not equals OperatorNE Operator = "ne" // OperatorGT greater than OperatorGT Operator = "gt" // OperatorGTE greater than or equal OperatorGTE Operator = "gte" // OperatorLT less than OperatorLT Operator = "lt" // OperatorLTE less than or equal OperatorLTE Operator = "lte" // OperatorLIKE like (for strings) OperatorLIKE Operator = "like" // OperatorIN in (for arrays) OperatorIN Operator = "in" // OperatorNOTIN not in (for arrays) OperatorNOTIN Operator = "not_in" )
Click to show internal directories.
Click to hide internal directories.