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 RegisterMultipleOperators(operators ...*Operator) error
- func RegisterOperator(o *Operator) error
- func SplitBracketParameter(bracketed string) (values []string, err error)
- type AfterDeleter
- type AfterFinder
- type AfterInserter
- type AfterUpdater
- type BeforeDeleter
- type BeforeInserter
- type BeforeUpdater
- type Builder
- type CRUDRepository
- type Counter
- type Creator
- type DB
- type Deleter
- type Exister
- type Factory
- type FilterField
- func NewFilter(model interface{}, filter string, values ...interface{}) (*FilterField, error)
- func NewFilterC(c *controller.Controller, model interface{}, filter string, ...) (*FilterField, error)
- func NewFilterField(field *mapping.StructField, op *Operator, values ...interface{}) *FilterField
- func NewStringFilterWithForeignKey(c *controller.Controller, filter string, values ...interface{}) (*FilterField, error)
- func NewURLStringFilter(c *controller.Controller, filter string, values ...interface{}) (*FilterField, error)
- type Filters
- type Finder
- type FullRepository
- type IncludedRelation
- type Inserter
- type IsolationLevel
- type Operator
- type OperatorValues
- type Pagination
- func (p *Pagination) First() (*Pagination, error)
- func (p *Pagination) FormatQuery(q ...url.Values) url.Values
- func (p *Pagination) IsZero() bool
- func (p *Pagination) Last(total int64) (*Pagination, error)
- func (p *Pagination) Next(total int64) (*Pagination, error)
- func (p *Pagination) Previous() (*Pagination, error)
- func (p *Pagination) String() string
- func (p *Pagination) Validate() error
- type Repository
- func (_m *Repository) Begin(ctx context.Context, tx *Tx) error
- func (_m *Repository) Close(context.Context) error
- func (_m *Repository) Commit(ctx context.Context, tx *Tx) error
- func (_m *Repository) Count(ctx context.Context, s *Scope) (int64, error)
- func (_m *Repository) Delete(ctx context.Context, s *Scope) (int64, error)
- func (_m *Repository) Dial(context.Context) error
- func (_m *Repository) Exists(ctx context.Context, s *Scope) (bool, error)
- func (_m *Repository) FactoryName() string
- func (_m *Repository) Find(ctx context.Context, s *Scope) error
- func (_m *Repository) HealthCheck(context.Context) (*repository.HealthResponse, error)
- func (_m *Repository) ID() string
- func (_m *Repository) Insert(ctx context.Context, s *Scope) error
- func (_m *Repository) RegisterModels(...*mapping.ModelStruct) error
- func (_m *Repository) Rollback(ctx context.Context, tx *Tx) error
- func (_m *Repository) Update(ctx context.Context, s *Scope) (int64, error)
- type Scope
- func (s *Scope) AutoSelectedFields() bool
- func (s *Scope) ClearFilters()
- func (s *Scope) Copy() *Scope
- func (s *Scope) Count(ctx context.Context) (int64, error)
- func (s *Scope) DB() DB
- func (s *Scope) Delete(ctx context.Context) (int64, error)
- func (s *Scope) Exists(ctx context.Context) (bool, error)
- func (s *Scope) Filter(filter *FilterField) error
- func (s *Scope) Find(ctx context.Context) ([]mapping.Model, error)
- func (s *Scope) FormatQuery() url.Values
- func (s *Scope) Get(ctx context.Context) (mapping.Model, error)
- func (s *Scope) ID() uuid.UUID
- func (s *Scope) Include(relation *mapping.StructField, relationFieldset ...*mapping.StructField) error
- func (s *Scope) Insert(ctx context.Context) (err error)
- func (s *Scope) Limit(limit int64)
- func (s *Scope) Offset(offset int64)
- func (s *Scope) OrderBy(fields ...string) error
- func (s *Scope) OrderedFieldset() (ordered mapping.OrderedFieldset)
- func (s *Scope) Select(fields ...*mapping.StructField) error
- func (s *Scope) SortField(field interface{}) error
- 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) Update(ctx context.Context) (modelsAffected int64, err error)
- func (s *Scope) Where(filter string, values ...interface{}) error
- type SortField
- type SortOrder
- type Transaction
- type Transactioner
- type Tx
- func (t *Tx) Commit() error
- func (t *Tx) Controller() *controller.Controller
- func (t *Tx) Err() error
- func (t *Tx) ID() uuid.UUID
- func (t *Tx) Options() TxOptions
- func (t *Tx) Query(model *mapping.ModelStruct, models ...mapping.Model) Builder
- func (t *Tx) QueryCtx(ctx context.Context, model *mapping.ModelStruct, models ...mapping.Model) Builder
- func (t *Tx) Rollback() error
- func (t *Tx) State() TxState
- type TxOptions
- type TxState
- type Updater
- type Upserter
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 ( // ParamLanguage is the language query parameter used in the url values. ParamLanguage = "lang" // ParamFilter is the filter query parameter used as the key in the url values. ParamFilter = "filter" )
const ( // ParamPage is a JSON API query parameter used as for pagination. ParamPage = "page" // 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]" )
Pagination defined constants used for formatting the query.
const ParamSort = "sort"
ParamSort is the url query parameter name for the sorting fields.
Variables ¶
var ( // MjrQuery is the major error classification for the query package. MjrQuery errors.Major // ClassInternal is the internal error classification. ClassInternal errors.Class // ClassNoResult is the error classification when for the query that returns no result. ClassNoResult errors.Class // MnrInput is the minor error classification related to the query input. MnrInput errors.Minor // ClassInvalidInput is the error classification for invalid query input. ClassInvalidInput errors.Class // ClassInvalidSort is the error classification for invalid sort input. ClassInvalidSort errors.Class // ClassInvalidModels is the error classification for the invalid models input. ClassInvalidModels errors.Class // ClassInvalidField is the error classification for the invalid field input ClassInvalidField errors.Class // ClassNoModels is the error classification when there is models provided in the input. ClassNoModels errors.Class // MnrFilter is the minor error classification related to the filters. MnrFilter errors.Minor // ClassFilterField is the error classification for the filter fields. ClassFilterField errors.Class // ClassFilterFormat is the error classification for the filter format. ClassFilterFormat errors.Class // ClassFilterCollection is the error classification for the filter collection. ClassFilterCollection errors.Class // MnrTransaction is minor error classification for the query transactions. MnrTransaction errors.Minor // ClassTxDone is the classification for finished transactions. ClassTxDone errors.Class // ClassTxState is the classification for the transaction state. ClassTxState errors.Class )
var ( OpEqual = &Operator{Value: "=", URLAlias: "$eq", Name: "Equal", Aliases: []string{"=="}} OpIn = &Operator{Value: "in", URLAlias: "$in", Name: "In"} OpNotEqual = &Operator{Value: "!=", URLAlias: "$ne", Name: "NotEqual", Aliases: []string{"<>"}} OpNotIn = &Operator{Value: "not in", URLAlias: "$not_in", Name: "NotIn"} OpGreaterThan = &Operator{Value: ">", URLAlias: "$gt", Name: "GreaterThan"} OpGreaterEqual = &Operator{Value: ">=", URLAlias: "$ge", Name: "GreaterThanOrEqualTo"} OpLessThan = &Operator{Value: "<", URLAlias: "$lt", Name: "LessThan"} OpLessEqual = &Operator{Value: "<=", URLAlias: "$le", Name: "LessThanOrEqualTo"} )
Logical Operators
var ( OpContains = &Operator{Value: "contains", URLAlias: "$contains", Name: "Contains"} OpStartsWith = &Operator{Value: "starts with", URLAlias: "$starts_with", Name: "StartsWith"} OpEndsWith = &Operator{Value: "ends with", URLAlias: "$ends_with", Name: "EndsWith"} )
Strings Only operators.
var ( OpIsNull = &Operator{Value: "is null", URLAlias: "$is_null", Name: "IsNull"} OpNotNull = &Operator{Value: "not null", URLAlias: "$not_null", Name: "NotNull"} )
Null and Existence operators.
var FilterOperators = newOpContainer()
FilterOperators is the container that stores all query filter operators.
Functions ¶
func RegisterMultipleOperators ¶ added in v0.15.0
RegisterMultipleOperators registers multiple operators at once
func RegisterOperator ¶ added in v0.15.0
RegisterOperator registers the operator in the provided container
func SplitBracketParameter ¶ added in v0.15.0
SplitBracketParameter splits the parameters within the '[' and ']' brackets.
Types ¶
type AfterDeleter ¶
AfterDeleter is the interface used as an after delete hook.
type AfterFinder ¶ added in v0.15.0
AfterFinder is the interface used as a after find hook.
type AfterInserter ¶ added in v0.15.0
AfterInserter is the interface that has a method used as a hook after the creation process.
type AfterUpdater ¶ added in v0.15.0
AfterUpdater is the interface used as a after patch hook.
type BeforeDeleter ¶
BeforeDeleter is the interface used as a before delete hook.
type BeforeInserter ¶ added in v0.15.0
BeforeInserter is the interface used for hooks before the creation process.
type BeforeUpdater ¶ added in v0.15.0
BeforeUpdater is the interface used as a before patch hook.
type Builder ¶ added in v0.15.0
type Builder interface { Scope() *Scope Err() error Ctx() context.Context Count() (int64, error) Insert() error Update() (int64, error) Exists() (bool, error) Get() (mapping.Model, error) Find() ([]mapping.Model, error) Delete() (int64, error) Select(fields ...*mapping.StructField) Builder Where(filter string, values ...interface{}) Builder Include(relation *mapping.StructField, relationFieldset ...*mapping.StructField) Builder OrderBy(fields ...*SortField) Builder Limit(limit int64) Builder Offset(offset int64) Builder Filter(filter *FilterField) Builder AddRelations(relationField *mapping.StructField, relations ...mapping.Model) error SetRelations(relationField *mapping.StructField, relations ...mapping.Model) error RemoveRelations(relationField *mapping.StructField) (int64, error) }
Builder is the interface used to build queries.
type CRUDRepository ¶ added in v0.15.0
CRUDRepository is an interface that implements all possible repository methods interfaces.
type Counter ¶ added in v0.15.0
Counter is the interface used for query repositories that allows to count the result number for the provided query.
type Creator ¶ added in v0.15.0
type Creator struct {
// contains filtered or unexported fields
}
Creator is the default query composer that implements DB interface.
func NewComposer ¶ added in v0.15.0
func NewComposer(c *controller.Controller) *Creator
NewComposer creates new query composer.
func (*Creator) Controller ¶ added in v0.15.0
func (c *Creator) Controller() *controller.Controller
Controller implements DB interface.
type DB ¶ added in v0.15.0
type DB interface { // Controller gets current controller. Controller() *controller.Controller // Query creates a new query for provided 'model'. Query(model *mapping.ModelStruct, models ...mapping.Model) Builder // QueryCtx creates a new query for provided 'model'. The query should take a context on it's QueryCtx(ctx context.Context, model *mapping.ModelStruct, models ...mapping.Model) Builder }
DB is the common interface that allows to do the queries.
type Exister ¶ added in v0.15.0
Exister is the interface used to check if given query object exists.
type Factory ¶ added in v0.15.0
Factory is the repository.Factory mock implementation
func (*Factory) DriverName ¶ added in v0.15.0
DriverName returns the factory repository name Implements repository.Repository
func (*Factory) New ¶ added in v0.15.0
func (f *Factory) New(*config.Repository) (repository.Repository, error)
New creates new repository Implements repository.Factory method
type FilterField ¶ added in v0.15.0
type FilterField struct { StructField *mapping.StructField // Models are the filter values for given attribute Filter Values []OperatorValues // Nested are the relationship fields filters. Nested []*FilterField }
FilterField is a struct that keeps information about given query filters. It is based on the mapping.StructField.
func NewFilter ¶ added in v0.15.0
func NewFilter(model interface{}, filter string, values ...interface{}) (*FilterField, error)
NewFilter creates new filterField for the default controller, 'model', 'filter' query and 'values'. The 'filter' should be of form:
- Field Operator 'ID IN', 'Name CONTAINS', 'id in', 'name contains'
- Relationship.Field Operator 'Car.UserID IN', 'Car.Doors ==', 'car.user_id >=",
The field might be a Golang model field name or the neuron name.
func NewFilterC ¶ added in v0.15.0
func NewFilterC(c *controller.Controller, model interface{}, filter string, values ...interface{}) (*FilterField, error)
NewFilterC creates new filterField for the controller 'c', 'model', 'filter' query and 'values'. The 'filter' should be of form:
- Field Operator 'ID IN', 'Name CONTAINS', 'id in', 'name contains'
- Relationship.Field Operator 'Car.UserID IN', 'Car.Doors ==', 'car.user_id >=",
The field might be a Golang model field name or the neuron name.
func NewFilterField ¶ added in v0.15.0
func NewFilterField(field *mapping.StructField, op *Operator, values ...interface{}) *FilterField
NewFilterField creates new filterField for given 'field', operator and 'values'.
func NewStringFilterWithForeignKey ¶ added in v0.15.0
func NewStringFilterWithForeignKey(c *controller.Controller, filter string, values ...interface{}) (*FilterField, error)
NewStringFilterWithForeignKey creates the filter field based on the provided filter, schemaName and values. Example:
- 'fitler': "filter[collection][fieldName][operator]"
- 'schema': "schemaName"
- 'values': 5, 13
This function allow to filter over the foreign key fields.
func NewURLStringFilter ¶ added in v0.15.0
func NewURLStringFilter(c *controller.Controller, filter string, values ...interface{}) (*FilterField, error)
NewURLStringFilter creates the filter field based on the provided 'filter' and 'values' in the 'url' format. Example:
- 'filter': "[collection][fieldName][operator]"
- 'values': 5, 13
This function doesn't allow to filter over foreign keys.
func (*FilterField) Copy ¶ added in v0.15.0
func (f *FilterField) Copy() *FilterField
Copy returns the copy of the filter field.
func (*FilterField) FormatQuery ¶ added in v0.15.0
func (f *FilterField) FormatQuery(q ...url.Values) url.Values
FormatQuery formats the filter field into url.Models. If the 'q' optional parameter is set, then the function would add the values into the provided argument 'q' url.Models. Otherwise it creates new url.Models. Returns updated (new) url.Models.
func (*FilterField) String ¶ added in v0.15.0
func (f *FilterField) String() string
String implements fmt.Stringer interface.
type Filters ¶ added in v0.15.0
type Filters []*FilterField
Filters is the wrapper over the slice of filter fields.
type FullRepository ¶
type FullRepository interface { CRUDRepository Transactioner }
FullRepository is the interface that implements both repository CRUDRepository and the transactioner interfaces.
type IncludedRelation ¶ added in v0.15.0
type IncludedRelation struct { StructField *mapping.StructField Fieldset mapping.FieldSet IncludedRelations []*IncludedRelation }
IncludedRelation is the includes information scope it contains the field to include from the root scope related subScope, and subfields to include.
type Inserter ¶ added in v0.15.0
Inserter is the repository interface that creates the value within the query.Scope.
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 unmarshal isolation level from the provided data Implements json.Unmarshaler
type Operator ¶ added in v0.15.0
type Operator struct { // ID is the filter operator id used for comparing the operator type. ID uint16 // Models is the operator query value Value string // Name is the human readable filter operator name. Name string // URLAlias is the alias value for the url parsable value operator. URLAlias string // Aliases is the alias for the operator raw value. Aliases []string }
Operator is the operator used for filtering the query.
func (*Operator) IsBasic ¶ added in v0.15.0
IsBasic checks if the operator is 'OpEqual' or OpNotEqual.
func (*Operator) IsRangeable ¶ added in v0.15.0
IsRangeable checks if the operator allows to have value ranges.
func (*Operator) IsStandard ¶ added in v0.15.0
IsStandard checks if the operator is standard.
func (*Operator) IsStringOnly ¶ added in v0.15.0
IsStringOnly checks if the operator is 'string only'.
type OperatorValues ¶ added in v0.15.0
type OperatorValues struct { Values []interface{} Operator *Operator }
OperatorValues is a struct that holds the Operator with the filter values.
type Pagination ¶ added in v0.1.5
type Pagination struct { // Limit is a pagination value that defines 'limit' or 'page size' Limit int64 // Offset is a pagination value that defines 'offset' or 'page number' Offset int64 }
Pagination defines the query limits and offsets. It defines the maximum size (Limit) as well as an offset at which the query should start. If the pagination type is 'LimitOffsetPagination' the value of 'Limit' defines the 'limit' where the value of 'Offset' defines it's 'offset'. If the pagination type is 'PageNumberPagination' the value of 'Limit' defines 'pageSize' and the value of 'Offset' defines 'pageNumber'. The page number value starts from '1'.
func (*Pagination) First ¶ added in v0.15.0
func (p *Pagination) First() (*Pagination, error)
First gets the first pagination for provided 'p' pagination values. If the 'p' pagination is already the 'first' pagination the function returns it as the result directly.
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) IsZero ¶ added in v0.15.0
func (p *Pagination) IsZero() bool
IsZero checks if the pagination is zero valued.
func (*Pagination) Last ¶ added in v0.15.0
func (p *Pagination) Last(total int64) (*Pagination, error)
Last gets the last pagination for the provided 'total' count. Returns error if current pagination is not valid, or 'total'. If current pagination 'p' is the last pagination it would be return directly as the result. In order to check if the 'p' is last pagination compare it's pointer with the 'p'.
func (*Pagination) Next ¶ added in v0.15.0
func (p *Pagination) Next(total int64) (*Pagination, error)
Next gets the next pagination for the provided 'total' count. If current pagination 'p' is the last one, then the function returns 'p' pagination directly. In order to check if there is a next pagination compare the result pointer with the 'p' pagination.
func (*Pagination) Previous ¶ added in v0.15.0
func (p *Pagination) Previous() (*Pagination, error)
Previous gets the pagination for the previous possible size and offset. If current pagination 'p' is the first page then the function returns 'p' pagination. If the previous size would overflow the 0th offset then the previous starts from 0th offset.
func (*Pagination) String ¶ added in v0.1.5
func (p *Pagination) String() string
String implements fmt.Stringer interface.
func (*Pagination) Validate ¶ added in v0.15.0
func (p *Pagination) Validate() error
Validate checks if the pagination is well formed.
type Repository ¶ added in v0.15.0
Repository is an autogenerated mock type for the Repository type
func (*Repository) Begin ¶ added in v0.15.0
func (_m *Repository) Begin(ctx context.Context, tx *Tx) error
Begin provides a mock function with given fields: TransactionCtx, s
func (*Repository) Close ¶ added in v0.15.0
func (_m *Repository) Close(context.Context) error
Close closes the repository connection
func (*Repository) Commit ¶ added in v0.15.0
func (_m *Repository) Commit(ctx context.Context, tx *Tx) error
Commit provides a mock function with given fields: TransactionCtx, s
func (*Repository) Count ¶ added in v0.15.0
Count provides a mock function with given fields: TransactionCtx, s
func (*Repository) Delete ¶ added in v0.15.0
Delete provides a mock function with given fields: TransactionCtx, s
func (*Repository) Dial ¶ added in v0.15.0
func (_m *Repository) Dial(context.Context) error
Dial implements repository.Repository
func (*Repository) Exists ¶ added in v0.15.0
Exists provides a mock function with given fields: TransactionCtx, s
func (*Repository) FactoryName ¶ added in v0.15.0
func (_m *Repository) FactoryName() string
FactoryName provides a mock function that implements FactoryName method.
func (*Repository) Find ¶ added in v0.15.0
func (_m *Repository) Find(ctx context.Context, s *Scope) error
Find provides a mock function with given fields: TransactionCtx, s
func (*Repository) HealthCheck ¶ added in v0.15.0
func (_m *Repository) HealthCheck(context.Context) (*repository.HealthResponse, error)
HealthCheck implements repository.Repository.
func (*Repository) ID ¶ added in v0.15.0
func (_m *Repository) ID() string
ID implements repository.Repository interface.
func (*Repository) Insert ¶ added in v0.15.0
func (_m *Repository) Insert(ctx context.Context, s *Scope) error
Insert provides a mock function with given fields: TransactionCtx, s
func (*Repository) RegisterModels ¶ added in v0.15.0
func (_m *Repository) RegisterModels(...*mapping.ModelStruct) error
RegisterModels implements repository.Repository interface.
type Scope ¶
type Scope struct { // Models are the models values used within the context of this query. Models []mapping.Model // Fieldset represents fieldset defined for the whole scope of this query. Fieldset mapping.FieldSet // ModelsFieldsets are the fieldsets stored for the batch processes. This values are set only when the // main fieldset is not defined for the query. ModelsFieldsets []mapping.FieldSet // Filters contains all filters for given query. Filters Filters // SortingOrder are the query sort fields. SortingOrder []*SortField // IncludedRelations contain fields to include. If the included field is a relationship type, then // specific included field contains information about it IncludedRelations []*IncludedRelation // Pagination is the query pagination. Pagination *Pagination // Transaction is current scope's transaction. Transaction *Transaction // contains filtered or unexported fields }
Scope is the query's structure that contains information required for the processor to operate. The scope has its unique 'ID', contains predefined model, operational value, fieldset, filters, sorts and pagination. It also contains the mapping of the included scopes.
func NewScope ¶ added in v0.15.0
func NewScope(db DB, model *mapping.ModelStruct) *Scope
NewScope creates the scope for the provided model with respect to the provided internalController 'c'.
func (*Scope) AutoSelectedFields ¶ added in v0.15.0
AutoSelectedFields checks if the scope fieldset was set automatically. This function returns false if a user had defined any field in the Fieldset.
func (*Scope) ClearFilters ¶ added in v0.15.0
func (s *Scope) ClearFilters()
ClearFilters clears all scope filters.
func (*Scope) Count ¶ added in v0.15.0
Count returns the number of all model instances in the repository that matches given query.
func (*Scope) Exists ¶ added in v0.15.0
Exists returns true or false depending if there are any rows matching the query.
func (*Scope) Filter ¶ added in v0.15.0
func (s *Scope) Filter(filter *FilterField) error
Filter adds the filter field to the given query.
func (*Scope) Find ¶ added in v0.15.0
Find gets the values from the repository taking with respect to the query filters, sorts, pagination and included values. Provided context.Context 'TransactionCtx' would be used while querying the repositories.
func (*Scope) FormatQuery ¶
FormatQuery formats the scope's query into the url.Models.
func (*Scope) Get ¶
Get gets single value from the repository taking into account the scope filters and parameters.
func (*Scope) Include ¶ added in v0.15.0
func (s *Scope) Include(relation *mapping.StructField, relationFieldset ...*mapping.StructField) error
Include includes 'relation' field in the scope's query results.
func (*Scope) Insert ¶ added in v0.15.0
Insert stores the values within the given scope's value repository.
func (*Scope) Limit ¶ added in v0.1.5
Limit sets the maximum number of objects returned by the Find process, Returns error if the given scope has already different type of pagination.
func (*Scope) Offset ¶ added in v0.15.0
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. Returns error if the given scope has already different type of pagination.
func (*Scope) OrderBy ¶ added in v0.15.0
OrderBy adds the sort fields into given scope. If the scope already have sorted fields the function appends newly created sort fields. If the fields are duplicated returns error.
func (*Scope) OrderedFieldset ¶ added in v0.15.0
func (s *Scope) OrderedFieldset() (ordered mapping.OrderedFieldset)
OrderedFieldset gets the fieldset fields sorted by the struct field's index.
func (*Scope) Select ¶ added in v0.15.0
func (s *Scope) Select(fields ...*mapping.StructField) error
Select 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) StoreGet ¶ added in v0.15.0
StoreGet gets the value from the scope's Store for given 'key'.
func (*Scope) StoreSet ¶ added in v0.15.0
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) Where ¶ added in v0.15.0
Where parses the filter into the and adds it to the given scope. The 'filter' should be of form:
- Field Operator 'ID IN', 'Name CONTAINS', 'id in', 'name contains'
- Relationship.Field Operator 'Car.UserID IN', 'Car.Doors ==', 'car.user_id >=",
The field might be a Golang model field name or the neuron name.
type SortField ¶ added in v0.1.5
type SortField struct { StructField *mapping.StructField // Order defines if the sorting order (ascending or descending) Order SortOrder // SubFields are the relationship sub field sorts SubFields []*SortField }
SortField is a field that contains sorting information.
func NewSort ¶ added in v0.15.0
func NewSort(m *mapping.ModelStruct, sort string, disallowFK bool, order ...SortOrder) (*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 OrderBy field of foreign key field.
func NewSortFields ¶ added in v0.15.0
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.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 provided url.Models. Otherwise it creates new url.Models instance. Returns modified url.Models
type SortOrder ¶ added in v0.1.5
type SortOrder int
SortOrder is the enum used as the sorting values order.
type Transaction ¶ added in v0.15.0
type Transaction struct { ID uuid.UUID `json:"id"` Ctx context.Context `json:"context"` State TxState `json:"state"` Options *TxOptions `json:"options"` }
Transaction is the structure that defines the query transaction.
type Transactioner ¶
type Transactioner interface { ID() string // Begin the scope's transaction. Begin(ctx context.Context, tx *Tx) error // Commit the scope's transaction. Commit(ctx context.Context, tx *Tx) error // Rollback the scope's transaction. Rollback(ctx context.Context, tx *Tx) error }
Transactioner is the interface used for the transactions.
type Tx ¶
type Tx struct { Transaction *Transaction // contains filtered or unexported fields }
Tx is an in-progress transaction orm. A transaction must end with a call to Commit or Rollback. After a call to Commit or Rollback all operations on the transaction fail with an error of class
func Begin ¶ added in v0.15.0
func Begin(ctx context.Context, c *controller.Controller, options *TxOptions) *Tx
Begin startsC new transaction with respect to the 'Transaction.Ctx' context and transaction TransactionOptions 'TransactionOptions' and controller 'c'.
func (*Tx) Controller ¶ added in v0.15.0
func (t *Tx) Controller() *controller.Controller
Controller returns transaction controller.
func (*Tx) Query ¶ added in v0.15.0
Query builds up a new query for given 'model'. The query is executed using transaction context.
func (*Tx) QueryCtx ¶ added in v0.15.0
func (t *Tx) QueryCtx(ctx context.Context, model *mapping.ModelStruct, models ...mapping.Model) Builder
QueryCtx builds up a new query for given 'model'. The query is executed using transaction context - provided context is used only for Builder purpose.
type TxOptions ¶
type TxOptions struct { Isolation IsolationLevel `json:"isolation"` ReadOnly bool `json:"read_only"` }
TxOptions are the TransactionOptions for the Transaction
type TxState ¶
type TxState int
TxState defines the current transaction Transaction.State
func (*TxState) MarshalJSON ¶
MarshalJSON marshals the Transaction.State into string value Implements the json.Marshaler interface
func (*TxState) UnmarshalJSON ¶
UnmarshalJSON unmarshal the Transaction.State from the json string value Implements json.Unmarshaler interface
Source Files
¶
- brackets.go
- builder.go
- classes.go
- common.go
- const.go
- creator.go
- delete.go
- doc.go
- filter-operators.go
- filters.go
- find.go
- hooks.go
- included.go
- insert.go
- mock_tests.go
- pagination.go
- process-filters.go
- relations.go
- repository-methods.go
- scope-fieldset.go
- scope-filters.go
- scope-sorts.go
- scope.go
- sorts.go
- transaction-builder.go
- tx.go
- update.go