query

package
v0.5.1 Latest Latest
Warning

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

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

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

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

View Source
const ParamSort = "sort"

ParamSort is the url query parameter name for the sorting fields.

Variables

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

type AfterCreator interface {
	AfterCreate(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 {
	AfterDelete(ctx context.Context, s *Scope) error
}

AfterDeleter is the interface used as an after delete hook.

type AfterGetter

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

AfterGetter is the interface used as a hook after getting the value.

type AfterLister

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

AfterLister is the interface used as a after list hook.

type AfterPatcher

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

AfterPatcher is the interface used as a after patch hook.

type BeforeCreator

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

BeforeCreator is the interface used for hooks before the creation process.

type BeforeDeleter

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

BeforeDeleter is the interface used as a before delete hook.

type BeforeGetter

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

BeforeGetter is the interface used as a hook before getting value.

type BeforeLister

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

BeforeLister is the interface used for before list hook.

type BeforePatcher

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

BeforePatcher is the interface used as a before patch hook.

type Creator added in v0.2.2

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

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

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 defines the processes chain for each of the repository methods.

func (*Processor) Create

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

Create initializes the Create Process Chain for the Scope.

func (*Processor) Delete

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

Delete initializes the Delete Process Chain for the scope 's'.

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 initializes the Patch Process Chain for the scope 's'.

type RepositoryMethoder

type RepositoryMethoder interface {
	Creator
	Getter
	Lister
	Patcher
	Deleter
}

RepositoryMethoder is an interface that implements all possible repository methods interfaces.

type Scope

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

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

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

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

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

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

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

func (s *Scope) Begin() (*Tx, error)

Begin begins the transaction for the provided scope with the default Options.

func (*Scope) BeginTx

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

BeginTx begins the transaction with the given context.Context 'ctx' and Options 'opts'.

func (*Scope) Commit

func (s *Scope) Commit() error

Commit commits the transaction for the scope and it's subscopes.

func (*Scope) CommitContext

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

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

func (s *Scope) Create() error

Create stores the values within the given scope's value repository, by starting the create process.

func (*Scope) CreateContext

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

CreateContext creates the scope values with the provided 'ctx' context.Context.

func (*Scope) Delete

func (s *Scope) Delete() error

Delete deletes the values provided in the query's scope.

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) Filter added in v0.3.0

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

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

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 stored as the UUID.

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

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

IncludeFields adds the included fields into query scope.

func (*Scope) IncludedModelValues added in v0.3.0

func (s *Scope) IncludedModelValues(model interface{}) (map[interface{}]interface{}, error)

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

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

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

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

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

func (s *Scope) Limit(limit, offset int) error

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

func (s *Scope) List() error

List gets the values from the repository taking with respect to the query filters, sorts, pagination and included values.

func (*Scope) ListContext

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

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

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

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

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

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

func (s *Scope) Page(number, size int) error

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

func (s *Scope) Patch() error

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

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

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

func (s *Scope) Rollback() error

Rollback does the transaction rollback process.

func (*Scope) RollbackContext

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

RollbackContext does the transaction rollback process with the given context.Context 'ctx'.

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 selected fields are all non zero valued fields in the struct.

func (*Scope) SelectFields added in v0.2.2

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

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

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

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

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

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

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

Sort adds the sort fields into given scope. If the scope already have sorted fields or the fields are duplicated returns error.

func (*Scope) SortField added in v0.5.1

func (s *Scope) SortField(field interface{}) error

SortField adds the sort 'field' to the scope.

func (*Scope) SortFields

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

SortFields returns the sorts used by the query's scope.

func (*Scope) StoreGet added in v0.2.1

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

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) String added in v0.5.1

func (s *Scope) String() string

String implements fmt.Stringer interface.

func (*Scope) Struct

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

Struct returns scope's model's structure - *mapping.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.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

type SortField sorts.SortField

SortField is a field that contains sorting information.

func NewSort added in v0.5.1

func NewSort(m *mapping.ModelStruct, sort string, disallowFK bool) (*SortField, error)

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

func (s *SortField) FormatQuery(q ...url.Values) url.Values

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) Order added in v0.2.1

func (s *SortField) Order() SortOrder

Order returns sortfield's order.

func (*SortField) String added in v0.5.1

func (s *SortField) String() string

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.

const (
	// AscendingOrder defines the sorting ascending order.
	AscendingOrder SortOrder = iota

	// DescendingOrder defines the sorting descending order.
	DescendingOrder
)

func (SortOrder) String added in v0.2.1

func (o SortOrder) String() string

String implements fmt.Stringer interface.

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) Commit added in v0.2.1

func (t *Tx) Commit() error

Commit commits the transaction.

func (*Tx) CommitContext added in v0.2.1

func (t *Tx) CommitContext(ctx context.Context) error

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.

func (*Tx) Rollback added in v0.2.1

func (t *Tx) Rollback() error

Rollback rolls back the transaction.

func (*Tx) RollbackContext added in v0.2.1

func (t *Tx) RollbackContext(ctx context.Context) error

RollbackContext rollsback the transaction with given 'ctx' context.

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

Jump to

Keyboard shortcuts

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