spec

package
v0.0.0-...-c19637d Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderingAscending  = "ASC"
	OrderingDescending = "DESC"
)

Ordering constants

Variables

View Source
var (
	ErrQueryRequired        = errors.New("spec: query is required")
	ErrInvalidParam         = errors.New("spec: parameters do not match the query")
	ErrInvalidUpdateFields  = errors.New("spec: update fields are invalid")
	ErrContextParamRequired = errors.New("spec: context parameter is required")
	ErrLimitAmountRequired  = errors.New("spec: limit amount is required")
	ErrLimitNonPositive     = errors.New("spec: limit value must be positive")
	ErrLimitOnFindOne       = errors.New("spec: cannot specify limit on find one")
)

parsing error constants

Functions

func NewArgumentTypeNotMatchedError

func NewArgumentTypeNotMatchedError(fieldName string, requiredType code.Type, givenType code.Type) error

NewArgumentTypeNotMatchedError creates argumentTypeNotMatchedError

func NewIncompatibleComparatorError

func NewIncompatibleComparatorError(comparator Comparator, field code.StructField) error

NewIncompatibleComparatorError creates incompatibleComparatorError

func NewIncompatibleUpdateOperatorError

func NewIncompatibleUpdateOperatorError(updateOperator UpdateOperator, fieldReference FieldReference) error

NewIncompatibleUpdateOperatorError creates incompatibleUpdateOperatorError

func NewInvalidQueryError

func NewInvalidQueryError(queryTokens []string) error

NewInvalidQueryError creates invalidQueryError

func NewInvalidSortError

func NewInvalidSortError(sortTokens []string) error

NewInvalidSortError creates invalidSortError

func NewOperationReturnCountUnmatchedError

func NewOperationReturnCountUnmatchedError(returnCount int) error

NewOperationReturnCountUnmatchedError creates operationReturnCountUnmatchedError.

func NewStructFieldNotFoundError

func NewStructFieldNotFoundError(tokens []string) error

NewStructFieldNotFoundError creates structFieldNotFoundError

func NewUnknownOperationError

func NewUnknownOperationError(operationName string) error

NewUnknownOperationError creates unknownOperationError

func NewUnsupportedReturnError

func NewUnsupportedReturnError(givenType code.Type, index int) error

NewUnsupportedReturnError creates unsupportedReturnError

Types

type Comparator

type Comparator string

Comparator is a comparison operator of the condition to query the data

const (
	ComparatorNot              Comparator = "NOT"
	ComparatorEqual            Comparator = "EQUAL"
	ComparatorLessThan         Comparator = "LESS_THAN"
	ComparatorLessThanEqual    Comparator = "LESS_THAN_EQUAL"
	ComparatorGreaterThan      Comparator = "GREATER_THAN"
	ComparatorGreaterThanEqual Comparator = "GREATER_THAN_EQUAL"
	ComparatorBetween          Comparator = "BETWEEN"
	ComparatorIn               Comparator = "IN"
	ComparatorNotIn            Comparator = "NOT_IN"
	ComparatorTrue             Comparator = "EQUAL_TRUE"
	ComparatorFalse            Comparator = "EQUAL_FALSE"
	ComparatorExists           Comparator = "EXISTS"
	ComparatorNotExists        Comparator = "NOT_EXISTS"
)

comparator types

func (Comparator) ArgumentTypeFromFieldType

func (c Comparator) ArgumentTypeFromFieldType(t code.Type) code.Type

ArgumentTypeFromFieldType returns a type of required argument from the given struct field type.

func (Comparator) NumberOfArguments

func (c Comparator) NumberOfArguments() int

NumberOfArguments returns the number of arguments required to perform the comparison.

type CountOperation

type CountOperation struct {
	Query QuerySpec
}

CountOperation is a method specification for count operations

func (CountOperation) Name

func (o CountOperation) Name() string

Name returns "Count" operation name

type DeleteOperation

type DeleteOperation struct {
	Mode  QueryMode
	Query QuerySpec
}

DeleteOperation is a method specification for delete operations

func (DeleteOperation) Name

func (o DeleteOperation) Name() string

Name returns "Delete" operation name

type FieldReference

type FieldReference []code.StructField

FieldReference is a reference path to access to the field

func (FieldReference) ReferencedField

