Documentation
¶
Index ¶
- Variables
- type APISelectors
- type APIToDBField
- type APIUpdates
- type Direction
- type ErrInvalidDatabaseSelectorTranslationData
- type ErrInvalidDatabaseUpdateTranslationData
- type ErrInvalidOrderFieldData
- type ErrInvalidPredicateData
- type ErrInvalidSelectorFieldData
- type ErrMaxPageLimitExceededData
- type ErrPredicateNotAllowedData
- type Orders
- type Page
- type Predicate
- type Predicates
- type Selector
Constants ¶
This section is empty.
Variables ¶
var AllPredicates = []Predicate{ Greater, Gt, GreaterOrEqual, Ge, Equal, Eq, NotEqual, Ne, Less, Lt, LessOrEqual, Le, In, NotIn, }
AllPredicates is a slice of all available predicates.
var DirectionsToDB = map[Direction]db.Direction{ DirectionAsc: db.OrderAsc, DirectionAscending: db.OrderAsc, DirectionDesc: db.OrderDesc, DirectionDescending: db.OrderDesc, }
DirectionsToDB is a map of order directions to database order directions.
EqualAndNotEqualPredicates is a slice of predicates that allow both equality and inequality.
var ErrInvalidDatabaseSelectorTranslation = apierror.NewAPIError(
"INVALID_DATABASE_SELECTOR_TRANSLATION",
)
ErrInvalidDatabaseSelectorTranslation indicates that the translation of a database selector failed.
var ErrInvalidDatabaseUpdateTranslation = apierror.NewAPIError(
"INVALID_DATABASE_UPDATE_TRANSLATION",
)
ErrInvalidDatabaseUpdateTranslation is used to indicate that the translation of a database update failed.
var ErrInvalidOrderField = apierror.NewAPIError("INVALID_ORDER_FIELD")
ErrInvalidOrderField is returned when a field is not allowed.
var ErrInvalidPredicate = apierror.NewAPIError("INVALID_PREDICATE")
ErrInvalidPredicate is returned when a predicate is not allowed.
var ErrInvalidSelectorField = apierror.NewAPIError("INVALID_SELECTOR_FIELD")
ErrInvalidSelectorField is returned when a field is not allowed.
var ErrMaxPageLimitExceeded = apierror.NewAPIError("MAX_PAGE_LIMIT_EXCEEDED")
ErrMaxPageLimitExceeded is returned when a page limit is exceeded.
var ErrPredicateNotAllowed = apierror.NewAPIError("PREDICATE_NOT_ALLOWED")
ErrPredicateNotAllowed is returned when a predicate is not allowed.
var OnlyEqualPredicates = []Predicate{Equal, Eq}
OnlyEqualPredicates is a slice of predicates that only allow equality.
var OnlyGreaterPredicates = []Predicate{GreaterOrEqual, Ge, Greater, Gt}
OnlyGreaterPredicates is a slice of predicates that only allow greater values.
var OnlyInAndNotInPredicates = []Predicate{In, NotIn}
OnlyInAndNotInPredicates is a slice of predicates that only allow IN and NOT_IN.
var OnlyLessPredicates = []Predicate{LessOrEqual, Le, Less, Lt}
OnlyLessPredicates is a slice of predicates that only allow less values.
var ToDBPredicates = map[Predicate]db.Predicate{ Greater: db.Greater, Gt: db.Greater, GreaterOrEqual: db.GreaterOrEqual, Ge: db.GreaterOrEqual, Equal: db.Equal, Eq: db.Equal, NotEqual: db.NotEqual, Ne: db.NotEqual, Less: db.Less, Lt: db.Less, LessOrEqual: db.LessOrEqual, Le: db.LessOrEqual, In: db.In, NotIn: db.NotIn, }
ToDBPredicates maps API-level predicates to database predicates.
Functions ¶
This section is empty.
Types ¶
type APISelectors ¶
APISelectors represents a collection of selectors used for filtering data. It is a map where the key is the field name and the value is the selector.
func (APISelectors) AddSelector ¶
func (s APISelectors) AddSelector( field string, predicate Predicate, value any, ) APISelectors
AddSelector adds a new selector to the collection of selectors.
Parameters:
- field: The field name.
- predicate: The predicate to use.
- value: The value to filter on.
Returns:
- APISelectors: A new collection of selectors with the new selector added.
func (APISelectors) ToDBSelectors ¶
func (s APISelectors) ToDBSelectors( apiToDBFieldMap map[string]APIToDBField, ) ([]db.Selector, error)
ToDBSelectors converts a slice of API-level selectors to database selectors.
Parameters:
- apiToDBFieldMap: A map translating API field names to their corresponding database field definitions.
Returns:
- []types.Selector: A slice of types.Selector, which represents the translated database selectors.
- error: An error if any validation fails, such as invalid predicates or unknown fields.
type APIToDBField ¶
APIToDBField is used to translate between API field and database field.
type APIUpdates ¶
APIUpdates represents a list of updates to apply to a database entity.
func (APIUpdates) ToDBUpdates ¶
func (updates APIUpdates) ToDBUpdates( apiToDBFieldMap map[string]APIToDBField, ) ([]db.Update, error)
ToDBUpdates translates a list of updates to a database update list and returns an error if the translation fails.
Parameters:
- updates: The list of updates to translate.
- apiToDBFieldMap: The mapping of API field names to database field names.
Returns:
- []Update: A list of database entity updates.
- error: An error if any field translation fails.
type Direction ¶
type Direction string
Direction is used to specify the direction of the order.
type ErrInvalidDatabaseSelectorTranslationData ¶
type ErrInvalidDatabaseSelectorTranslationData struct {
Field string `json:"field"`
}
ErrInvalidDatabaseSelectorTranslationData is the data for the ErrInvalidDatabaseSelectorTranslation error.
type ErrInvalidDatabaseUpdateTranslationData ¶
type ErrInvalidDatabaseUpdateTranslationData struct {
Field string `json:"field"`
}
ErrInvalidDatabaseUpdateTranslationData is the data for the ErrInvalidDatabaseUpdateTranslation error.
type ErrInvalidOrderFieldData ¶
type ErrInvalidOrderFieldData struct {
Field string `json:"field"`
}
ErrInvalidOrderFieldData is the data for the ErrInvalidOrderField error.
type ErrInvalidPredicateData ¶
type ErrInvalidPredicateData struct {
Predicate Predicate `json:""`
}
ErrInvalidPredicateData is the data for the ErrInvalidPredicate error.
type ErrInvalidSelectorFieldData ¶
type ErrInvalidSelectorFieldData struct {
Field string `json:"field"`
}
ErrInvalidSelectorFieldData is the data for the ErrInvalidSelectorField error.
type ErrMaxPageLimitExceededData ¶
type ErrMaxPageLimitExceededData struct {
MaxLimit int `json:"max_limit"`
}
ErrMaxPageLimitExceededData is the data for the ErrMaxPageLimitExceeded error.
type ErrPredicateNotAllowedData ¶
type ErrPredicateNotAllowedData struct {
Predicate Predicate `json:"predicate"`
}
ErrPredicateNotAllowedData is the data for the ErrPredicateNotAllowed error.
type Orders ¶
Orders is a map of field names to order directions.
func (Orders) ToDBOrders ¶
ToDBOrders translates the provided orders into database orders. It returns an error if any of the orders are invalid.
Parameters:
- apiToDBFieldMap: The mapping of API field names to database field names.
Returns:
- []Order: The list of database orders.
- error: An error if any of the orders are invalid.
func (Orders) TranslateToDBOrders ¶
TranslateToDBOrders translates the provided orders into database orders. It also returns an error if any of the orders are invalid.
Parameters:
- orders: The list of orders to translate.
- allowedOrderFields: The list of allowed order fields.
- apiToDBFieldMap: The mapping of API field names to database field names.
Returns:
- []Order: The list of database orders.
- error: An error if any of the orders are invalid.
type Predicate ¶
type Predicate string
Predicate is a string representation of a filtering predicate.
const ( Greater Predicate = ">" Gt Predicate = "gt" GreaterOrEqual Predicate = ">=" Ge Predicate = "ge" Equal Predicate = "=" Eq Predicate = "eq" NotEqual Predicate = "!=" Ne Predicate = "ne" Less Predicate = "<" Lt Predicate = "LT" LessOrEqual Predicate = "<=" Le Predicate = "le" In Predicate = "in" NotIn Predicate = "not_in" )
Predicates for filtering data.
type Predicates ¶
type Predicates []Predicate
Predicates is a slice of Predicate values.
func (Predicates) StrSlice ¶
func (p Predicates) StrSlice() []string
StrSlice returns a slice of strings representing the predicates.
Returns:
- []string: A slice of strings representing the predicates.
func (Predicates) String ¶
func (p Predicates) String() string
String returns a string representation of the predicates.
Returns:
- string: A comma-separated string of the predicates.
type Selector ¶
type Selector struct {
Predicate Predicate `json:"predicate"` // The predicate to use.
Value any `json:"value"` // The value to filter on.
}
Selector represents a data selector that specifies criteria for filtering data based on fields, predicates, and values.
func NewSelector ¶
NewSelector creates a new API selector with the provided predicate and value.
Parameters:
- predicate: The predicate to use.
- value: The value to filter on.
Returns:
- *APISelector: A new selector.