query

package
v0.0.0-...-d364ca2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package query parses and applies safe, resource-defined PostgreSQL queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(selectQuery *bun.SelectQuery, params Params, definition Definition) *bun.SelectQuery

func ApplyPagination

func ApplyPagination(selectQuery *bun.SelectQuery, params Params) *bun.SelectQuery

func EscapeLike

func EscapeLike(value string) string

Types

type Definition

type Definition struct {
	Filters        []Field
	Searchable     []string
	Sortable       []SortField
	DefaultSort    []Sort
	DefaultPage    int
	DefaultPerPage int
	MaxPerPage     int
}

func (Definition) Validate

func (definition Definition) Validate() error

func (Definition) WithDefaults

func (definition Definition) WithDefaults() Definition

type Field

type Field struct {
	Name      string
	Column    string
	Type      ValueType
	Operators []Operator
}

type Filter

type Filter struct {
	Field    Field
	Operator Operator
	Value    any
}

type Operator

type Operator string
const (
	Eq       Operator = "eq"
	Neq      Operator = "neq"
	Gt       Operator = "gt"
	Gte      Operator = "gte"
	Lt       Operator = "lt"
	Lte      Operator = "lte"
	In       Operator = "in"
	Contains Operator = "contains"
)

type Params

type Params struct {
	Page    int
	PerPage int
	Search  string
	Filters []Filter
	Sort    []Sort
}

func Parse

func Parse(values url.Values, definition Definition) (Params, error)

type Sort

type Sort struct {
	Field      string
	Column     string
	Descending bool
}

type SortField

type SortField struct {
	Name   string
	Column string
}

type ValueType

type ValueType string
const (
	String    ValueType = "string"
	Bool      ValueType = "bool"
	Int       ValueType = "int"
	Float     ValueType = "float"
	UUID      ValueType = "uuid"
	Date      ValueType = "date"
	Timestamp ValueType = "timestamp"
)

Jump to

Keyboard shortcuts

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