filterexpr

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind[M Msg, P any](msg M, binding *P, schema ResourceSchema) error

Bind parses the request filter & order_by and populates the query params struct accordingly.

Types

type FilterField

type FilterField struct {
	Expr   string
	Kind   ValueKind
	Ops    map[Op]string
	Setter SetterFunc
}

FilterField describes how a filter field maps to a params struct field and which operations are allowed.

type Msg

type Msg interface {
	GetFilter() string
	GetOrderBy() string
}

Msg wraps request DTOs that expose filter and order_by raw inputs.

type Op

type Op string

Op represents a supported comparison operation.

const (
	OpEQ  Op = "=="
	OpGTE Op = ">="
	OpLTE Op = "<="
	OpSW  Op = "startsWith"
	OpIN  Op = "in"
)

type OrderField

type OrderField struct {
	Expr  string
	Nulls string
}

OrderField maps an order key to a SQL expression.

type OrderSchema

type OrderSchema struct {
	DefaultPrimary     string
	DefaultPrimaryDesc bool
	FallbackKey        string
	FallbackDesc       bool
	Fields             map[string]OrderField
}

OrderSchema describes ordering defaults and whitelisted keys.

type ResourceSchema

type ResourceSchema struct {
	Filter map[string]FilterField
	Order  OrderSchema
}

ResourceSchema aggregates filtering and ordering rules for a resource.

type SetterFunc

type SetterFunc func(field reflect.Value, value any) error

SetterFunc allows custom assignment of literal values to struct fields.

type ValueKind

type ValueKind string

ValueKind describes the kind of literal value a field accepts.

const (
	KindString    ValueKind = "string"
	KindNumber    ValueKind = "number"
	KindTimestamp ValueKind = "timestamp"
)

Jump to

Keyboard shortcuts

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