query

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: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

View Source
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,
	}
)
View Source
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,
	}
)
View Source
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,
	}
)
View Source
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,
	}
)
View Source
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,
	}
)
View Source
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,
	}
)
View Source
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")
)
View Source
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

View Source
var ErrNoCreateRepository = errors.New("No create repository for model found.")

ErrNoCreateRepository is thrown when the repository doesn't implement the creator interface

View Source
var (
	// ErrTxAlreadyBegan notifies that the transaction had already began
	ErrTxAlreadyBegan = errors.New("Transaction already began")
)

Functions

func RegisterProcess

func RegisterProcess(p *Process) error

RegisterProcess registers the process. If the process is already registered the function panics

Types

type AfterCreator

type AfterCreator interface {
	HAfterCreate(ctx context.Context, s *Scope) error
}

AfterCreator is the interface that has a method used as a hook after the creation process

type AfterDeleter

type AfterDeleter interface {
	HAfterDelete(ctx context.Context, s *Scope) error
}

AfterDeleter is the interface used as an after delete hook

type AfterGetter

type AfterGetter interface {
	HAfterGet(ctx context.Context, s *Scope) error
}

AfterGetter is the interface used as a hook after getting the value from api

type AfterLister

type AfterLister interface {
	HAfterList(ctx context.Context, s *Scope) error
}

AfterLister is the interface used as a after list hook

type AfterPatcher

type AfterPatcher interface {
	HAfterPatch(ctx context.Context, s *Scope) error
}

AfterPatcher is the interface used as a after patch hook

type BeforeCreator

type BeforeCreator interface {
	HBeforeCreate(ctx context.Context, s *Scope) error
}

BeforeCreator is the interface used for hooks before the creation process

type BeforeDeleter

type BeforeDeleter interface {
	HBeforeDelete(ctx context.Context, s *Scope) error
}

BeforeDeleter is the interface used as a before delete hook

type BeforeGetter

type BeforeGetter interface {
	HBeforeGet(ctx context.Context, s *Scope) error
}

BeforeGetter is the interface used as a hook before gettin value from api

type BeforeLister

type BeforeLister interface {
	HBeforeList(ctx context.Context, s *Scope) error
}

BeforeLister is the interface used for before list hook

type BeforePatcher

type BeforePatcher interface {
	HBeforePatch(ctx context.Context, s *Scope) error
}

BeforePatcher is the interface used as a before patch hook

type Beginner

type Beginner interface {
	Begin(ctx context.Context, s *Scope) error
}

Beginner is the interface used for the distributed transaction to begin

type Committer

type Committer interface {
	Commit(ctx context.Context, s *Scope) error
}

Committer is the interface used for committing the scope's transaction

type Creater

type Creater interface {
	Create(ctx context.Context, s *Scope) error
}

Creater is the repository interface that creates the value within the query.Scope

type Deleter

type Deleter interface {
	Delete(ctx context.Context, s *Scope) error
}

Deleter is the interface for the repositories that deletes provided query value

type FullRepository

type FullRepository interface {
	RepositoryMethoder
	Transactioner
}

FullRepository is the interface that implements both repository methoder and the transactioner intefaces

type Getter

type Getter interface {
	Get(ctx context.Context, s *Scope) error
}

Getter is the repository interface that Gets single query value

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 Lister

type Lister interface {
	List(ctx context.Context, s *Scope) error
}

Lister is the repository interface that Lists provided query values

type Patcher

type Patcher interface {
	Patch(ctx context.Context, s *Scope) error
}

Patcher is the repository interface that patches given query values

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

func (*ProcessChain) Replace

func (c *ProcessChain) Replace(toReplace string, process *Process) error

Replace replaces the process within the ProcessChain

type ProcessFunc

type ProcessFunc func(ctx context.Context, s *Scope) error

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

func (*Processor) Create

func (p *Processor) Create(ctx context.Context, s *scope.Scope) error

Create is the initializes the Create Process Chain for the Scope

func (*Processor) Delete

func (p *Processor) Delete(ctx context.Context, s *scope.Scope) error

Delete does the Delete process chain

func (*Processor) Get

func (p *Processor) Get(ctx context.Context, s *scope.Scope) error

Get initializes the Get Process chain for the scope

func (*Processor) List

func (p *Processor) List(ctx context.Context, s *scope.Scope) error

List initializes the List Process Chain for the scope

func (*Processor) Patch

func (p *Processor) Patch(ctx context.Context, s *scope.Scope) error

Patch does the Patch Process Chain

