listquery

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtoiDefault

func AtoiDefault(val string, def int) int

AtoiDefault converts a string to int and returns def on parse failure.

func MapPredicates

func MapPredicates[T any](predicates []Predicate, mapper func(Predicate) T) []T

MapPredicates projects parsed predicates into consumer-specific predicate types.

func ParsePredicateKey

func ParsePredicateKey(key string) (string, string)

ParsePredicateKey splits filter keys like "title__ilike".

func ToString

func ToString(v any) string

ToString converts common scalar values into string.

func ValuesFromAny

func ValuesFromAny(raw any) []string

ValuesFromAny normalizes scalar/array filter values into a string slice.

Types

type Options

type Options[T any] struct {
	Page       int
	PerPage    int
	SortBy     string
	SortDesc   bool
	Filters    map[string]any
	Predicates []T
	Search     string
}

Options projects Result into consumer-specific predicate types. The field layout intentionally mirrors admin and boot list option structs.

func ParseOptions

func ParseOptions[T any](c router.Context, defaultPage, defaultPerPage int, mapper func(Predicate) T) Options[T]

ParseOptions parses list query params and maps predicates into consumer-specific types.

type Predicate

type Predicate struct {
	Field    string
	Operator string
	Values   []string
}

Predicate describes a single parsed operator-aware filter.

func PredicatesFromFilters

func PredicatesFromFilters(filters map[string]any) []Predicate

PredicatesFromFilters converts a filter map into normalized predicates.

type Result

type Result struct {
	Page       int
	PerPage    int
	SortBy     string
	SortDesc   bool
	Search     string
	Filters    map[string]any
	Predicates []Predicate
}

Result captures normalized list query options.

func ParseContext

func ParseContext(c router.Context, defaultPage, defaultPerPage int) Result

ParseContext extracts list query options from a router context.

Jump to

Keyboard shortcuts

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