odata

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFilterNotToSpec is odata spec related error:
	ErrFilterNotToSpec = errors.New("odata filter parameter: not to odata spec")

	// ErrSchemaOperationNotSupportedForType is an eror with the schema specification
	// and would be better as a compile-time check if it was possible
	ErrSchemaOperationNotSupportedForType = errors.New("odata filter schema: operation not supported for type")

	ErrFilterOperationNotSupported = errors.New("odata filter parameter: operation not supported")
	ErrFilterTypeNotSupported      = errors.New("odata filter parameter: type not supported")

	ErrFilterInvalidValue = errors.New("odata filter parameter: value invalid")

	ErrFilterNonSchema               = errors.New("odata filter parameter: non schema")
	ErrFilterTypeIncompatible        = errors.New("odata filter parameter: type incompatible")
	ErrFilterValueConversionFailed   = errors.New("odata filter parameter: type conversation failed")
	ErrFilterValueModificationFailed = errors.New("odata filter parameter: value modification failed")
)

Functions

func MaxLengthValidator

func MaxLengthValidator(maxLength int) func(string) bool

MaxLengthValidator gets a helper ValueValidator. More can be added if generic enough.

func ToUpper

func ToUpper(s string) (string, bool)

ToUpper is helper ValueModifier. More can be added if generic enough.

Types

type DBQuery

type DBQuery string

DBQuery specifies the mapping between odata filters (and potentially other things) to a CMK repo operation.

const (
	WhereQuery DBQuery = ""     // Default, Therefore leave as empty string
	NoQuery    DBQuery = "None" // Client must handle
)

type Filter

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

Filter represents an OData filter.

func NewFilter

func NewFilter() *Filter

NewFilter creates a new instance of Filter.

func (*Filter) Add

func (fb *Filter) Add(field Query, value string) *Filter

Add adds an add filter to the Filter.

func (*Filter) And

func (fb *Filter) And() *Filter

And adds an and filter to the Filter.

func (*Filter) Contains

func (fb *Filter) Contains(field Query, value string) *Filter

Contains adds a contains filter to the Filter.

func (*Filter) Div

func (fb *Filter) Div(field Query, value string) *Filter

Div adds a divide filter to the Filter.

func (*Filter) DivBy

func (fb *Filter) DivBy(field Query, value string) *Filter

DivBy adds a divide by filter to the Filter.

func (*Filter) EndsWith

func (fb *Filter) EndsWith(field Query, value string) *Filter

EndsWith adds an endswith filter to the Filter.

func (*Filter) Eq

func (fb *Filter) Eq(field Query, value string) *Filter

Eq adds an equality filter to the Filter.

func (*Filter) Ge

func (fb *Filter) Ge(field Query, value string) *Filter

Ge adds a greater than or equal filter to the Filter.

func (*Filter) Group

func (fb *Filter) Group(groupFunc func(*Filter)) *Filter

Group groups filters together using the provided group function.

func (*Filter) Gt

func (fb *Filter) Gt(field Query, value string) *Filter

Gt adds a greater than filter to the Filter.

func (*Filter) Has

func (fb *Filter) Has(field Query, value string) *Filter

Has adds a has filter to the Filter.

func (*Filter) In

func (fb *Filter) In(field Query, values ...string) *Filter

In adds an in filter to the Filter.

func (*Filter) Le

func (fb *Filter) Le(field Query, value string) *Filter

Le adds a less than or equal filter to the Filter.

func (*Filter) Lt

func (fb *Filter) Lt(field Query, value string) *Filter

Lt adds a less than filter to the Filter.

func (*Filter) MatchesPattern

func (fb *Filter) MatchesPattern(field Query, pattern string) *Filter

MatchesPattern adds a matchesPattern filter to the Filter.

func (*Filter) Mod

func (fb *Filter) Mod(field Query, value string) *Filter

Mod adds a modulo filter to the Filter.

func (*Filter) Mul

func (fb *Filter) Mul(field Query, value string) *Filter

Mul adds a multiply filter to the Filter.

func (*Filter) Ne

func (fb *Filter) Ne(field Query, value string) *Filter

Ne adds a not equal filter to the Filter.

func (*Filter) Not

func (fb *Filter) Not() *Filter

Not adds a not filter to the Filter.

func (*Filter) Or

func (fb *Filter) Or() *Filter

Or adds an or filter to the Filter.

func (*Filter) StartsWith

func (fb *Filter) StartsWith(field Query, value string) *Filter

