Documentation
¶
Overview ¶
Package scope defines and encapsulates query scope structure with the methods that should be used internally within the neuron-core module.
Index ¶
- Variables
- func DeleteselectedFields(s *Scope, fields ...*models.StructField) 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) AddSelectedFields(fields ...interface{}) error
- func (s *Scope) AddToFieldset(fields ...interface{}) error
- func (s *Scope) AppendSortFields(fromStart bool, sortFields ...*sorts.SortField)
- func (s *Scope) AreSelected(fields ...interface{}) (bool, error)
- func (s *Scope) AttributeFilters() []*filters.FilterField
- func (s *Scope) AutoSelectFields() error
- func (s *Scope) BuildFieldset(fields ...string) []errors.DetailedError
- func (s *Scope) BuildIncludedFields(includedList ...string) []errors.DetailedError
- func (s *Scope) BuildSortFields(sortFields ...string) error
- func (s *Scope) Chain() []*Scope
- func (s *Scope) ClearAllFilters()
- func (s *Scope) ClearAttributeFilters()
- func (s *Scope) ClearFilterKeyFilters()
- func (s *Scope) ClearForeignKeyFilters()
- func (s *Scope) ClearLanguageFilters()
- func (s *Scope) ClearPrimaryFilters()
- func (s *Scope) ClearRelationshipFilters()
- func (s *Scope) CopyIncludedBoundaries()
- func (s *Scope) CreateModelsRootScope(mStruct *models.ModelStruct) *Scope
- func (s *Scope) CreateSortFields(disallowFK bool, sortFields ...string) ([]*sorts.SortField, error)
- 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) ForeignKeyFilters() []*filters.FilterField
- func (s *Scope) GetCollection() string
- func (s *Scope) GetCollectionScope() *Scope
- func (s *Scope) GetFieldValue(sField *models.StructField) (reflect.Value, error)
- func (s *Scope) GetForeignKeyValues(foreign *models.StructField) ([]interface{}, 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() ([]interface{}, error)
- func (s *Scope) GetScopeValueString() string
- func (s *Scope) GetUniqueForeignKeyValues(foreign *models.StructField) ([]interface{}, error)
- func (s *Scope) HaveSortFields() bool
- func (s *Scope) ID() uuid.UUID
- func (s *Scope) InFieldset(field string) (*models.StructField, bool)
- func (s *Scope) IncludedFields() []*IncludeField
- func (s *Scope) IncludedFieldsChan() <-chan *IncludeField
- func (s *Scope) IncludedScopeByStruct(mStruct *models.ModelStruct) (*Scope, bool)
- func (s *Scope) IncludedScopes() []*Scope
- func (s *Scope) IncludedValues() *safemap.SafeHashMap
- func (s *Scope) IsFieldsetDefault() bool
- func (s *Scope) IsMany() bool
- func (s *Scope) IsPrimaryFieldSelected() bool
- func (s *Scope) IsRoot() bool
- func (s *Scope) IsSelected(field interface{}) (bool, error)
- 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) errors.DetailedError
- 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) SelectFields(fields ...interface{}) error
- 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) SetFiltersTo(to *Scope) error
- 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) SetPagination(p *paginations.Pagination) error
- 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) StoreGet(key interface{}) (value interface{}, ok bool)
- func (s *Scope) StoreSet(key, value interface{})
- func (s *Scope) Struct() *models.ModelStruct
- func (s *Scope) UnselectFieldIfSelected(field *models.StructField)
- func (s *Scope) UnselectFields(fields ...*models.StructField) error
- func (s *Scope) UseI18n() bool
Constants ¶
This section is empty.
Variables ¶
var MaxPermissibleDuplicates = 3
MaxPermissibleDuplicates is the maximum permissible dupliactes value used for errors TODO: get the value from config
Functions ¶
func DeleteselectedFields ¶
func DeleteselectedFields(s *Scope, fields ...*models.StructField) error
DeleteselectedFields deletes the models.StructFields from the given scope Fieldset.
Types ¶
type IncludeField ¶
type IncludeField struct { *models.StructField // Scope is the query scope that contains the values and filters for given // include field Scope *Scope // RelatedScope is a pointer to the main 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 collection 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{} // contains filtered or unexported fields }
Scope contains information about given query for specific collection. If the query defines the different collection (included) than the main scope, then every detail about querying (fieldset, filters, sorts) are within new scopes kept in the Subscopes.
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) AddSelectedFields ¶ added in v0.2.1
AddSelectedFields adds the fields to the scope's selected fields.
func (*Scope) AddToFieldset ¶
AddToFieldset adds the fields into the fieldset
func (*Scope) AppendSortFields ¶
AppendSortFields appends the sortfield to the given scope.
func (*Scope) AreSelected ¶ added in v0.2.1
AreSelected iterates over all selected fields within given scope and returns boolean statement all of provided 'fields' are already selected. Returns an error if any of the 'fields' are not found within given model. or are of invalid type. 'field' may be in a following types/formats:
- NeuronName - string
- Name - string
- models.StructField
func (*Scope) AttributeFilters ¶
func (s *Scope) AttributeFilters() []*filters.FilterField
AttributeFilters returns scope's attribute filters.
func (*Scope) AutoSelectFields ¶
AutoSelectFields selects the fields automatically if none of the select field method were called.
func (*Scope) BuildFieldset ¶
func (s *Scope) BuildFieldset(fields ...string) []errors.DetailedError
BuildFieldset builds the fieldset for the provided scope's string fields in an NeuronName form field1, field2.
func (*Scope) BuildIncludedFields ¶ added in v0.3.0
func (s *Scope) BuildIncludedFields(includedList ...string) []errors.DetailedError
BuildIncludedFields builds the included fields for the given scope.
func (*Scope) BuildSortFields ¶
BuildSortFields sets the sort fields for given string array with the disallowed foreign keys.
func (*Scope) ClearAllFilters ¶ added in v0.2.1
func (s *Scope) ClearAllFilters()
ClearAllFilters clears all filters within the scope.
func (*Scope) ClearAttributeFilters ¶ added in v0.2.1
func (s *Scope) ClearAttributeFilters()
ClearAttributeFilters clears all the attribute filters.
func (*Scope) ClearFilterKeyFilters ¶ added in v0.2.1
func (s *Scope) ClearFilterKeyFilters()
ClearFilterKeyFilters clears the filter key filters.
func (*Scope) ClearForeignKeyFilters ¶ added in v0.2.1
func (s *Scope) ClearForeignKeyFilters()
ClearForeignKeyFilters clears the foreign key filters.
func (*Scope) ClearLanguageFilters ¶ added in v0.2.1
func (s *Scope) ClearLanguageFilters()
ClearLanguageFilters clears the language filters.
func (*Scope) ClearPrimaryFilters ¶ added in v0.2.1
func (s *Scope) ClearPrimaryFilters()
ClearPrimaryFilters clears the primary field filters.
func (*Scope) ClearRelationshipFilters ¶
func (s *Scope) ClearRelationshipFilters()
ClearRelationshipFilters clears the relationship filters.
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) CreateSortFields ¶ added in v0.2.1
CreateSortFields creates the sortfields provided as arguments. The 'disallowFK' is a flag that checks if sorting by Foreign Keys are allowed.
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 returns all key filters.
func (*Scope) ForeignKeyFilters ¶ added in v0.2.1
func (s *Scope) ForeignKeyFilters() []*filters.FilterField
ForeignKeyFilters returns all the foreign key filters.
func (*Scope) GetCollection ¶
GetCollection Returns the collection name for given scope
func (*Scope) GetCollectionScope ¶ added in v0.3.0
GetCollectionScope gets the collection root scope for given scope. Used for included Field scopes for getting their model root scope, that contains all
func (*Scope) GetFieldValue ¶
GetFieldValue gets the value of the provided field
func (*Scope) GetForeignKeyValues ¶
func (s *Scope) GetForeignKeyValues(foreign *models.StructField) ([]interface{}, 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' *model.StructField.
func (*Scope) GetOrCreateFilterKeyFilter ¶
func (s *Scope) GetOrCreateFilterKeyFilter(sField *models.StructField) (filter *filters.FilterField)
GetOrCreateFilterKeyFilter creates or get an existing filter key filter for given 'sField' *models.StructField.
func (*Scope) GetOrCreateForeignKeyFilter ¶
func (s *Scope) GetOrCreateForeignKeyFilter(sField *models.StructField) (filter *filters.FilterField)
GetOrCreateForeignKeyFilter creates or get an existing foreign key filter for given 'sField' *models.StructField.
func (*Scope) GetOrCreateIDFilter ¶
func (s *Scope) GetOrCreateIDFilter() *filters.FilterField
GetOrCreateIDFilter creates or gets an exististing primary field filter.
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 creates or gets an existing language language field filter.
func (*Scope) GetOrCreateRelationshipFilter ¶
func (s *Scope) GetOrCreateRelationshipFilter(sField *models.StructField) (filter *filters.FilterField)
GetOrCreateRelationshipFilter creates or gets existing relationship field fitler for the 'sField' *models.StructField.
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.
func (*Scope) GetScopeValueString ¶
GetScopeValueString gets the scope's value string
func (*Scope) GetUniqueForeignKeyValues ¶ added in v0.2.1
func (s *Scope) GetUniqueForeignKeyValues(foreign *models.StructField) ([]interface{}, error)
GetUniqueForeignKeyValues gets the unique values of the foreign key struct field
func (*Scope) HaveSortFields ¶ added in v0.2.1
HaveSortFields boolean that defines if the scope has any sort fields.
func (*Scope) InFieldset ¶
func (s *Scope) InFieldset(field string) (*models.StructField, bool)
InFieldset checks if the field is in Fieldset
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) IncludedScopeByStruct ¶ added in v0.3.0
func (s *Scope) IncludedScopeByStruct(mStruct *models.ModelStruct) (*Scope, bool)
IncludedScopeByStruct returns the included scope by provided 'mStruct' model struct. Returns scope and boolean which define if the scope exists.
func (*Scope) IncludedScopes ¶
IncludedScopes returns included scopes
func (*Scope) IncludedValues ¶
func (s *Scope) IncludedValues() *safemap.SafeHashMap
IncludedValues returns included scope values
func (*Scope) IsFieldsetDefault ¶ added in v0.5.1
IsFieldsetDefault gets the boolean if the fieldset is set by default.
func (*Scope) IsPrimaryFieldSelected ¶
IsPrimaryFieldSelected checks if the Scopes primary field is selected
func (*Scope) IsSelected ¶ added in v0.2.1
IsSelected iterates over all selected fields within given scope and returns boolean statement if provided 'field' is already selected. Returns an error if the 'field' is not found within given model or it is of invalid type. 'field' may be of following types/formats:
- NeuronName - string
- Name - string
- models.StructField
func (*Scope) IsSubscope ¶
IsSubscope checks if the given scope is a subscope
func (*Scope) LanguageFilter ¶
func (s *Scope) LanguageFilter() *filters.FilterField
LanguageFilter returns language field filter.
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) errors.DetailedError
PreparePaginatedValue prepares paginated value for given key, value and index
func (*Scope) PrimaryFilters ¶
func (s *Scope) PrimaryFilters() []*filters.FilterField
PrimaryFilters returns scope's primary filters.
func (*Scope) QueryLanguage ¶
QueryLanguage gets the QueryLanguage tag.
func (*Scope) RelationshipFilters ¶
func (s *Scope) RelationshipFilters() []*filters.FilterField
RelationshipFilters returns scope's relationship filters.
func (*Scope) RemoveRelationshipFilter ¶
RemoveRelationshipFilter removes the relationship filter 'at' index in relationshipFilters array.
func (*Scope) ResetIncludedField ¶
func (s *Scope) ResetIncludedField()
ResetIncludedField resets the current included field pointer.
func (*Scope) SelectFields ¶ added in v0.2.2
SelectFields creates new SelectFields container and set it's values to provided 'fields'.
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 foreign key fields for the 'belongs to' relationships.
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 contains included 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) SetFiltersTo ¶ added in v0.2.1
SetFiltersTo set the filters to the scope with the same model struct.
func (*Scope) SetIDFilters ¶
func (s *Scope) SetIDFilters(idValues ...interface{})
SetIDFilters sets the primary field filter with the operator OpIn for given 'idValues'.
func (*Scope) SetLanguageFilter ¶
func (s *Scope) SetLanguageFilter(languages ...interface{})
SetLanguageFilter the language filter with the OpIn filter operator and 'languages' values. 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) SetPagination ¶ added in v0.2.1
func (s *Scope) SetPagination(p *paginations.Pagination) error
SetPagination sets the pagination with checking if the pagination is without errors.
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 field filter with the operator OpIn for given 'idValues'.
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 for 'fs' filter fields.
func (*Scope) SortFields ¶
SortFields return current scope sort fields.
func (*Scope) StoreGet ¶ added in v0.2.1
StoreGet gets the store value and checks if exists such key in the store
func (*Scope) StoreSet ¶ added in v0.2.1
func (s *Scope) StoreSet(key, value interface{})
StoreSet sets the store value with the key and it's value
func (*Scope) Struct ¶
func (s *Scope) Struct() *models.ModelStruct
Struct returns scope's model struct
func (*Scope) UnselectFieldIfSelected ¶ added in v0.2.1
func (s *Scope) UnselectFieldIfSelected(field *models.StructField)
UnselectFieldIfSelected unselects provided field if it is selected.
func (*Scope) UnselectFields ¶ added in v0.2.1
func (s *Scope) UnselectFields(fields ...*models.StructField) error
UnselectFields unselects provided fields.