scope

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package scope defines and encapsulates query scope structure with the methods that should be used internally within the neuron-core module.

Index

Constants

This section is empty.

Variables

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

type Kind int

Kind is the enum defining the kind of scope.

const (
	RootKind Kind = iota
	IncludedKind
	RelationshipKind
	RelatedKind
	SubscopeKind
)

Enums for the scope kind.

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 New

func New(model *models.ModelStruct) *Scope

New creates new scope for provided model.

func NewRootScope

func NewRootScope(modelStruct *models.ModelStruct) *Scope

NewRootScope creates new root scope for provided model.

func (*Scope) AddChainSubscope

func (s *Scope) AddChainSubscope(sub *Scope)

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

func (s *Scope) AddSelectedFields(fields ...interface{}) error

AddSelectedFields adds the fields to the scope's selected fields.

func (*Scope) AddToFieldset

func (s *Scope) AddToFieldset(fields ...interface{}) error

AddToFieldset adds the fields into the fieldset

func (*Scope) AppendSortFields

func (s *Scope) AppendSortFields(fromStart bool, sortFields ...*sorts.SortField)

AppendSortFields appends the sortfield to the given scope.

func (*Scope) AreSelected added in v0.2.1

func (s *Scope) AreSelected(fields ...interface{}) (bool, error)

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

func (s *Scope) AutoSelectFields() error

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

func (s *Scope) BuildSortFields(sortFields ...string) error

BuildSortFields sets the sort fields for given string array with the disallowed foreign keys.

func (*Scope) Chain

func (s *Scope) Chain() []*Scope

Chain returns the scope's subscopes chain

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

func (s *Scope) CreateSortFields(disallowFK bool, sortFields ...string) ([]*sorts.SortField, error)

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

func (s *Scope) GetCollection() string

GetCollection Returns the collection name for given scope

func (*Scope) GetCollectionScope added in v0.3.0

func (s *Scope) GetCollectionScope() *Scope

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

func (s *Scope) GetFieldValue(sField *models.StructField) (reflect.Value, error)

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

func (s *Scope) GetPrimaryFieldValue() (reflect.Value, error)

GetPrimaryFieldValue gets the primary field reflect.Value

func (*Scope) GetPrimaryFieldValues

func (s *Scope) GetPrimaryFieldValues() ([]interface{}, error)

GetPrimaryFieldValues - gets the primary field values from the scope. Returns the values within the []interface{} form.

func (*Scope) GetScopeValueString

func (s *Scope) GetScopeValueString() string

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

func (s *Scope) HaveSortFields() bool

HaveSortFields boolean that defines if the scope has any sort fields.

func (*Scope) ID

func (s *Scope) ID() uuid.UUID

ID gets the scope's ID

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

func (s *Scope) IncludedScopes() []*Scope

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

func (s *Scope) IsFieldsetDefault() bool

IsFieldsetDefault gets the boolean if the fieldset is set by default.

func (*Scope) IsMany

func (s *Scope) IsMany() bool

IsMany checks if the value is a slice

func (*Scope) IsPrimaryFieldSelected

func (s *Scope) IsPrimaryFieldSelected() bool

IsPrimaryFieldSelected checks if the Scopes primary field is selected

func (*Scope) IsRoot

func (s *Scope) IsRoot() bool

IsRoot checks if the scope is root kind

func (*Scope) IsSelected added in v0.2.1

func (s *Scope) IsSelected(field interface{}) (bool, error)

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

func (s *Scope) IsSubscope() bool

IsSubscope checks if the given scope is a subscope

func (*Scope) Kind

func (s *Scope) Kind() Kind

Kind returns scope's kind

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

func (s *Scope) NextIncludedField() bool

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) Processor

func (s *Scope) Processor() Processor

Processor returns the scope's processor.

func (*Scope) QueryLanguage

func (s *Scope) QueryLanguage() language.Tag

QueryLanguage gets the QueryLanguage tag.

func (*Scope) RelationshipFilters

func (s *Scope) RelationshipFilters() []*filters.FilterField

RelationshipFilters returns scope's relationship filters.

func (*Scope) RemoveRelationshipFilter

func (s *Scope) RemoveRelationshipFilter(at int) error

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

func (s *Scope) SelectFields(fields ...interface{}) error

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

func (s *Scope) SetBelongsToForeignKeyFields() error

SetBelongsToForeignKeyFields sets the foreign key fields for the 'belongs to' relationships.

func (*Scope) SetCollectionScope

func (s *Scope) SetCollectionScope(cs *Scope)

SetCollectionScope sets the collection scope for given scope.

func (*Scope) SetCollectionValues

func (s *Scope) SetCollectionValues() error

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) SetFields

func (s *Scope) SetFields(fields ...interface{}) error

SetFields sets the fieldset from the provided fields

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

func (s *Scope) SetFiltersTo(to *Scope) error

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) SetIsMany

func (s *Scope) SetIsMany(isMany bool)

SetIsMany sets the isMany variable from the provided argument.

func (*Scope) SetKind

func (s *Scope) SetKind(kind Kind)

SetKind sets the scope's kind

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

func (s *Scope) SetProcessor(p Processor)

SetProcessor sets the processor for given scope

func (*Scope) SetQueryLanguage

func (s *Scope) SetQueryLanguage(tag language.Tag)

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

func (s *Scope) SortFields() []*sorts.SortField

SortFields return current scope sort fields.

func (*Scope) StoreGet added in v0.2.1

func (s *Scope) StoreGet(key interface{}) (value interface{}, ok bool)

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.

func (*Scope) UseI18n

func (s *Scope) UseI18n() bool

UseI18n is a bool that defines if given scope uses the i18n field. I.e. it allows to predefine if model should set language filter.

Jump to

Keyboard shortcuts

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