Documentation
¶
Index ¶
- Variables
- func MaxLengthValidator(maxLength int) func(string) bool
- func ToUpper(s string) (string, bool)
- type DBQuery
- type Filter
- func (fb *Filter) Add(field Query, value string) *Filter
- func (fb *Filter) And() *Filter
- func (fb *Filter) Contains(field Query, value string) *Filter
- func (fb *Filter) Div(field Query, value string) *Filter
- func (fb *Filter) DivBy(field Query, value string) *Filter
- func (fb *Filter) EndsWith(field Query, value string) *Filter
- func (fb *Filter) Eq(field Query, value string) *Filter
- func (fb *Filter) Ge(field Query, value string) *Filter
- func (fb *Filter) Group(groupFunc func(*Filter)) *Filter
- func (fb *Filter) Gt(field Query, value string) *Filter
- func (fb *Filter) Has(field Query, value string) *Filter
- func (fb *Filter) In(field Query, values ...string) *Filter
- func (fb *Filter) Le(field Query, value string) *Filter
- func (fb *Filter) Lt(field Query, value string) *Filter
- func (fb *Filter) MatchesPattern(field Query, pattern string) *Filter
- func (fb *Filter) Mod(field Query, value string) *Filter
- func (fb *Filter) Mul(field Query, value string) *Filter
- func (fb *Filter) Ne(field Query, value string) *Filter
- func (fb *Filter) Not() *Filter
- func (fb *Filter) Or() *Filter
- func (fb *Filter) StartsWith(field Query, value string) *Filter
- func (fb *Filter) String() string
- func (fb *Filter) Sub(field Query, value string) *Filter
- type FilterSchema
- type FilterSchemaEntry
- type Query
- func (q *Query) Ceiling(field string) Query
- func (q *Query) Concat(fields ...string) Query
- func (q *Query) Floor(field string) Query
- func (q *Query) IndexOf(field, value string) Query
- func (q *Query) Length(field string) Query
- func (q *Query) Round(field string) Query
- func (q *Query) String() string
- func (q *Query) Substring(field string, pos int) Query
- func (q *Query) ToLower(field string) Query
- func (q *Query) ToUpper(field string) Query
- func (q *Query) Trim(field string) Query
- type QueryOdataMapper
- func (mf *QueryOdataMapper) GetPagination() repo.Pagination
- func (mf *QueryOdataMapper) GetPaging() (*int, *int, *bool)
- func (mf *QueryOdataMapper) GetQuery(_ context.Context) *repo.Query
- func (mf *QueryOdataMapper) GetString(field repo.QueryField) (string, error)
- func (mf *QueryOdataMapper) GetUUID(field repo.QueryField) (uuid.UUID, error)
- func (mf *QueryOdataMapper) ParseFilter(param *string) error
- func (mf *QueryOdataMapper) SetPaging(skip, top *int, count *bool)
- type Type
Constants ¶
This section is empty.
Variables ¶
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 ¶
MaxLengthValidator gets a helper ValueValidator. 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.
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter represents an OData filter.
func (*Filter) MatchesPattern ¶
MatchesPattern adds a matchesPattern filter to the Filter.
func (*Filter) StartsWith ¶
StartsWith adds a startswith 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 (*Query) Substring ¶
Substring returns the substring of the field starting at the specified position 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) 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.