scope

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoParamsInContext = errors.New("No parameters in the request Context.")
	ErrNoValue           = errors.New("No value provided within the scope.")
)

Errors used in the scope

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

func AddselectedFields(s *Scope, fields ...string) error

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

func GetLangtagValue(s *Scope) (string, error)

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

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

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

func GetTotalIncludeFieldCount(s *Scope) int

GetTotalIncludeFieldCount gets the count for all included Fields. May be used as a wait group counter.

func IsRoot

func IsRoot(s *Scope) bool

IsRoot checks if given scope is a root scope of the query

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 SetFields

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

SetFields the fieldset for given scope

func SetLangTagValue

func SetLangTagValue(s *Scope, langtag string) error

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 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{}

	// 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 CopyScope

func CopyScope(s *Scope, root *Scope, isRoot bool) *Scope

CopyScope copies provided scope and sets its root

func GetCollectionScope

func GetCollectionScope(s *Scope) *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 GetRelatedScope

func GetRelatedScope(s *Scope) (*Scope, error)

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

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

AddToFieldset adds the fields into the fieldset

func (*Scope) AddToSelectedFields

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

AddToSelectedFields adds the fields to the scope's selected fields

func (*Scope) AppendSortFields

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

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

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) (errs []*aerrors.ApiError)

BuildFieldset builds the fieldset for the provided scope fields[collection] = field1, field2

func (*Scope) BuildIncludeList

func (s *Scope) BuildIncludeList(includedList ...string,
) (errs []*aerrors.ApiError)

BuildIncludeList provide fast checks for the includedList if given include passes use buildInclude method on it.

func (*Scope) BuildSortFields

func (s *Scope) BuildSortFields(sortFields ...string) (errs []*aerrors.ApiError)

BuildSortFields sets the sort fields for given string array.

func (*Scope) Chain

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

Chain returns the scope's subscopes chain

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

func (s *Scope) CurrentErrorCount() int

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

func (s *Scope) Flags() *flags.Container

Flags gets the scope flags

func (*Scope) GetCollection

func (s *Scope) GetCollection() string

GetCollection Returns the collection name for given scope

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

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

GetPrimaryFieldValue gets the primary field reflect.Value

func (*Scope) GetPrimaryFieldValues

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

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

func (s *Scope) GetRelationshipScope() (relScope *Scope, err error)

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

func (s *Scope) GetScopeValueString() string

GetScopeValueString gets the scope's value string

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

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

func (s *Scope) IncreaseErrorCount(count int)

IncreaseErrorCount adds another error count for the given scope

func (*Scope) InitializeIncluded

func (s *Scope) InitializeIncluded(maxNestedLevel int)

InitializeIncluded initializes the included scopes

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

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) *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) 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 scopes relationship filters

func (*Scope) RemoveRelationshipFilter

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

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

func (s *Scope) SetBelongsToForeignKeyFields() error

SetBelongsToForeignKeyFields sets the fields of type foreign key to the belongs of relaitonships

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

func (s *Scope) SetFlags(c *flags.Container)

SetFlags sets the flags for the given scope

func (*Scope) SetFlagsFrom

func (s *Scope) SetFlagsFrom(flgs ...*flags.Container)

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

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

func (*Scope) SortFields

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

SortFields return current scope sort fields

func (*Scope) Struct

func (s *Scope) Struct() *models.ModelStruct

Struct returns scope's model struct

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