Documentation
¶
Overview ¶
Package query is the package used that defines the neuron query it's structure, processor, transactions. The package is used to create new queries, allow to set proper query parameters like: filters, pagination, sort order and includes. It also defines the query processes with their config names.
Index ¶
- Constants
- Variables
- func RegisterProcess(p *Process)
- type AfterCreator
- type AfterDeleter
- type AfterGetter
- type AfterLister
- type AfterPatcher
- type BeforeCreator
- type BeforeDeleter
- type BeforeGetter
- type BeforeLister
- type BeforePatcher
- type Creator
- type Deleter
- type FullRepository
- type Getter
- type IsolationLevel
- type Lister
- type Pagination
- func (p *Pagination) Check() error
- func (p *Pagination) FormatQuery(q ...url.Values) url.Values
- func (p *Pagination) GetLimitOffset() (limit int, offset int)
- func (p *Pagination) GetNumberSize() (number, size int)
- func (p *Pagination) SetLimit(limit int)
- func (p *Pagination) SetOffset(offset int)
- func (p *Pagination) SetPageNumber(pageNumber int)
- func (p *Pagination) SetPageSize(pageSize int)
- func (p *Pagination) String() string
- func (p *Pagination) Type() PaginationType
- type PaginationType
- type Patcher
- type Process
- type ProcessChain
- type ProcessFunc
- type Processor
- func (p *Processor) Create(ctx context.Context, s *scope.Scope) error
- func (p *Processor) Delete(ctx context.Context, s *scope.Scope) error
- func (p *Processor) Get(ctx context.Context, s *scope.Scope) error
- func (p *Processor) List(ctx context.Context, s *scope.Scope) error
- func (p *Processor) Patch(ctx context.Context, s *scope.Scope) error
- type RepositoryMethoder
- type Scope
- func MustNew(model interface{}) *Scope
- func MustNewC(c *controller.Controller, model interface{}) *Scope
- func New(model interface{}) (*Scope, error)
- func NewC(c *controller.Controller, model interface{}) (*Scope, error)
- func NewModelC(c *controller.Controller, mStruct *mapping.ModelStruct, isMany bool) *Scope
- func (s *Scope) AddTxChain(sub *Scope)
- func (s *Scope) AppendSelectedFields(fields ...interface{}) error
- func (s *Scope) AttributeFilters() []*filters.FilterField
- func (s *Scope) Begin() (*Tx, error)
- func (s *Scope) BeginTx(ctx context.Context, opts *TxOptions) (*Tx, error)
- func (s *Scope) Commit() error
- func (s *Scope) CommitContext(ctx context.Context) error
- func (s *Scope) Controller() *controller.Controller
- func (s *Scope) Create() error
- func (s *Scope) CreateContext(ctx context.Context) error
- func (s *Scope) Delete() error
- func (s *Scope) DeleteContext(ctx context.Context) error
- func (s *Scope) Fieldset() (fs []*mapping.StructField)
- func (s *Scope) Filter(rawFilter string, values ...interface{}) error
- func (s *Scope) FilterField(filter *filters.FilterField) error
- func (s *Scope) FilterKeyFilters() []*filters.FilterField
- func (s *Scope) ForeignFilters() []*filters.FilterField
- func (s *Scope) FormatQuery() url.Values
- func (s *Scope) Get() error
- func (s *Scope) GetContext(ctx context.Context) error
- func (s *Scope) ID() uuid.UUID
- func (s *Scope) InFieldset(field string) (*mapping.StructField, bool)
- func (s *Scope) IncludeFields(fields ...string) error
- func (s *Scope) IncludedModelValues(model interface{}) (map[interface{}]interface{}, error)
- func (s *Scope) IncludedScope(model interface{}) (*Scope, error)
- func (s *Scope) IsSelected(field interface{}) (bool, error)
- func (s *Scope) LanguageFilter() *filters.FilterField
- func (s *Scope) Limit(limit, offset int) error
- func (s *Scope) List() error
- func (s *Scope) ListContext(ctx context.Context) error
- func (s *Scope) New(value interface{}) (*Scope, error)
- func (s *Scope) NewContext(ctx context.Context, value interface{}) (*Scope, error)
- func (s *Scope) NotSelectedFields(withForeigns ...bool) (notSelected []*mapping.StructField)
- func (s *Scope) Page(number, size int) error
- func (s *Scope) Pagination() *Pagination
- func (s *Scope) Patch() error
- func (s *Scope) PatchContext(ctx context.Context) error
- func (s *Scope) PrimaryFilters() []*filters.FilterField
- func (s *Scope) RelationshipFilters() []*filters.FilterField
- func (s *Scope) Rollback() error
- func (s *Scope) RollbackContext(ctx context.Context) error
- func (s *Scope) SelectField(name string) error
- func (s *Scope) SelectFields(fields ...interface{}) error
- func (s *Scope) SelectedFields() (selected []*mapping.StructField)
- func (s *Scope) SetFields(fields ...interface{}) error
- func (s *Scope) SetFieldset(fields ...interface{}) error
- func (s *Scope) SetPagination(p *Pagination) error
- func (s *Scope) Sort(fields ...string) error
- func (s *Scope) SortField(field interface{}) error
- func (s *Scope) SortFields() []*SortField
- func (s *Scope) StoreGet(key interface{}) (value interface{}, ok bool)
- func (s *Scope) StoreSet(key, value interface{})
- func (s *Scope) String() string
- func (s *Scope) Struct() *mapping.ModelStruct
- func (s *Scope) Tx() *Tx
- func (s *Scope) ValidateCreate() []errors.DetailedError
- func (s *Scope) ValidatePatch() []errors.DetailedError
- type SortField
- type SortOrder
- type Transactioner
- type Tx
- func (t *Tx) Commit() error
- func (t *Tx) CommitContext(ctx context.Context) error
- func (t *Tx) NewC(c *controller.Controller, model interface{}) (*Scope, error)
- func (t *Tx) NewContextC(ctx context.Context, c *controller.Controller, model interface{}) (*Scope, error)
- func (t *Tx) NewContextModelC(ctx context.Context, c *controller.Controller, model *mapping.ModelStruct, ...) (*Scope, error)
- func (t *Tx) NewModelC(c *controller.Controller, model *mapping.ModelStruct, isMany bool) (*Scope, error)
- func (t *Tx) Rollback() error
- func (t *Tx) RollbackContext(ctx context.Context) error
- type TxOptions
- type TxState
Constants ¶
const ( // ParamInclude is the url.Query parameter name for the included fields. ParamInclude string = "include" // ParamFields is the url.Query parameter name for the fieldset. ParamFields string = "fields" )
const ( // ParamPage is a JSON API query parameter used as for pagination. ParamPage = "page" // ParamPageNumber is a JSON API query parameter used in a page based // pagination strategy in conjunction with ParamPageSize. ParamPageNumber = "page[number]" // ParamPageSize is a JSON API query parameter used in a page based // pagination strategy in conjunction with ParamPageNumber. ParamPageSize = "page[size]" // ParamPageOffset is a JSON API query parameter used in an offset based // pagination strategy in conjunction with ParamPageLimit. ParamPageOffset = "page[offset]" // ParamPageLimit is a JSON API query parameter used in an offset based // pagination strategy in conjunction with ParamPageOffset. ParamPageLimit = "page[limit]" // ParamPageCursor is a JSON API query parameter used with a cursor-based // strategy. ParamPageCursor = "page[cursor]" // ParamPageTotal is a JSON API query parameter used in pagination // It tells to API to add information about total-pages or total-count // (depending on the current strategy). ParamPageTotal = "page[total]" )
Pagination constants
const ParamSort = "sort"
ParamSort is the url query parameter name for the sorting fields.
Variables ¶
var ( // ProcessCreate is the process that does the Repository Create method. ProcessCreate = &Process{ Name: "neuron:create", Func: createFunc, } // ProcessBeforeCreate is the process that does the hook BeforeCreate. ProcessBeforeCreate = &Process{ Name: "neuron:hook_before_create", Func: beforeCreateFunc, } // ProcessAfterCreate is the Process that does the hook AfterCreate. ProcessAfterCreate = &Process{ Name: "neuron:hook_after_create", Func: afterCreateFunc, } // ProcessStoreScopePrimaries gets the primary field values and sets into scope's store // under key: internal.ReducedPrimariesKeyCtx. ProcessStoreScopePrimaries = &Process{ Name: "neuron:store_scope_primaries", Func: storeScopePrimaries, } )
var ( // ProcessDelete is the process that does the Repository Delete method. ProcessDelete = &Process{ Name: "neuron:delete", Func: deleteFunc, } // ProcessReducePrimaryFilters is the process that reduces the primary filters for the given process. ProcessReducePrimaryFilters = &Process{ Name: "neuron:reduce_primary_filters", Func: reducePrimaryFilters, } // ProcessBeforeDelete is the Process that does the BeforeDelete hook. ProcessBeforeDelete = &Process{ Name: "neuron:hook_before_delete", Func: beforeDeleteFunc, } // ProcessAfterDelete is the Process that does the AfterDelete hook. ProcessAfterDelete = &Process{ Name: "neuron:hook_after_delete", Func: afterDeleteFunc, } // ProcessDeleteForeignRelationships is the Process that deletes the foreign relatioionships. ProcessDeleteForeignRelationships = &Process{ Name: "neuron:delete_foreign_relationships", Func: deleteForeignRelationshipsFunc, } // ProcessDeleteForeignRelationshipsSafe is the Process that deletes the foreign relatioionships. ProcessDeleteForeignRelationshipsSafe = &Process{ Name: "neuron:delete_foreign_relationships_safe", Func: deleteForeignRelationshipsSafeFunc, } )
var ( // ProcessGet is the process that does the repository Get method. ProcessGet = &Process{ Name: "neuron:get", Func: getFunc, } // ProcessBeforeGet is the process that does the hook BeforeGet. ProcessBeforeGet = &Process{ Name: "neuron:hook_before_get", Func: beforeGetFunc, } // ProcessAfterGet is the process that does the hook AfterGet. ProcessAfterGet = &Process{ Name: "neuron:hook_after_get", Func: afterGetFunc, } // ProcessFillEmptyFieldset fills the fieldset if it is empty. ProcessFillEmptyFieldset = &Process{ Name: "neuron:fill_empty_fieldset", Func: fillEmptyFieldset, } )
var ( // ProcessGetIncluded is the process that gets the included scope values. ProcessGetIncluded = &Process{ Name: "neuron:get_included", Func: getIncludedFunc, } // ProcessGetIncludedSafe is the gouroutine safe process that gets the included scope values. ProcessGetIncludedSafe = &Process{ Name: "neuron:get_included_safe", Func: getIncludedSafeFunc, } )
var ( // ProcessList is the Process that do the Repository List method. ProcessList = &Process{ Name: "neuron:list", Func: listFunc, } // ProcessBeforeList is the Process that do the Hook Before List. ProcessBeforeList = &Process{ Name: "neuron:hook_before_list", Func: beforeListFunc, } // ProcessAfterList is the Process that do the Hook After List. ProcessAfterList = &Process{ Name: "neuron:hook_after_list", Func: afterListFunc, } )
var ( // ProcessPatch is the Process that does the repository Patch method. ProcessPatch = &Process{ Name: "neuron:patch", Func: patchFunc, } // ProcessBeforePatch is the Process that does the hook BeforePatch. ProcessBeforePatch = &Process{ Name: "neuron:hook_before_patch", Func: beforePatchFunc, } // ProcessAfterPatch is the Process that does the hook AfterPatch. ProcessAfterPatch = &Process{ Name: "neuron:hook_after_patch", Func: afterPatchFunc, } // ProcessPatchBelongsToRelationships is the process that patches the belongs to relationships. ProcessPatchBelongsToRelationships = &Process{ Name: "neuron:patch_belongs_to_relationships", Func: patchBelongsToRelationshipsFunc, } // ProcessPatchForeignRelationships is the Process that patches the foreign relationships. ProcessPatchForeignRelationships = &Process{ Name: "neuron:patch_foreign_relationships", Func: patchForeignRelationshipsFunc, } // ProcessPatchForeignRelationshipsSafe is the goroutine safe Process that patches the foreign relationships. ProcessPatchForeignRelationshipsSafe = &Process{ Name: "neuron:patch_foreign_relationships_safe", Func: patchForeignRelationshipsSafeFunc, } )
var ( // ProcessSetBelongsToRelationships is the Process that sets the BelongsToRelationships. ProcessSetBelongsToRelationships = &Process{ Name: "neuron:set_belongs_to_relationships", Func: setBelongsToRelationshipsFunc, } // ProcessGetForeignRelationships is the Process that gets the foreign relationships. ProcessGetForeignRelationships = &Process{ Name: "neuron:get_foreign_relationships", Func: getForeignRelationshipsFunc, } // ProcessGetForeignRelationshipsSafe is the goroutine safe Process that gets the foreign relationships. ProcessGetForeignRelationshipsSafe = &Process{ Name: "neuron:get_foreign_relationships_safe", Func: getForeignRelationshipsSafeFunc, } // ProcessConvertRelationshipFilters converts the relationship filters into a primary or foreign key filters of the root scope. ProcessConvertRelationshipFilters = &Process{ Name: "neuron:convert_relationship_filters", Func: convertRelationshipFiltersFunc, } // ProcessConvertRelationshipFiltersSafe goroutine safe process that converts the relationship filters into a primary or foreign key filters of the root scope. ProcessConvertRelationshipFiltersSafe = &Process{ Name: "neuron:convert_relationship_filters_safe", Func: convertRelationshipFiltersSafeFunc, } )
var ( // ProcessTransactionBegin is the process that begins the transaction. ProcessTransactionBegin = &Process{ Name: "neuron:begin_transaction", Func: beginTransactionFunc, } // ProcessTransactionCommitOrRollback is the process that commits the scope's query // or rollbacks if the error occurred. ProcessTransactionCommitOrRollback = &Process{ Name: "neuron:commit_or_rollback_transaction", Func: commitOrRollbackFunc, } )
Functions ¶
func RegisterProcess ¶
func RegisterProcess(p *Process)
RegisterProcess registers the process with it's unique name. If the process is already registered the function panics.
Types ¶
type AfterCreator ¶
AfterCreator is the interface that has a method used as a hook after the creation process.
type AfterDeleter ¶
AfterDeleter is the interface used as an after delete hook.
type AfterGetter ¶
AfterGetter is the interface used as a hook after getting the value.
type AfterLister ¶
AfterLister is the interface used as a after list hook.
type AfterPatcher ¶
AfterPatcher is the interface used as a after patch hook.
type BeforeCreator ¶
BeforeCreator is the interface used for hooks before the creation process.
type BeforeDeleter ¶
BeforeDeleter is the interface used as a before delete hook.
type BeforeGetter ¶
BeforeGetter is the interface used as a hook before getting value.
type BeforeLister ¶
BeforeLister is the interface used for before list hook.
type BeforePatcher ¶
BeforePatcher is the interface used as a before patch hook.
type Creator ¶ added in v0.2.2
Creator is the repository interface that creates the value within the query.Scope.
type FullRepository ¶
type FullRepository interface { RepositoryMethoder Transactioner }
FullRepository is the interface that implements both repository methoder and the transactioner intefaces.
type IsolationLevel ¶
type IsolationLevel int
IsolationLevel is the
const ( LevelDefault IsolationLevel = iota LevelReadUncommitted LevelReadCommitted LevelWriteCommitted LevelRepeatableRead LevelSnapshot LevelSerializable LevelLinearizable )
Isolation level enums
func (*IsolationLevel) MarshalJSON ¶
func (i *IsolationLevel) MarshalJSON() ([]byte, error)
MarshalJSON marshals the isolation level into json encoding Implements the json.Marshaller interface
func (IsolationLevel) String ¶
func (i IsolationLevel) String() string
func (*IsolationLevel) UnmarshalJSON ¶
func (i *IsolationLevel) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals isolation level from the provided data Implements json.Unmarshaler
type Pagination ¶ added in v0.2.1
type Pagination paginations.Pagination
Pagination defines the query limits and offsets. It defines the maximum size (Limit) as well as an offset at which the query should start.
func LimitOffsetPagination ¶ added in v0.2.1
func LimitOffsetPagination(limit, offset int) *Pagination
LimitOffsetPagination createw new limit, offset type pagination.
func PagedPagination ¶ added in v0.2.1
func PagedPagination(number, size int) *Pagination
PagedPagination creates new paged type Pagination.
func (*Pagination) Check ¶ added in v0.2.1
func (p *Pagination) Check() error
Check checks if the pagination is well formed.
func (*Pagination) FormatQuery ¶ added in v0.2.1
func (p *Pagination) FormatQuery(q ...url.Values) url.Values
FormatQuery formats the pagination for the url query.
func (*Pagination) GetLimitOffset ¶ added in v0.2.1
func (p *Pagination) GetLimitOffset() (limit int, offset int)
GetLimitOffset gets the limit and offset from the current pagination.
func (*Pagination) GetNumberSize ¶ added in v0.5.1
func (p *Pagination) GetNumberSize() (number, size int)
GetNumberSize gets the page number and page size from the provided pagination.
func (*Pagination) SetLimit ¶ added in v0.2.1
func (p *Pagination) SetLimit(limit int)
SetLimit sets the limit for the pagination.
func (*Pagination) SetOffset ¶ added in v0.2.1
func (p *Pagination) SetOffset(offset int)
SetOffset sets the offset for the pagination.
func (*Pagination) SetPageNumber ¶ added in v0.2.1
func (p *Pagination) SetPageNumber(pageNumber int)
SetPageNumber sets the page number for the pagination.
func (*Pagination) SetPageSize ¶ added in v0.2.1
func (p *Pagination) SetPageSize(pageSize int)
SetPageSize sets the page number for the pagination.
func (*Pagination) String ¶ added in v0.2.1
func (p *Pagination) String() string
String implements fmt.Stringer interface.
func (*Pagination) Type ¶ added in v0.2.1
func (p *Pagination) Type() PaginationType
Type returns pagination type.
type PaginationType ¶ added in v0.2.1
type PaginationType int
PaginationType defines the pagination type.
const ( // TpLimitOffset is the pagination type that defines limit or (and) offset. TpLimitOffset PaginationType = iota // TpPage is the pagination type that uses page type pagination i.e. page=1 page size = 10. TpPage )
type Process ¶
type Process struct { Name string Func ProcessFunc }
Process is the structure that defines the query Processor function. It is a pair of the 'Name' and the process function 'Func'. The name is used by the config for specifying Processor's processes order.
type ProcessChain ¶
type ProcessChain []*Process
ProcessChain is the slice (chain) of processes.
func (*ProcessChain) DeleteProcess ¶
func (c *ProcessChain) DeleteProcess(processName string) error
DeleteProcess deletes the process from the chain
func (*ProcessChain) InsertAfter ¶
func (c *ProcessChain) InsertAfter(after string, processes ...*Process) error
InsertAfter inserts the processes after the provided process name
func (*ProcessChain) InsertBefore ¶
func (c *ProcessChain) InsertBefore(before string, processes ...*Process) error
InsertBefore adds the process before the process with the 'before' name.
type ProcessFunc ¶
ProcessFunc is the function that modifies or changes the scope value
type Processor ¶
type Processor struct { CreateChain ProcessChain GetChain ProcessChain ListChain ProcessChain PatchChain ProcessChain DeleteChain ProcessChain }
Processor defines the processes chain for each of the repository methods.
type RepositoryMethoder ¶
RepositoryMethoder is an interface that implements all possible repository methods interfaces.
type Scope ¶
Scope is the query's structure that contains all information required to get, create, patch or delete the data in the repository.
func MustNew ¶ added in v0.2.3
func MustNew(model interface{}) *Scope
MustNew creates new scope with given 'model' for the default controller. Panics on error.
func MustNewC ¶ added in v0.2.1
func MustNewC(c *controller.Controller, model interface{}) *Scope
MustNewC creates new scope with given 'model' for the given controller 'c'. Panics on error.
func New ¶
New creates the scope on the base of the given 'model' it uses default internalController.
func NewC ¶
func NewC(c *controller.Controller, model interface{}) (*Scope, error)
NewC creates the scope for the provided model with respect to the provided internalController 'c'.
func NewModelC ¶
func NewModelC(c *controller.Controller, mStruct *mapping.ModelStruct, isMany bool) *Scope
NewModelC creates new scope on the base of the provided model struct with the value. The value might be a slice of instances if 'isMany' is true.
func (*Scope) AddTxChain ¶
AddTxChain adds a transaction subscope to the given query's scope transaction chain. By default scopes created by the 'New' method are added to the transaction chain and should not be added again.
func (*Scope) AppendSelectedFields ¶ added in v0.3.0
AppendSelectedFields adds provided fields into the scope's selected fields. This would affect the Create or Patch processes where the SelectedFields are taken as the unmarshaled fields. Returns error if the field is already selected.
func (*Scope) AttributeFilters ¶
func (s *Scope) AttributeFilters() []*filters.FilterField
AttributeFilters returns scope's attribute filters.
func (*Scope) BeginTx ¶
BeginTx begins the transaction with the given context.Context 'ctx' and Options 'opts'.
func (*Scope) CommitContext ¶
CommitContext commits the given transaction for the scope with the context.Context 'ctx'.
func (*Scope) Controller ¶
func (s *Scope) Controller() *controller.Controller
Controller gets the scope's internalController.
func (*Scope) Create ¶
Create stores the values within the given scope's value repository, by starting the create process.
func (*Scope) CreateContext ¶
CreateContext creates the scope values with the provided 'ctx' context.Context.
func (*Scope) DeleteContext ¶
DeleteContext deletes the values provided in the scope's value with the context.
func (*Scope) Fieldset ¶
func (s *Scope) Fieldset() (fs []*mapping.StructField)
Fieldset returns the fields in the scope's Fieldset.
func (*Scope) Filter ¶ added in v0.3.0
Filter parses the filter into the filters.FilterField and adds it to the given scope.
func (*Scope) FilterField ¶ added in v0.3.0
func (s *Scope) FilterField(filter *filters.FilterField) error
FilterField adds the filter field to the given query.
func (*Scope) FilterKeyFilters ¶
func (s *Scope) FilterKeyFilters() []*filters.FilterField
FilterKeyFilters returns scope's primary key filters.
func (*Scope) ForeignFilters ¶
func (s *Scope) ForeignFilters() []*filters.FilterField
ForeignFilters returns scope's foreign key filters.
func (*Scope) FormatQuery ¶
FormatQuery formats the scope's query into the url.Values.
func (*Scope) Get ¶
Get gets single value from the repository taking into account the scope filters and parameters
func (*Scope) GetContext ¶
GetContext gets single value from repository taking into account the scope filters, parameters and the context.
func (*Scope) InFieldset ¶
func (s *Scope) InFieldset(field string) (*mapping.StructField, bool)
InFieldset checks if the provided field is in the scope's fieldset.
func (*Scope) IncludeFields ¶ added in v0.3.0
IncludeFields adds the included fields into query scope.
func (*Scope) IncludedModelValues ¶ added in v0.3.0
IncludedModelValues gets the scope's included values for the given 'model'. Returns the map of primary keys to the model values.
func (*Scope) IncludedScope ¶ added in v0.5.1
IncludedScope gets included scope if exists for the 'model'. NOTE: included scope contains no resultant values. This function is used only to set the included models fieldset and filters.
func (*Scope) IsSelected ¶ added in v0.2.1
IsSelected checks if the provided 'field' is selected within given query's scope.
func (*Scope) LanguageFilter ¶
func (s *Scope) LanguageFilter() *filters.FilterField
LanguageFilter returns language filter for given scope.
func (*Scope) Limit ¶ added in v0.2.1
Limit sets the maximum number of objects returned by the List process, Offset sets the query result's offset. It says to skip as many object's from the repository before beginning to return the result. 'Offset' 0 is the same as omitting the 'Offset' clause.
func (*Scope) List ¶
List gets the values from the repository taking with respect to the query filters, sorts, pagination and included values.
func (*Scope) ListContext ¶
ListContext gets the values from the repository taking with respect to the query filters, sorts, pagination and included values. Provided context.Context 'ctx' would be used while querying the repositories.
func (*Scope) New ¶
New creates new subscope with the provided model 'value'. If the root scope is on the transacation the new one will be added to the root's transaction chain. It is a recommended way to create new scope's within hooks if the given scope should be included in the given transaction.
func (*Scope) NewContext ¶
NewContext creates new subscope with the provided model 'value' with the context.Context 'ctx'. If the root scope is on the transacation the new one will be added to the root's transaction chain. It is a recommended way to create new scope's within hooks if the given scope should be included in the given transaction.
func (*Scope) NotSelectedFields ¶
func (s *Scope) NotSelectedFields(withForeigns ...bool) (notSelected []*mapping.StructField)
NotSelectedFields returns fields that are not selected in the query.
func (*Scope) Page ¶ added in v0.2.1
Page sets the pagination of the type TpPage with the page 'number' and page 'size'.
func (*Scope) Pagination ¶
func (s *Scope) Pagination() *Pagination
Pagination returns the query pagination for given scope.
func (*Scope) Patch ¶
Patch updates the scope's attribute and relationship values based on the scope's value and filters. In order to start patch process scope should contain a value with the non-zero primary field, or primary field filters.
func (*Scope) PatchContext ¶
PatchContext updates the scope's attribute and relationship values based on the scope's value and filters with respect to the context.Context 'ctx'. In order to start patch process scope should contain a value with the non-zero primary field, or primary field filters.
func (*Scope) PrimaryFilters ¶
func (s *Scope) PrimaryFilters() []*filters.FilterField
PrimaryFilters returns scope's primary filters.
func (*Scope) RelationshipFilters ¶ added in v0.2.1
func (s *Scope) RelationshipFilters() []*filters.FilterField
RelationshipFilters returns scope's relation fields filters.
func (*Scope) RollbackContext ¶
RollbackContext does the transaction rollback process with the given context.Context 'ctx'.
func (*Scope) SelectField ¶
SelectField selects the field by the name. Selected fields are used in the patching process. By default selected fields are all non zero valued fields in the struct.
func (*Scope) SelectFields ¶ added in v0.2.2
SelectFields clears current scope selected fields and set it to the provided 'fields'. The fields might be a string (NeuronName, Name) or the *mapping.StructField.
func (*Scope) SelectedFields ¶
func (s *Scope) SelectedFields() (selected []*mapping.StructField)
SelectedFields gets the fields selected to modify/create in the repository.
func (*Scope) SetFields ¶ added in v0.3.0
SetFields adds the fields to the scope's fieldset. The fields may be a mapping.StructField as well as field's NeuronName (string) or the StructField Name (string).
func (*Scope) SetFieldset ¶
SetFieldset sets the fieldset for the 'fields'. A field may be a field's name (string), NeuronName (string) or *mapping.StructField.
func (*Scope) SetPagination ¶
func (s *Scope) SetPagination(p *Pagination) error
SetPagination sets the Pagination for the scope.
func (*Scope) Sort ¶ added in v0.3.0
Sort adds the sort fields into given scope. If the scope already have sorted fields or the fields are duplicated returns error.
func (*Scope) SortFields ¶
SortFields returns the sorts used by the query's scope.
func (*Scope) StoreGet ¶ added in v0.2.1
StoreGet gets the value from the scope's Store for given 'key'.
func (*Scope) StoreSet ¶ added in v0.2.1
func (s *Scope) StoreSet(key, value interface{})
StoreSet sets the 'key' and 'value' in the given scope's store.
func (*Scope) Struct ¶
func (s *Scope) Struct() *mapping.ModelStruct
Struct returns scope's model's structure - *mapping.ModelStruct.
func (*Scope) ValidateCreate ¶
func (s *Scope) ValidateCreate() []errors.DetailedError
ValidateCreate validates the scope's value with respect to the 'create validator' and the 'create' validation tags.
func (*Scope) ValidatePatch ¶
func (s *Scope) ValidatePatch() []errors.DetailedError
ValidatePatch validates the scope's value with respect to the 'Patch Validator'.
type SortField ¶ added in v0.2.1
SortField is a field that contains sorting information.
func NewSort ¶ added in v0.5.1
NewSort creates new 'sort' field for given model 'm'. If the 'disallowFK' is set to true the function would not allow to create Sort field of foreign key field.
func NewSortFields ¶ added in v0.5.1
func NewSortFields(m *mapping.ModelStruct, disallowFK bool, sortFields ...string) ([]*SortField, error)
NewSortFields creates new 'sortFields' for given model 'm'. If the 'disallowFK' is set to true the function would not allow to create foreign key sort field. The function throws errors on duplicated field values.
func (*SortField) FormatQuery ¶ added in v0.2.1
FormatQuery returns the sort field formatted for url query. If the optional argument 'q' is provided the format would be set into the provdied url.Values. Otherwise it creates new url.Values instance. Returns modified url.Values
func (*SortField) StructField ¶ added in v0.2.1
func (s *SortField) StructField() *mapping.StructField
StructField returns sortfield's structure.
type SortOrder ¶ added in v0.2.1
type SortOrder int
SortOrder is the enum used as the sorting values order.
type Transactioner ¶
type Transactioner interface { // Begin the scope's transaction. Begin(ctx context.Context, s *Scope) error // Commit the scope's transaction. Commit(ctx context.Context, s *Scope) error // Rollback the scope's transaction. Rollback(ctx context.Context, s *Scope) error }
Transactioner is the interface used for the transactions.
type Tx ¶
type Tx struct { ID uuid.UUID `json:"id"` State TxState `json:"state"` Options TxOptions `json:"options"` // contains filtered or unexported fields }
Tx is the scope's transaction model. It is bound to the single model type.
func (*Tx) CommitContext ¶ added in v0.2.1
CommitContext commits the transaction with 'ctx' context.
func (*Tx) NewC ¶ added in v0.2.1
func (t *Tx) NewC(c *controller.Controller, model interface{}) (*Scope, error)
NewC creates new scope for given transaction.
func (*Tx) NewContextC ¶ added in v0.2.1
func (t *Tx) NewContextC(ctx context.Context, c *controller.Controller, model interface{}) (*Scope, error)
NewContextC creates new scope for given transaction with the 'ctx' context.
func (*Tx) NewContextModelC ¶ added in v0.2.1
func (t *Tx) NewContextModelC(ctx context.Context, c *controller.Controller, model *mapping.ModelStruct, isMany bool) (*Scope, error)
NewContextModelC creates new scope for given 'model' structure and 'ctx' context. It also initializes scope's value. The value might be a slice of instances if 'isMany' is true or a single instance if false.
func (*Tx) NewModelC ¶ added in v0.2.1
func (t *Tx) NewModelC(c *controller.Controller, model *mapping.ModelStruct, isMany bool) (*Scope, error)
NewModelC creates new scope for given model structure, and initializes it's value. The value might be a slice of instances if 'isMany' is true or a single instance if false.
type TxOptions ¶
type TxOptions struct { Isolation IsolationLevel `json:"isolation"` ReadOnly bool `json:"read_only"` }
TxOptions are the options for the Transaction
type TxState ¶
type TxState int
TxState defines the current transaction state
const ( TxBegin TxState TxCommit TxRollback TxDone )
Transaction state enums
func (*TxState) MarshalJSON ¶
MarshalJSON marshals the state into string value Implements the json.Marshaler interface
func (*TxState) UnmarshalJSON ¶
UnmarshalJSON unmarshals the state from the json string value Implements json.Unmarshaler interface
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package filters defines the filter field structure, it's methods and create functions.
|
Package filters defines the filter field structure, it's methods and create functions. |
Package mocks contains mocked neuron factory and repository.
|
Package mocks contains mocked neuron factory and repository. |
Package tests contains query unit tests.
|
Package tests contains query unit tests. |