Documentation
¶
Index ¶
- Variables
- func AddFilterField(s *Scope, filter *filters.FilterField) error
- func AddselectedFields(s *Scope, fields ...string) error
- func DeleteselectedFields(s *Scope, fields ...*models.StructField) error
- func Fieldset(s *Scope) map[string]*models.StructField
- func FiltersAttributes(s *Scope) []*filters.FilterField
- func FiltersForeigns(s *Scope) []*filters.FilterField
- func FiltersKeys(s *Scope) []*filters.FilterField
- func FiltersPrimary(s *Scope) []*filters.FilterField
- func FiltersRelationFields(s *Scope) []*filters.FilterField
- func GetFieldValue(s *Scope, sField *models.StructField) (interface{}, error)
- func GetLangtagValue(s *Scope) (string, error)
- func GetPrimaryFieldValues(s *Scope) ([]interface{}, error)
- func GetTotalIncludeFieldCount(s *Scope) int
- func IsRoot(s *Scope) bool
- func SelectedFieldValues(s *Scope, dialectNamer dialect.FieldNamer) (map[string]interface{}, error)
- func SetAllFields(s *Scope)
- func SetFields(s *Scope, fields ...interface{}) error
- func SetLangTagValue(s *Scope, langtag string) error
- func SetPagination(s *Scope, p *paginations.Pagination) error
- type IncludeField
- type Kind
- type Processor
- type Scope
- func (s *Scope) AddChainSubscope(sub *Scope)
- func (s *Scope) AddFilterField(filter *filters.FilterField) error
- func (s *Scope) AddSelectedField(field *models.StructField)
- func (s *Scope) AddToFieldset(fields ...interface{}) error
- func (s *Scope) AddToSelectedFields(fields ...interface{}) error
- func (s *Scope) AppendSortFields(fromStart bool, sortFields ...*sorts.SortField)
- func (s *Scope) AttributeFilters() []*filters.FilterField
- func (s *Scope) AutoSelectFields() error
- func (s *Scope) BuildFieldset(fields ...string) (errs []*aerrors.ApiError)
- func (s *Scope) BuildIncludeList(includedList ...string) (errs []*aerrors.ApiError)
- func (s *Scope) BuildSortFields(sortFields ...string) (errs []*aerrors.ApiError)
- func (s *Scope) Chain() []*Scope
- func (s *Scope) ClearRelationshipFilters()
- func (s *Scope) CopyIncludedBoundaries()
- func (s *Scope) CreateModelsRootScope(mStruct *models.ModelStruct) *Scope
- func (s *Scope) CurrentErrorCount() int
- func (s *Scope) CurrentIncludedField() (*IncludeField, error)
- func (s *Scope) Fieldset() []*models.StructField
- func (s *Scope) FieldsetDialectNames(dialectNamer dialect.FieldNamer) []string
- func (s *Scope) FillFieldsetIfNotSet()
- func (s *Scope) FilterKeyFilters() []*filters.FilterField
- func (s *Scope) Flags() *flags.Container
- func (s *Scope) GetCollection() string
- func (s *Scope) GetFieldValue(sField *models.StructField) (reflect.Value, error)
- func (s *Scope) GetForeignKeyValues(foreign *models.StructField) (values []interface{}, err error)
- func (s *Scope) GetModelsRootScope(mStruct *models.ModelStruct) (collRootScope *Scope)
- func (s *Scope) GetOrCreateAttributeFilter(sField *models.StructField) (filter *filters.FilterField)
- func (s *Scope) GetOrCreateFilterKeyFilter(sField *models.StructField) (filter *filters.FilterField)
- func (s *Scope) GetOrCreateForeignKeyFilter(sField *models.StructField) (filter *filters.FilterField)
- func (s *Scope) GetOrCreateIDFilter() *filters.FilterField
- func (s *Scope) GetOrCreateIncludeField(field *models.StructField) (includeField *IncludeField)
- func (s *Scope) GetOrCreateLanguageFilter() (filter *filters.FilterField)
- func (s *Scope) GetOrCreateRelationshipFilter(sField *models.StructField) (filter *filters.FilterField)
- func (s *Scope) GetPrimaryFieldValue() (reflect.Value, error)
- func (s *Scope) GetPrimaryFieldValues() (values []interface{}, err error)
- func (s *Scope) GetRelationshipScope() (relScope *Scope, err error)
- func (s *Scope) GetScopeValueString() string
- func (s *Scope) ID() uuid.UUID
- func (s *Scope) InFieldset(field string) (*models.StructField, bool)
- func (s *Scope) IncludeScopeByStruct(mStruct *models.ModelStruct) (*Scope, bool)
- func (s *Scope) IncludedFields() []*IncludeField
- func (s *Scope) IncludedFieldsChan() <-chan *IncludeField
- func (s *Scope) IncludedScopes() []*Scope
- func (s *Scope) IncludedValues() *safemap.SafeHashMap
- func (s *Scope) IncreaseErrorCount(count int)
- func (s *Scope) InitializeIncluded(maxNestedLevel int)
- func (s *Scope) IsMany() bool
- func (s *Scope) IsPrimaryFieldSelected() bool
- func (s *Scope) IsRoot() bool
- func (s *Scope) IsSubscope() bool
- func (s *Scope) Kind() Kind
- func (s *Scope) LanguageFilter() *filters.FilterField
- func (s *Scope) NewValueMany()
- func (s *Scope) NewValueSingle()
- func (s *Scope) NextIncludedField() bool
- func (s *Scope) NonRootScope(mStruct *models.ModelStruct) *Scope
- func (s *Scope) NotSelectedFields(foreignKeys ...bool) []*models.StructField
- func (s *Scope) Pagination() *paginations.Pagination
- func (s *Scope) PreparePaginatedValue(key, value string, index paginations.Parameter) *aerrors.ApiError
- func (s *Scope) PrimaryFilters() []*filters.FilterField
- func (s *Scope) Processor() Processor
- func (s *Scope) QueryLanguage() language.Tag
- func (s *Scope) RelationshipFilters() []*filters.FilterField
- func (s *Scope) RemoveRelationshipFilter(at int) error
- func (s *Scope) ResetIncludedField()
- func (s *Scope) SelectedFields() []*models.StructField
- func (s *Scope) SetAllFields()
- func (s *Scope) SetBelongsToForeignKeyFields() error
- func (s *Scope) SetCollectionScope(cs *Scope)
- func (s *Scope) SetCollectionValues() error
- func (s *Scope) SetEmptyFieldset()
- func (s *Scope) SetFields(fields ...interface{}) error
- func (s *Scope) SetFieldsetNoCheck(fields ...*models.StructField)
- func (s *Scope) SetFlags(c *flags.Container)
- func (s *Scope) SetFlagsFrom(flgs ...*flags.Container)
- func (s *Scope) SetIDFilters(idValues ...interface{})
- func (s *Scope) SetIsMany(isMany bool)
- func (s *Scope) SetKind(kind Kind)
- func (s *Scope) SetLanguageFilter(languages ...interface{})
- func (s *Scope) SetNilFieldset()
- func (s *Scope) SetPaginationNoCheck(p *paginations.Pagination)
- func (s *Scope) SetPrimaryFilters(values ...interface{})
- func (s *Scope) SetProcessor(p Processor)
- func (s *Scope) SetQueryLanguage(tag language.Tag)
- func (s *Scope) SetRelationshipFilters(fs []*filters.FilterField)
- func (s *Scope) SortFields() []*sorts.SortField
- func (s *Scope) Struct() *models.ModelStruct
- func (s *Scope) UseI18n() bool
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoParamsInContext = errors.New("No parameters in the request Context.") ErrNoValue = errors.New("No value provided within the scope.") )
Errors used in the scope
var (
// MaxPermissibleDuplicates is the maximum permissible dupliactes value used for errors
MaxPermissibleDuplicates = 3
)
Functions ¶
func AddFilterField ¶
func AddFilterField(s *Scope, filter *filters.FilterField) error
AddFilterField adds the filter field for given scope
func AddselectedFields ¶
AddselectedFields adds provided fields into given Scope's selectedFields Container
func DeleteselectedFields ¶
func DeleteselectedFields(s *Scope, fields ...*models.StructField) error
DeleteselectedFields deletes the models.StructFields from the given scope Fieldset
func Fieldset ¶
func Fieldset(s *Scope) map[string]*models.StructField
Fieldset returns given scope fieldset
func FiltersAttributes ¶
func FiltersAttributes(s *Scope) []*filters.FilterField
FiltersAttributes returns scope's attribute filters
func FiltersForeigns ¶
func FiltersForeigns(s *Scope) []*filters.FilterField
FiltersForeigns returns all foreign key filter
func FiltersKeys ¶
func FiltersKeys(s *Scope) []*filters.FilterField
FiltersKeys return all FilterKey filters
func FiltersPrimary ¶
func FiltersPrimary(s *Scope) []*filters.FilterField
FiltersPrimary returns scope's primary filters
func FiltersRelationFields ¶
func FiltersRelationFields(s *Scope) []*filters.FilterField
FiltersRelationFields returns scope's relationship filters
func GetFieldValue ¶
func GetFieldValue(s *Scope, sField *models.StructField) (interface{}, error)
GetFieldValue gets the scope's field value
func GetLangtagValue ¶
GetLangtagValue returns the value of the langtag for given scope returns error if:
- the scope's model does not support i18n
- provided nil Value for the scope
- the scope's Value is of invalid type
func GetPrimaryFieldValues ¶
GetPrimaryFieldValues - gets the primary field values from the scope. Returns the values within the []interface{} form
returns - ErrNoValue if no value provided. - ErrInvalidType if the scope's value is of invalid type - *reflect.ValueError if internal occurs.
func GetTotalIncludeFieldCount ¶
GetTotalIncludeFieldCount gets the count for all included Fields. May be used as a wait group counter.
func SelectedFieldValues ¶
func SelectedFieldValues(s *Scope, dialectNamer dialect.FieldNamer) (map[string]interface{}, error)
SelectedFieldValues gets the scopes field values with provided dialectNamer
func SetAllFields ¶
func SetAllFields(s *Scope)
SetAllFields sets the fieldset to all possible fields
func SetLangTagValue ¶
SetLangTagValue sets the langtag to the scope's value. returns an error
- if the Value is of invalid type or if the
- if the model does not support i18n
- if the scope's Value is nil pointer
func SetPagination ¶
func SetPagination(s *Scope, p *paginations.Pagination) error
SetPagination sets the Pagination for the query scope
Types ¶
type IncludeField ¶
type IncludeField struct { *models.StructField // Scope is the scope that contains the values and filters for given // include field Scope *Scope // RelatedScope is a pointer to the scope where the IncludedField is stored. RelatedScope *Scope NotInFieldset bool }
IncludeField is the includes information scope it contains the field to include from the root scope related subscope, and subfields to include.
func (*IncludeField) GetMissingPrimaries ¶
func (i *IncludeField) GetMissingPrimaries() ([]interface{}, error)
GetMissingPrimaries gets the id values from the RelatedScope, checks which id values were already stored within the colleciton root scope and return new ones.
type Processor ¶
type Processor interface { // Create runs creation processes Create(ctx context.Context, s *Scope) error // Delete runs delete processes Delete(ctx context.Context, s *Scope) error // Get runs get processes Get(ctx context.Context, s *Scope) error // List runs the list processes List(ctx context.Context, s *Scope) error // Patch runs the patch processes Patch(ctx context.Context, s *Scope) error }
Processor is the interface used to create the scope's of the queries
type Scope ¶
type Scope struct { // Value is the values or / value of the queried object / objects Value interface{} // Store stores the scope's related key values Store map[interface{}]interface{} // contains filtered or unexported fields }
Scope contains information about given query for specific collection if the query defines the different collection than the main scope, then every detail about querying (fieldset, filters, sorts) are within new scopes kept in the Subscopes
func GetCollectionScope ¶
GetCollectionScope gets the collection root scope for given scope. Used for included Field scopes for getting their model root scope, that contains all
func GetRelatedScope ¶
GetRelatedScope gets the related scope with preset filter values. The filter values are being taken form the root 's' Scope relationship id's. Returns error if the scope was not build by controller BuildRelatedScope.
func NewRootScope ¶
func NewRootScope(modelStruct *models.ModelStruct) *Scope
NewRootScope creates new root scope for provided model
func (*Scope) AddChainSubscope ¶
AddChainSubscope adds the subscope to the 's' subscopes
func (*Scope) AddFilterField ¶
func (s *Scope) AddFilterField(filter *filters.FilterField) error
AddFilterField adds the filter to the given scope
func (*Scope) AddSelectedField ¶
func (s *Scope) AddSelectedField(field *models.StructField)
AddSelectedField adds the selected field to the selected field's array
func (*Scope) AddToFieldset ¶
AddToFieldset adds the fields into the fieldset
func (*Scope) AddToSelectedFields ¶
AddToSelectedFields adds the fields to the scope's selected fields
func (*Scope) AppendSortFields ¶
AppendSortFields appends the sortfield to the given scope
func (*Scope) AttributeFilters ¶
func (s *Scope) AttributeFilters() []*filters.FilterField
AttributeFilters returns scopes attribute filters
func (*Scope) AutoSelectFields ¶
AutoSelectFields selects the fields automatically if none of the select field method were called
func (*Scope) BuildFieldset ¶
BuildFieldset builds the fieldset for the provided scope fields[collection] = field1, field2
func (*Scope) BuildIncludeList ¶
BuildIncludeList provide fast checks for the includedList if given include passes use buildInclude method on it.
func (*Scope) BuildSortFields ¶
BuildSortFields sets the sort fields for given string array.
func (*Scope) ClearRelationshipFilters ¶
func (s *Scope) ClearRelationshipFilters()
ClearRelationshipFilters clears the relationship filters for the scope
func (*Scope) CopyIncludedBoundaries ¶
func (s *Scope) CopyIncludedBoundaries()
CopyIncludedBoundaries copies all included data from scope's included fields Into it's included scopes.
func (*Scope) CreateModelsRootScope ¶
func (s *Scope) CreateModelsRootScope(mStruct *models.ModelStruct) *Scope
CreateModelsRootScope creates scope for given model (mStruct) and stores it within the rootScope.includedScopes. Used for collection unique root scopes (filters, fieldsets etc. for given collection scope)
func (*Scope) CurrentErrorCount ¶
CurrentErrorCount returns current error count number
func (*Scope) CurrentIncludedField ¶
func (s *Scope) CurrentIncludedField() (*IncludeField, error)
CurrentIncludedField gets current included field, based on the index
func (*Scope) Fieldset ¶
func (s *Scope) Fieldset() []*models.StructField
Fieldset returns current scope fieldset
func (*Scope) FieldsetDialectNames ¶
func (s *Scope) FieldsetDialectNames(dialectNamer dialect.FieldNamer) []string
FieldsetDialectNames gets the fieldset names, named using provided DialetFieldNamer
func (*Scope) FillFieldsetIfNotSet ¶
func (s *Scope) FillFieldsetIfNotSet()
FillFieldsetIfNotSet sets the fieldset to full if the fieldset is not set
func (*Scope) FilterKeyFilters ¶
func (s *Scope) FilterKeyFilters() []*filters.FilterField
FilterKeyFilters return key filters for the scope
func (*Scope) GetCollection ¶
GetCollection Returns the collection name for given scope
func (*Scope) GetFieldValue ¶
GetFieldValue gets the value of the provided field
func (*Scope) GetForeignKeyValues ¶
func (s *Scope) GetForeignKeyValues(foreign *models.StructField) (values []interface{}, err error)
GetForeignKeyValues gets the values of the foreign key struct field
func (*Scope) GetModelsRootScope ¶
func (s *Scope) GetModelsRootScope(mStruct *models.ModelStruct) (collRootScope *Scope)
GetModelsRootScope returns the scope for given model that is stored within the rootScope
func (*Scope) GetOrCreateAttributeFilter ¶
func (s *Scope) GetOrCreateAttributeFilter( sField *models.StructField, ) (filter *filters.FilterField)
GetOrCreateAttributeFilter creates or gets existing attribute filter for given sField
func (*Scope) GetOrCreateFilterKeyFilter ¶
func (s *Scope) GetOrCreateFilterKeyFilter(sField *models.StructField) (filter *filters.FilterField)
GetOrCreateFilterKeyFilter creates or get an existing filter field
func (*Scope) GetOrCreateForeignKeyFilter ¶
func (s *Scope) GetOrCreateForeignKeyFilter(sField *models.StructField) (filter *filters.FilterField)
GetOrCreateForeignKeyFilter creates or get an existing filter field
func (*Scope) GetOrCreateIDFilter ¶
func (s *Scope) GetOrCreateIDFilter() *filters.FilterField
GetOrCreateIDFilter gets or creates new filterField
func (*Scope) GetOrCreateIncludeField ¶
func (s *Scope) GetOrCreateIncludeField(field *models.StructField, ) (includeField *IncludeField)
GetOrCreateIncludeField checks if given include field exists within given scope. if not found create new include field. returns the include field
func (*Scope) GetOrCreateLanguageFilter ¶
func (s *Scope) GetOrCreateLanguageFilter() (filter *filters.FilterField)
GetOrCreateLanguageFilter used to get or if yet not found create the language filter field
func (*Scope) GetOrCreateRelationshipFilter ¶
func (s *Scope) GetOrCreateRelationshipFilter(sField *models.StructField) (filter *filters.FilterField)
GetOrCreateRelationshipFilter creates or gets existing fitler field for given struct field.
func (*Scope) GetPrimaryFieldValue ¶
GetPrimaryFieldValue gets the primary field reflect.Value
func (*Scope) GetPrimaryFieldValues ¶
GetPrimaryFieldValues - gets the primary field values from the scope. Returns the values within the []interface{} form
returns - ErrNoValue if no value provided. - ErrInvalidType if the scope's value is of invalid type - *reflect.ValueError if internal occurs.
func (*Scope) GetRelationshipScope ¶
GetRelationshipScope - for given root Scope 's' gets the value of the relationship used for given request and set it's value into relationshipScope. returns an error if the value is not set or there is no relationship includedField for given scope.
func (*Scope) GetScopeValueString ¶
GetScopeValueString gets the scope's value string
func (*Scope) InFieldset ¶
func (s *Scope) InFieldset(field string) (*models.StructField, bool)
InFieldset checks if the field is in Fieldset
func (*Scope) IncludeScopeByStruct ¶
func (s *Scope) IncludeScopeByStruct(mStruct *models.ModelStruct) (*Scope, bool)
IncludeScopeByStruct returns the included scope by model struct
func (*Scope) IncludedFields ¶
func (s *Scope) IncludedFields() []*IncludeField
IncludedFields returns included fields slice
func (*Scope) IncludedFieldsChan ¶
func (s *Scope) IncludedFieldsChan() <-chan *IncludeField
IncludedFieldsChan generates an included field channel
func (*Scope) IncludedScopes ¶
IncludedScopes returns included scopes
func (*Scope) IncludedValues ¶
func (s *Scope) IncludedValues() *safemap.SafeHashMap
IncludedValues returns included scope values
func (*Scope) IncreaseErrorCount ¶
IncreaseErrorCount adds another error count for the given scope
func (*Scope) InitializeIncluded ¶
InitializeIncluded initializes the included scopes
func (*Scope) IsPrimaryFieldSelected ¶
IsPrimaryFieldSelected checks if the Scopes primary field is selected
func (*Scope) IsSubscope ¶
IsSubscope checks if the given scope is a subscope
func (*Scope) LanguageFilter ¶
func (s *Scope) LanguageFilter() *filters.FilterField
LanguageFilter return language filters for given scope
func (*Scope) NewValueMany ¶
func (s *Scope) NewValueMany()
NewValueMany creates empty slice of ptr value for given scope value is of type []*models.ModelStruct.Type
func (*Scope) NewValueSingle ¶
func (s *Scope) NewValueSingle()
NewValueSingle creates new value for given scope of a type *models.ModelStruct.Type
func (*Scope) NextIncludedField ¶
NextIncludedField allows iteration over the includedFields. If there is any included field it changes the current field index to the next available.
func (*Scope) NonRootScope ¶
func (s *Scope) NonRootScope(mStruct *models.ModelStruct) *Scope
NonRootScope creates non root scope
func (*Scope) NotSelectedFields ¶
func (s *Scope) NotSelectedFields(foreignKeys ...bool) []*models.StructField
NotSelectedFields lists all the fields that are not selected within the scope
func (*Scope) Pagination ¶
func (s *Scope) Pagination() *paginations.Pagination
Pagination returns scope's pagination
func (*Scope) PreparePaginatedValue ¶
func (s *Scope) PreparePaginatedValue(key, value string, index paginations.Parameter) *aerrors.ApiError
PreparePaginatedValue prepares paginated value for given key, value and index
func (*Scope) PrimaryFilters ¶
func (s *Scope) PrimaryFilters() []*filters.FilterField
PrimaryFilters returns scopes primary filter values
func (*Scope) QueryLanguage ¶
QueryLanguage gets the QueryLanguage tag
func (*Scope) RelationshipFilters ¶
func (s *Scope) RelationshipFilters() []*filters.FilterField
RelationshipFilters returns scopes relationship filters
func (*Scope) RemoveRelationshipFilter ¶
RemoveRelationshipFilter at index
func (*Scope) ResetIncludedField ¶
func (s *Scope) ResetIncludedField()
ResetIncludedField resets the current included field pointer
func (*Scope) SelectedFields ¶
func (s *Scope) SelectedFields() []*models.StructField
SelectedFields return fields that were selected during unmarshaling
func (*Scope) SetAllFields ¶
func (s *Scope) SetAllFields()
SetAllFields sets all fields in the fieldset
func (*Scope) SetBelongsToForeignKeyFields ¶
SetBelongsToForeignKeyFields sets the fields of type foreign key to the belongs of relaitonships
func (*Scope) SetCollectionScope ¶
SetCollectionScope sets the collection scope for given scope
func (*Scope) SetCollectionValues ¶
SetCollectionValues iterate over the scope's Value field and add it to the collection root scope.if the collection root scope contains value with given primary field it checks if given // scope containsincluded fields that are not within fieldset. If so it adds the included field value to the value that were inside the collection root scope.
func (*Scope) SetEmptyFieldset ¶
func (s *Scope) SetEmptyFieldset()
SetEmptyFieldset sets the scope's fieldset to nil
func (*Scope) SetFieldsetNoCheck ¶
func (s *Scope) SetFieldsetNoCheck(fields ...*models.StructField)
SetFieldsetNoCheck adds fields to the scope without checking if the fields are correct.
func (*Scope) SetFlagsFrom ¶
SetFlagsFrom sets the flags from the provided provided flags array
func (*Scope) SetIDFilters ¶
func (s *Scope) SetIDFilters(idValues ...interface{})
SetIDFilters sets the ID Filter for given values.
func (*Scope) SetLanguageFilter ¶
func (s *Scope) SetLanguageFilter(languages ...interface{})
SetLanguageFilter the LanguageFilter for given scope. If the scope's model does not support i18n it does not create language filter, and ends fast.
func (*Scope) SetNilFieldset ¶
func (s *Scope) SetNilFieldset()
SetNilFieldset sets the fieldset to nil
func (*Scope) SetPaginationNoCheck ¶
func (s *Scope) SetPaginationNoCheck(p *paginations.Pagination)
SetPaginationNoCheck sets the pagination without check
func (*Scope) SetPrimaryFilters ¶
func (s *Scope) SetPrimaryFilters(values ...interface{})
SetPrimaryFilters sets the primary filter for given values.
func (*Scope) SetProcessor ¶
SetProcessor sets the processor for given scope
func (*Scope) SetQueryLanguage ¶
SetQueryLanguage sets the query language tag
func (*Scope) SetRelationshipFilters ¶
func (s *Scope) SetRelationshipFilters(fs []*filters.FilterField)
SetRelationshipFilters sets the relationship filters
func (*Scope) SortFields ¶
SortFields return current scope sort fields
func (*Scope) Struct ¶
func (s *Scope) Struct() *models.ModelStruct
Struct returns scope's model struct