Documentation
¶
Index ¶
- Variables
- func RegisterProcess(p *Process) error
- type AfterCreator
- type AfterDeleter
- type AfterGetter
- type AfterLister
- type AfterPatcher
- type BeforeCreator
- type BeforeDeleter
- type BeforeGetter
- type BeforeLister
- type BeforePatcher
- type Beginner
- type Committer
- type Creater
- 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() (int, 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 Rollbacker
- type Scope
- func (s *Scope) AddFilter(filter *filters.FilterField) error
- func (s *Scope) AddStringFilter(rawFilter string, values ...interface{}) error
- func (s *Scope) AddStringSortFields(fields ...string) error
- func (s *Scope) AddToFieldset(fields ...interface{}) error
- func (s *Scope) AddToSelectedFields(fields ...interface{}) error
- func (s *Scope) AddTxChain(sub *Scope)
- func (s *Scope) AttributeFilters() []*filters.FilterField
- func (s *Scope) Begin() error
- func (s *Scope) BeginTx(ctx context.Context, opts *TxOptions) error
- func (s *Scope) Commit() error
- func (s *Scope) CommitContext(ctx context.Context) error
- func (s *Scope) Controller() *ctrl.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) 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) IncludedValue(model interface{}) (interface{}, 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) RelationFilters() []*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) SelectedFields() (selected []*mapping.StructField)
- func (s *Scope) SetFieldset(fields ...interface{}) error
- func (s *Scope) SetPagination(p *Pagination) error
- func (s *Scope) SortBy(fields ...string) error
- func (s *Scope) SortFields() []*SortField
- func (s *Scope) Struct() *mapping.ModelStruct
- func (s *Scope) Tx() *Tx
- func (s *Scope) ValidateCreate() []*errors.ApiError
- func (s *Scope) ValidatePatch() []*errors.ApiError
- type SortField
- type SortOrder
- type Transactioner
- type Tx
- type TxOptions
- type TxState
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilScopeValue error = errors.New("Scope with nil value provided") ErrRepsitoryNotATransactioner error = errors.New("Given repository doesn't implement Tranasctioner interface") ErrNoRepositoryFound error = errors.New("No repositories found for model.") ErrNoGetterRepoFound error = errors.New("No Getter repository possible for provided model") ErrNoListerRepoFound error = errors.New("No Lister repository possible for provided model") ErrNoPatcherFound error = errors.New("The repository doesn't implement Patcher interface") ErrNoDeleterFound error = errors.New("The repository doesn't implement Deleter interface") ErrTransactionAlreadyResolved error = errors.New("Transaction already resolved") )
common errors used in the scope package
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 HBeforeCreate ProcessBeforeCreate = &Process{ Name: "neuron:hook_before_create", Func: beforeCreateFunc, } // ProcessAfterCreate is the Process that does the hook HAfterCreate ProcessAfterCreate = &Process{ Name: "neuron:hook_after_create", Func: afterCreateFunc, } )
var ( // ProcessDelete is the process that does the Repository Delete method ProcessDelete = &Process{ Name: "neuron:delete", Func: deleteFunc, } // ProcessBeforeDelete is the Process that does the HBeforeDelete hook ProcessBeforeDelete = &Process{ Name: "neuron:hook_before_delete", Func: beforeDeleteFunc, } // ProcessAfterDelete is the Process that does the HAfterDelete hook ProcessAfterDelete = &Process{ Name: "neuron:hook_after_delete", Func: afterDeleteFunc, } // ProcessDeleteForeignRelationships is the Process that deletes the foreing relatioionships ProcessDeleteForeignRelationships = &Process{ Name: "neuron:delete_foreign_relationships", Func: deleteForeignRelationshipsFunc, } )
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 HBeforeGet ProcessBeforeGet = &Process{ Name: "neuron:hook_before_get", Func: beforeGetFunc, } // ProcessAfterGet is the process that does the hook HAfterGet ProcessAfterGet = &Process{ Name: "neuron:hook_after_get", Func: afterGetFunc, } )
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 HBeforePatch ProcessBeforePatch = &Process{ Name: "neuron:hook_before_patch", Func: beforePatchFunc, } // ProcessAfterPatch is the Process that does the hook HAfterPatch 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, } )
var ( // ProcessGetIncluded is the process that gets the included scope values ProcessGetIncluded = &Process{ Name: "neuron:get_included", Func: getIncludedFunc, } // 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, } // ProcessConvertRelationshipFilters converts the relationship filters into a primary or foreign key filters of the root scope ProcessConvertRelationshipFilters = &Process{ Name: "neuron:convert_relationship_filters", Func: convertRelationshipFilters, } )
var ( // ErrFieldNotFound is an error thrown when the provided Field is not found wihtin the scope ErrFieldNotFound error = stdErrors.New("Field not found") // ErrModelNotIncluded is an error that is thrown when the provided model is not included into given scope ErrModelNotIncluded error = stdErrors.New("Model were not included into scope") )
var ( ErrRepositoryNotACommiter = errors.New("Repository doesn't implement Commiter interface") ErrRepositoryNotARollbacker = errors.New("Repository doesn't implement Rollbacker interface") )
ErrRepositoryNotACommiter is an error returned when the repository doesn't implement Commiter interface
var ErrNoCreateRepository = errors.New("No create repository for model found.")
ErrNoCreateRepository is thrown when the repository doesn't implement the creator interface
var ( // ErrTxAlreadyBegan notifies that the transaction had already began ErrTxAlreadyBegan = errors.New("Transaction already began") )
Functions ¶
func RegisterProcess ¶
RegisterProcess registers the process. 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 from api
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 gettin value from api
type BeforeLister ¶
BeforeLister is the interface used for before list hook
type BeforePatcher ¶
BeforePatcher is the interface used as a before patch hook
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.1.5
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.1.5
func LimitOffsetPagination(limit, offset int) *Pagination
LimitOffsetPagination createw new limit, offset type pagination
func PagedPagination ¶ added in v0.1.5
func PagedPagination(number, size int) *Pagination
PagedPagination creates new paged type Pagination
func (*Pagination) Check ¶ added in v0.1.5
func (p *Pagination) Check() error
Check checks if the pagination is well formed
func (*Pagination) FormatQuery ¶ added in v0.1.5
func (p *Pagination) FormatQuery(q ...url.Values) url.Values
FormatQuery formats the pagination for the url query.
func (*Pagination) GetLimitOffset ¶ added in v0.1.5
func (p *Pagination) GetLimitOffset() (int, int)
GetLimitOffset gets the limit and offset from the current pagination
func (*Pagination) SetLimit ¶ added in v0.1.5
func (p *Pagination) SetLimit(limit int)
SetLimit sets the limit for the pagination
func (*Pagination) SetOffset ¶ added in v0.1.5
func (p *Pagination) SetOffset(offset int)
SetOffset sets the offset for the pagination
func (*Pagination) SetPageNumber ¶ added in v0.1.5
func (p *Pagination) SetPageNumber(pageNumber int)
SetPageNumber sets the page number for the pagination
func (*Pagination) SetPageSize ¶ added in v0.1.5
func (p *Pagination) SetPageSize(pageSize int)
SetPageSize sets the page number for the pagination
func (*Pagination) String ¶ added in v0.1.5
func (p *Pagination) String() string
String implements Stringer interface
func (*Pagination) Type ¶ added in v0.1.5
func (p *Pagination) Type() PaginationType
Type returns pagination type
type PaginationType ¶ added in v0.1.5
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 pair of the name and the ProcessFunction
type ProcessChain ¶
type ProcessChain []*Process
ProcessChain is the 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 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 is the struct that allows to query over the gateway's model's
type RepositoryMethoder ¶
RepositoryMethoder is an interface that implements all possible repository methods interfaces
type Rollbacker ¶
Rollbacker is the interface used for rollbacks the interface transaction
type Scope ¶
Scope is the Queries heart and soul which keeps all possible information Within it's structure
func MustC ¶
func MustC(c *ctrl.Controller, model interface{}) *Scope
MustC creates the scope's model for the provided controller
func NewC ¶
func NewC(c *ctrl.Controller, model interface{}) (*Scope, error)
NewC creates the scope for the provided model with respect to the provided controller 'c'
func NewModelC ¶
func NewModelC(c *ctrl.Controller, mStruct *mapping.ModelStruct, isMany bool) *Scope
NewModelC creates new scope on the base of the provided model struct with the new single value
func (*Scope) AddFilter ¶
func (s *Scope) AddFilter(filter *filters.FilterField) error
AddFilter adds the given scope's filter field
func (*Scope) AddStringFilter ¶
AddStringFilter parses the filter into the FilterField and adds to the provided scope's filters
func (*Scope) AddStringSortFields ¶
AddStringSortFields adds the sort fields in a string form i.e. [-field_1, field_2] -> Descending Field1 and Ascending Field2
func (*Scope) AddToFieldset ¶
AddToFieldset adds the fields to the scope's fieldset. The fields may be a mapping.StructField as well as the string - which might be the 'api name' or structFields name.
func (*Scope) AddToSelectedFields ¶
AddToSelectedFields 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.
func (*Scope) AddTxChain ¶
AddTxChain adds the 'sub' Scope to the 's' transaction chain Use on scope not created with 's'.New()
func (*Scope) AttributeFilters ¶
func (s *Scope) AttributeFilters() []*filters.FilterField
AttributeFilters returns scope's attribute iFilters
func (*Scope) CommitContext ¶
CommitContext commits the given transaction for the scope with the context
func (*Scope) Controller ¶
func (s *Scope) Controller() *ctrl.Controller
Controller getsthe scope's predefined controller
func (*Scope) CreateContext ¶
CreateContext creates the scope values with the 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) FilterKeyFilters ¶
func (s *Scope) FilterKeyFilters() []*filters.FilterField
FilterKeyFilters returns scope's primary iFilters
func (*Scope) ForeignFilters ¶
func (s *Scope) ForeignFilters() []*filters.FilterField
ForeignFilters returns scope's foreign key iFilters
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 fieldset
func (*Scope) IncludedValue ¶
IncludedValue getst the scope's included values for provided model's the returning value would be pointer to slice of pointer to models i.e.: type Model struct {}, the result would be returned as a *[]*Model{}
func (*Scope) LanguageFilter ¶
func (s *Scope) LanguageFilter() *filters.FilterField
LanguageFilter returns language filter for given scope
func (*Scope) Limit ¶ added in v0.1.5
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 ommitting the 'Offset' clause.
func (*Scope) List ¶
List gets the values from the repository taking into account the scope filters and parameters
func (*Scope) ListContext ¶
ListContext gets the values from the repository taking into account the scope filters and parameters
func (*Scope) New ¶
New creates new scope for the provided model value. Created scope is a subscope for the scope. If the root scope 's' is on the transacation the new one will be created with the current transaction. It allows to commit or rollback a chain of scopes within a single method usage
func (*Scope) NewContext ¶
NewContext creates new scope for the provided model value. Created scope is a subscope for the scope. If the root scope 's' is on the transacation the new one will be created with the current transaction. It allows to commit or rollback a chain of scopes within a single method usage
func (*Scope) NotSelectedFields ¶
func (s *Scope) NotSelectedFields(withForeigns ...bool) (notSelected []*mapping.StructField)
NotSelectedFields returns all the fields that are not selected
func (*Scope) Pagination ¶
func (s *Scope) Pagination() *Pagination
Pagination returns the pagination for given scope
func (*Scope) Patch ¶
Patch updates the scope's attribute and relationship values with the restrictions provided in the scope's parameters
func (*Scope) PatchContext ¶
PatchContext updates the scope's attribute and relationship values with the restrictions provided in the scope's parameters
func (*Scope) PrimaryFilters ¶
func (s *Scope) PrimaryFilters() []*filters.FilterField
PrimaryFilters returns scope's primary iFilters
func (*Scope) RelationFilters ¶
func (s *Scope) RelationFilters() []*filters.FilterField
RelationFilters returns scope's relation fields iFilters
func (*Scope) RollbackContext ¶
RollbackContext rollsback the transaction for given scope
func (*Scope) SelectField ¶
SelectField selects the field by the name. Selected fields are used in the patching process. By default the selected fields are all non zero valued fields in the struct.
func (*Scope) SelectedFields ¶
func (s *Scope) SelectedFields() (selected []*mapping.StructField)
SelectedFields returns fields selected during
func (*Scope) SetFieldset ¶
SetFieldset sets the fieldset for the provided scope
func (*Scope) SetPagination ¶
func (s *Scope) SetPagination(p *Pagination) error
SetPagination sets the Pagination for the scope.
func (*Scope) SortFields ¶
SortFields returns the sorts used in the scope
func (*Scope) Struct ¶
func (s *Scope) Struct() *mapping.ModelStruct
Struct returns scope's ModelStruct
func (*Scope) ValidateCreate ¶
ValidateCreate validates the scope's value with respect to the 'create validator' and the 'create' validation tags
func (*Scope) ValidatePatch ¶
ValidatePatch validates the scope's value with respect to the 'Patch Validator'
type SortField ¶ added in v0.1.5
SortField is a field that contains sorting information
func (*SortField) FormatQuery ¶ added in v0.1.5
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.1.5
func (s *SortField) StructField() *mapping.StructField
StructField returns sortfield's structure
type SortOrder ¶ added in v0.1.5
type SortOrder int
SortOrder is the enum used for the sorting values
type Transactioner ¶
type Transactioner interface { Beginner Committer Rollbacker }
Transactioner is the interface used for the transactions implementation
type Tx ¶
type Tx struct { ID uuid.UUID `json:"id"` State TxState `json:"state"` Options TxOptions `json:"options"` }
Tx is the scope's defined transaction
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