odata

package
v0.12.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Eq = "eq"
	Ne = "ne"
	Gt = "gt"
	Ge = "ge"
	Lt = "lt"
	Le = "le"

	String Type = "STRING"
	Bool   Type = "BOOL"
	Int    Type = "INT"
	UUID   Type = "UUID"
)
View Source
const (
	None = ""
	And  = "and"
	Or   = "or"
)
View Source
const MaxOrderClauses = 10

Variables

View Source
var (
	ErrFilterNotToSpec             = errors.New("odata filter parameter: not to odata spec")
	ErrFilterOperationNotSupported = errors.New("odata filter parameter: operation not supported")
	ErrFilterInvalidValue          = errors.New("odata filter parameter: value invalid")
	ErrFilterTypeNotSupported      = errors.New("odata filter parameter: type not supported")
	ErrFilterValueConversionFailed = errors.New("odata filter parameter: type conversion failed")
	ErrFilterNonSchema             = errors.New("odata filter parameter: invalid db mapping")

	ErrOrderNotToSpec        = errors.New("odata orderby parameter: not to odata spec")
	ErrOrderInvalidDirection = errors.New("odata orderby parameter: direction not supported")
	ErrOrderNonSchema        = errors.New("odata orderby parameter: invalid db mapping")
)

Functions

func MaxLengthValidator

func MaxLengthValidator(maxLength int) func(string) bool

func ToUpper

func ToUpper(s string) string

Types

type Filter

type Filter struct {
	Items           []FilterItem
	FilterToRepoMap FilterToRepoMap
}

func NewFilter

func NewFilter(filter *string, filterToRepoMap FilterToRepoMap) (*Filter, error)

NewFilter does not support nested OData operations () If needed in the future the data structure needs to be swap from a slice to a tree As this is not a simple implementation it was skipped for now

func (*Filter) GetFieldValues added in v0.10.0

func (f *Filter) GetFieldValues(field repo.QueryField) ([]any, error)

func (*Filter) GetQuery added in v0.10.0

func (f *Filter) GetQuery() (*repo.Query, error)

type FilterItem added in v0.10.0

type FilterItem struct {
	Conditional string // "" for first, then "and" or "or" (connector before it)
	Field       string
	Operation   string
	Value       string
}

type FilterToRepoItem added in v0.10.0

type FilterToRepoItem struct {
	Type           Type
	DBName         repo.QueryField                                // used whenever there is a direct mapping to the DB
	DBQuery        func(query *repo.Query, value any) *repo.Query // used whenever odata maps to a query
	ValueModifier  RepoValueModifier
	ValueValidator RepoValueValidator
}

type FilterToRepoMap added in v0.10.0

type FilterToRepoMap map[string]FilterToRepoItem

type OData added in v0.10.0

type OData struct {
	// contains filtered or unexported fields
}

func New added in v0.10.0

func New(opts ...Option) *OData

func (*OData) GetFilter added in v0.10.0

func (o *OData) GetFilter() (repo.QueryFilter, error)

func (*OData) GetOrder added in v0.12.2

func (o *OData) GetOrder() (*repo.Query, []repo.OrderField, error)

func (*OData) GetPagination added in v0.10.0

func (o *OData) GetPagination() repo.Pagination

func (*OData) GetSearch added in v0.10.0

func (o *OData) GetSearch() (repo.QueryGetter, error)

type Option added in v0.10.0

type Option func(*OData)

func WithFilter added in v0.10.0

func WithFilter(filter *string, repoToFilterMap FilterToRepoMap) Option

func WithOrder added in v0.12.2

func WithOrder(orderby *string, orderMap OrderToRepoMap) Option

func WithOrderJoins added in v0.12.2

func WithOrderJoins(fields ...OrderJoinField) Option

func WithPagination added in v0.10.0

func WithPagination(skip *int, top *int, count *bool) Option

func WithSearch added in v0.10.0

func WithSearch(search *string, fields ...repo.QueryField) Option

func WithSearchJoins added in v0.10.0

func WithSearchJoins(fields ...SearchJoinField) Option

type Order added in v0.12.2

type Order struct {
	// contains filtered or unexported fields
}

func NewOrder added in v0.12.2

func NewOrder(orderby *string, m OrderToRepoMap, joinFields []OrderJoinField) (*Order, error)

func (*Order) GetOrder added in v0.12.2

func (o *Order) GetOrder() (*repo.Query, []repo.OrderField, error)

GetOrder returns a query holding the needed joins and the order fields. repo.Query.Merge drops OrderFields, so the caller must merge the joins and apply the order separately.

type OrderJoinField added in v0.12.2

type OrderJoinField struct {
	UserField string
	Column    string
	Join      repo.JoinCondition
}

type OrderToRepoItem added in v0.12.2

type OrderToRepoItem struct {
	DBName repo.QueryField
}

OrderToRepoItem maps a user-facing field to a DB column. Only mapped fields reach the repo, which puts the field into ORDER BY unquoted, so the map is the guard against injection.

type OrderToRepoMap added in v0.12.2

type OrderToRepoMap map[string]OrderToRepoItem

type RepoValueModifier added in v0.10.0

type RepoValueModifier func(string) string

type RepoValueValidator added in v0.10.0

type RepoValueValidator func(string) bool
type Search struct {
	Items      []SearchItem
	Fields     []repo.QueryField
	JoinFields []SearchJoinField
}

func NewSearch added in v0.10.0

func NewSearch(search *string, fields []repo.QueryField, joinFields []SearchJoinField) (*Search, error)

NewSearch does not support nested OData operations () This currently does not support nested operations () If needed in the future the data structure needs to be swap from a slice to a tree As this is not a simple implementation it was skipped for now

func (*Search) GetQuery added in v0.10.0

func (f *Search) GetQuery() (*repo.Query, error)

type SearchItem added in v0.10.0

type SearchItem struct {
	Conditional string // "" for first, then "and" or "or" (connector before it)
	Value       string
}

type SearchJoinField added in v0.10.0

type SearchJoinField struct {
	Column string
	Join   repo.JoinCondition
}

type Type

type Type string

Jump to

Keyboard shortcuts

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