func (r FieldReference) ReferencedField() code.StructField

ReferencedField returns the last struct field

func (FieldReference) ReferencingCode

func (r FieldReference) ReferencingCode() string

ReferencingCode returns a string containing name of the referenced fields concatenating with period (.).

type FindOperation

type FindOperation struct {
	Mode  QueryMode
	Query QuerySpec
	Sorts []Sort
	Limit int
}

FindOperation is a method specification for find operations

func (FindOperation) Name

func (o FindOperation) Name() string

Name returns "Find" operation name

type InsertOperation

type InsertOperation struct {
	Mode QueryMode
}

InsertOperation is a method specification for insert operations

func (InsertOperation) Name

func (o InsertOperation) Name() string

Name returns "Insert" operation name

type MethodSpec

type MethodSpec struct {
	Name      string
	Params    []code.Param
	Returns   []code.Type
	Operation Operation
}

MethodSpec is a method specification inside repository specification

func ParseInterfaceMethod

func ParseInterfaceMethod(structs map[string]code.Struct, structModel code.Struct,
	method code.Method) (MethodSpec, error)

ParseInterfaceMethod returns repository method spec from declared interface method.

type Operation

type Operation interface {
	Name() string
}

Operation is an interface for any kind of operation

type Operator

type Operator string

Operator is a boolean operator for merging conditions

const (
	OperatorAnd Operator = "AND"
	OperatorOr  Operator = "OR"
)

boolean operator types

type Ordering

type Ordering string

Ordering is a sort order

type Predicate

type Predicate struct {
	FieldReference FieldReference
	Comparator     Comparator
	ParamIndex     int
}

Predicate is a criteria for querying a field

type QueryMode

type QueryMode string

QueryMode one or many

const (
	QueryModeOne  QueryMode = "ONE"
	QueryModeMany QueryMode = "MANY"
)

query mode constants

type QuerySpec

type QuerySpec struct {
	Operator   Operator
	Predicates []Predicate
}

QuerySpec is a set of conditions of querying the database

func (QuerySpec) NumberOfArguments

func (q QuerySpec) NumberOfArguments() int

NumberOfArguments returns number of arguments required to perform the query

type Sort

type Sort struct {
	FieldReference FieldReference
	Ordering       Ordering
}

Sort is a detail of sorting find result

type Update

type Update interface {
	Name() string
	NumberOfArguments() int
}

Update is an interface of update operation type

type UpdateField

type UpdateField struct {
	FieldReference FieldReference
	ParamIndex     int
	Operator       UpdateOperator
}

UpdateField stores mapping between field name in the model and the parameter index.

type UpdateFields

type UpdateFields []UpdateField

UpdateFields is a type of update operation that update specific fields

func (UpdateFields) Name

func (u UpdateFields) Name() string

Name returns UpdateFields name 'Fields'

func (UpdateFields) NumberOfArguments

func (u UpdateFields) NumberOfArguments() int

NumberOfArguments returns number of update fields

type UpdateModel

type UpdateModel struct {
}

UpdateModel is a type of update operation that update the whole model

func (UpdateModel) Name

func (u UpdateModel) Name() string

Name returns UpdateModel name 'Model'

func (UpdateModel) NumberOfArguments

func (u UpdateModel) NumberOfArguments() int

NumberOfArguments returns 1

type UpdateOperation

type UpdateOperation struct {
	Update Update
	Mode   QueryMode
	Query  QuerySpec
}

UpdateOperation is a method specification for update operations

func (UpdateOperation) Name

func (o UpdateOperation) Name() string

Name returns "Update" operation name

type UpdateOperator

type UpdateOperator string

UpdateOperator is a custom type that declares update operator to be used in an update operation

const (
	UpdateOperatorSet  UpdateOperator = "SET"
	UpdateOperatorPush UpdateOperator = "PUSH"
	UpdateOperatorInc  UpdateOperator = "INC"
)

UpdateOperator constants

func (UpdateOperator) ArgumentType

func (o UpdateOperator) ArgumentType(fieldType code.Type) code.Type

ArgumentType returns type that is required for function parameter

func (UpdateOperator) NumberOfArguments

func (o UpdateOperator) NumberOfArguments() int

NumberOfArguments returns number of arguments required to perform an update operation

Jump to

Keyboard shortcuts

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