type RepositoryMethoder

type RepositoryMethoder interface {
	Creater
	Getter
	Lister
	Patcher
	Deleter
}

RepositoryMethoder is an interface that implements all possible repository methods interfaces

type Rollbacker

type Rollbacker interface {
	Rollback(ctx context.Context, s *Scope) error
}

Rollbacker is the interface used for rollbacks the interface transaction

type Scope

type Scope scope.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 New

func New(model interface{}) (*Scope, error)

New creates the scope on the base of the given model

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

func (s *Scope) AddStringFilter(rawFilter string, values ...interface{}) error

AddStringFilter parses the filter into the FilterField and adds to the provided scope's filters

func (*Scope) AddStringSortFields

func (s *Scope) AddStringSortFields(fields ...string) error

AddStringSortFields adds the sort fields in a string form i.e. [-field_1, field_2] -> Descending Field1 and Ascending Field2

func (*Scope) AddToFieldset

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

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

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

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

func (s *Scope) AddTxChain(sub *Scope)

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

func (s *Scope) Begin() error

Begin begins the transaction for the provided scope

func (*Scope) BeginTx

func (s *Scope) BeginTx(ctx context.Context, opts *TxOptions) error

BeginTx begins the transaction with the given tx.Options

func (*Scope) Commit

func (s *Scope) Commit() error

Commit commits the given transaction for the scope

func (*Scope) CommitContext

func (s *Scope) CommitContext(ctx context.Context) error

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

func (s *Scope) Create() error

Create creates the scope values

func (*Scope) CreateContext

func (s *Scope) CreateContext(ctx context.Context) error

CreateContext creates the scope values with the context.Context

func (*Scope) Delete

func (s *Scope) Delete() error

Delete deletes the values provided in the scope's value

func (*Scope) DeleteContext

func (s *Scope) DeleteContext(ctx context.Context) error

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

func (s *Scope) FormatQuery() url.Values

FormatQuery formats the scope's query into the url.Values

func (*Scope) Get

func (s *Scope) Get() error

Get gets single value from the repository taking into account the scope filters and parameters

func (*Scope) GetContext

func (s *Scope) GetContext(ctx context.Context) error

GetContext gets single value from repository taking into account the scope filters, parameters and the context.

func (*Scope) ID

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

ID returns the scope's identity number represented as github.com/google/uuid

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

func (s *Scope) IncludedValue(model interface{}) (interface{}, error)

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

func (s *Scope) List() error

List gets the values from the repository taking into account the scope filters and parameters

func (*Scope) ListContext

func (s *Scope) ListContext(ctx context.Context) error

ListContext gets the values from the repository taking into account the scope filters and parameters

func (*Scope) New

func (s *Scope) New(value interface{}) (*Scope, error)

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

func (s *Scope) NewContext(ctx context.Context, value interface{}) (*Scope, error)

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

Pagination returns the pagination for given scope

func (*Scope) Patch

func (s *Scope) Patch() error

Patch updates the scope's attribute and relationship values with the restrictions provided in the scope's parameters

func (*Scope) PatchContext

func (s *Scope) PatchContext(ctx context.Context) error

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

func (s *Scope) Rollback() error

Rollback rollsback the transaction for given scope

func (*Scope) RollbackContext

func (s *Scope) RollbackContext(ctx context.Context) error

RollbackContext rollsback the transaction for given scope

func (*Scope) SelectField

func (s *Scope) SelectField(name string) error

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

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

SetFieldset sets the fieldset for the provided scope

func (*Scope) SetPagination

func (s *Scope) SetPagination(p *pagination.Pagination) error

SetPagination sets the Pagination for the scope.

func (*Scope) SortBy

func (s *Scope) SortBy(fields ...string) error

SortBy adds the sort fields into given scope

func (*Scope) SortFields

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

SortFields returns the sorts used in the scope

func (*Scope) Struct

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

Struct returns scope's ModelStruct

func (*Scope) Tx

func (s *Scope) Tx() *Tx

Tx returns the transaction for the given scope if exists

func (*Scope) ValidateCreate

func (s *Scope) ValidateCreate() []*errors.ApiError

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.ApiError

ValidatePatch validates the scope's value with respect to the 'Patch Validator'

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

func (s *TxState) MarshalJSON() ([]byte, error)

MarshalJSON marshals the state into string value Implements the json.Marshaler interface

func (TxState) String

func (s TxState) String() string

func (*TxState) UnmarshalJSON

func (s *TxState) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the state from the json string value Implements json.Unmarshaler interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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