selector

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
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

func AsSelectorError(err error, target any) bool

AsSelectorError checks if an error is of type SelectorError and assigns it to target.

func IsSelectorError

func IsSelectorError(err error) bool

IsSelectorError checks if an error is of type SelectorError.

func NewFieldSelector

func NewFieldSelector(dest any) (*fieldSelector, error)

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

func SelectorFieldResolver(model any) (*selectorFieldResolver, error)

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

type SelectorError struct {
	SelectorError error
	OriginalError error
}

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

Jump to

Keyboard shortcuts

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