StartsWith adds a startswith filter to the Filter.

func (*Filter) String

func (fb *Filter) String() string

String returns the string representation of the Filter.

func (*Filter) Sub

func (fb *Filter) Sub(field Query, value string) *Filter

Sub adds a subtract filter to the Filter.

type FilterSchema

type FilterSchema struct {
	// We avoid a map here as it's unsorted and we probably want to keep our
	// sql deterministic.
	Entries []FilterSchemaEntry
}

FilterSchema contains all the FilterSchemaEntry associated with an endpoint.

type FilterSchemaEntry

type FilterSchemaEntry struct {
	FilterName     string
	FilterType     Type
	DBName         repo.QueryField
	DBQuery        DBQuery
	ValueModifier  func(string) (string, bool)
	ValueValidator func(string) bool
}

FilterSchemaEntry provides an endpoint specific specification for supported filters. FieldName and Type specify the odata filter names and types. DBName specifies the DB column name the filter maps to. DBQuery specifies what type of DB operation the odata filter should map to. ValueModifier and ValueValidator act on the filter field values provided on an endpoint call.

type Query

type Query string

Query represents an OData query.

func NewQuery

func NewQuery() *Query

NewQuery creates a new instance of Query.

func (*Query) Ceiling

func (q *Query) Ceiling(field string) Query

Ceiling returns the ceiling of the field in the Query.

func (*Query) Concat

func (q *Query) Concat(fields ...string) Query

Concat concatenates the provided fields in the Query.

func (*Query) Floor

func (q *Query) Floor(field string) Query

Floor returns the floor of the field in the Query.

func (*Query) IndexOf

func (q *Query) IndexOf(field, value string) Query

IndexOf returns the index of the value in the field in the Query.

func (*Query) Length

func (q *Query) Length(field string) Query

Length returns the length of the field in the Query.

func (*Query) Round

func (q *Query) Round(field string) Query

Round returns the round of the field in the Query.

func (*Query) String

func (q *Query) String() string

String returns the string representation of the Query.

func (*Query) Substring

func (q *Query) Substring(field string, pos int) Query

Substring returns the substring of the field starting at the specified position in the Query.

func (*Query) ToLower

func (q *Query) ToLower(field string) Query

ToLower converts the field to lowercase in the Query.

func (*Query) ToUpper

func (q *Query) ToUpper(field string) Query

ToUpper converts the field to uppercase in the Query.

func (*Query) Trim

func (q *Query) Trim(field string) Query

Trim removes leading and trailing spaces from the field in the Query.

type QueryOdataMapper

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

QueryOdataMapper maps odata fields and parameters to repo queries. It implements the repo.QueryMapper interface, which describes mapping of generic data to repo query parameters.

func NewQueryOdataMapper

func NewQueryOdataMapper(schema FilterSchema) *QueryOdataMapper

NewQueryOdataMapper returns a new QueryOdataMapper with the provided filter schema.

func (*QueryOdataMapper) GetPagination added in v0.3.0

func (mf *QueryOdataMapper) GetPagination() repo.Pagination

func (*QueryOdataMapper) GetPaging

func (mf *QueryOdataMapper) GetPaging() (*int, *int, *bool)

func (*QueryOdataMapper) GetQuery

func (mf *QueryOdataMapper) GetQuery(_ context.Context) *repo.Query

GetQuery is a QueryMapper interface function which returns a *repo.Query with where clauses added from the mapped odata filter parameter string.

func (*QueryOdataMapper) GetString

func (mf *QueryOdataMapper) GetString(field repo.QueryField) (string, error)

func (*QueryOdataMapper) GetUUID

func (mf *QueryOdataMapper) GetUUID(field repo.QueryField) (uuid.UUID, error)

GetUUID is a QueryMapper interface function which returns the uuid value for a specified query field, if it exists.

func (*QueryOdataMapper) ParseFilter

func (mf *QueryOdataMapper) ParseFilter(param *string) error

ParseFilter is used in the controller to parse the http odata parameter string.

func (*QueryOdataMapper) SetPaging

func (mf *QueryOdataMapper) SetPaging(skip, top *int, count *bool)

SetPaging is used in the controller to set the paging.

type Type

type Type string

Type specifies the odata type.

const (
	String Type = "STRING"
	Bool   Type = "BOOL"
	Int    Type = "INT"
	UUID   Type = "UUID"
)

Jump to

Keyboard shortcuts

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