Documentation
¶
Index ¶
- Constants
- func AsSelectorError(err error, target any) bool
- func IsSelectorError(err error) bool
- func NewFieldSelector(dest any) (*fieldSelector, error)
- func ResolveFieldsFromSchema(dest any) (map[SelectorFieldName]*gormschema.Field, error)
- func SelectorFieldResolver(model any) (*selectorFieldResolver, error)
- type FieldNameResolver
- type SelectorError
- type SelectorField
- type SelectorFieldName
- type SelectorFieldType
Constants ¶
const ( Bool = iota Int SmallInt BigInt Float String Time BoolArray IntArray SmallIntArray BigIntArray FloatArray TextArray TimestampArray Jsonb )
Variables ¶
This section is empty.
Functions ¶
func AsSelectorError ¶
AsSelectorError checks if an error is of type SelectorError and assigns it to target.
func IsSelectorError ¶
IsSelectorError checks if an error is of type SelectorError.
func NewFieldSelector ¶
func ResolveFieldsFromSchema ¶
func ResolveFieldsFromSchema(dest any) (map[SelectorFieldName]*gormschema.Field, error)
ResolveFieldsFromSchema parses the schema of the given model and extracts the fields annotated with the `selector` tag. This is useful for determining which fields can be used in selector queries.
func SelectorFieldResolver ¶
SelectorFieldResolver initializes a new selectorFieldResolver. It resolves schema fields from the provided model. If the model implements FieldNameResolver, it will be used to resolve custom field names.
Types ¶
type FieldNameResolver ¶
type FieldNameResolver interface {
// ResolveCustomSelector resolves a custom selector name to a slice of selector names
// that correspond to actual fields in the model. This allows for mapping of selectors
// to their respective fields, enabling more dynamic queries.
ResolveCustomSelector(selector SelectorFieldName) []SelectorFieldName
// ListCustomSelectors returns a list of custom selectors that can be resolved by the implementing model.
ListCustomSelectors() []SelectorFieldName
}
FieldNameResolver defines an interface for resolving custom field name mappings. This is useful for advanced cases where certain fields map to other names or when dealing with complex schemas that require custom resolution logic.
type SelectorError ¶
SelectorError represents an error related to a selector, wrapping another error.
func NewSelectorError ¶
func NewSelectorError(selectorError, originalError error) *SelectorError
NewSelectorError creates a new SelectorError.
func (*SelectorError) Error ¶
func (e *SelectorError) Error() string
Error returns the string representation of the SelectorError.
func (*SelectorError) Unwrap ¶
func (e *SelectorError) Unwrap() error
Unwrap returns the original error.
type SelectorField ¶
type SelectorField struct {
DBName string
Type SelectorFieldType
DataType gormschema.DataType
StructField reflect.StructField
}
func (*SelectorField) IsJSONBCast ¶
func (sf *SelectorField) IsJSONBCast() bool
IsJSONBCast returns true if the field's data type is 'jsonb' in the database and the expected type is not Jsonb.
type SelectorFieldName ¶
type SelectorFieldName string
SelectorFieldName represents the name of a field used in a selector.
type SelectorFieldType ¶
type SelectorFieldType int
func (SelectorFieldType) IsArray ¶
func (t SelectorFieldType) IsArray() bool
func (SelectorFieldType) String ¶
func (t SelectorFieldType) String() string