Documentation ¶
Overview ¶
Package require provides simple constraints to assist with detecting errors in database queries that arise from the wrong number of result (for example no result or too many results).
The errors arising when requirements are not met are Sizer values.
Index ¶
- Constants
- Variables
- func ActualResultSize(err error) (int64, bool)
- func ChainErrorIfExecNotSatisfiedBy(err error, r Requirement, actual int64) error
- func ChainErrorIfQueryNotSatisfiedBy(err error, r Requirement, actual int64) error
- func ErrWrongSize(actualSize int64, format string, args ...interface{}) error
- func ErrorIfExecNotSatisfiedBy(r Requirement, actual int64) error
- func ErrorIfQueryNotSatisfiedBy(r Requirement, actual int64) error
- func IsNotFound(err error) bool
- func IsNotUnique(err error) bool
- type AtLeast
- type Exactly
- type NoMoreThan
- type Quantifier
- type Requirement
- type Sizer
Constants ¶
const ( // All is a requirement that is updated to exactly match some number that is only known at // call time. The generated code accepts this requirement, then substitues for it the // expression 'Exactly(n)', with n being determined automatically. For example, given // a slice of primary keys, a select query that should always match all of them can use // the length of the slice as 'n'. All lateBound = iota )
Variables ¶
var AtLeastOne = AtLeast(1)
AtLeastOne is a requirement that is met by the actual results being at least one, i.e. not empty.
var NoMoreThanOne = NoMoreThan(1)
NoMoreThanOne is a requirement that is met by the actual results being no more than one.
Functions ¶
func ActualResultSize ¶ added in v0.9.0
ActualResultSize tests the error and returns true only if the error is a wrong-size error, in which case it also returns the actual result size.
func ChainErrorIfExecNotSatisfiedBy ¶
func ChainErrorIfExecNotSatisfiedBy(err error, r Requirement, actual int64) error
ChainErrorIfExecNotSatisfiedBy matches a requirement against the actual result size for an exec query. The requirement may be nil in which case there will be no error. This function accepts an existing potential error, passing it on if not nil.
func ChainErrorIfQueryNotSatisfiedBy ¶
func ChainErrorIfQueryNotSatisfiedBy(err error, r Requirement, actual int64) error
ChainErrorIfQueryNotSatisfiedBy matches a requirement against the actual result size for a select query. The requirement may be nil in which case there will be no error. This function accepts an existing potential error, passing it on if not nil.
func ErrWrongSize ¶ added in v0.9.0
ErrWrongSize returns an error based on the actual size received and a message describing the unsatisfied requirement. The returned value is both an error and a Sizer.
func ErrorIfExecNotSatisfiedBy ¶
func ErrorIfExecNotSatisfiedBy(r Requirement, actual int64) error
ErrorIfExecNotSatisfiedBy matches a requirement against the actual result size for an exec query. The requirement may be nil in which case there will be no error.
func ErrorIfQueryNotSatisfiedBy ¶
func ErrorIfQueryNotSatisfiedBy(r Requirement, actual int64) error
ErrorIfQueryNotSatisfiedBy matches a requirement against the actual result size for a select query. The requirement may be nil in which case there will be no error.
func IsNotFound ¶ added in v0.9.0
IsNotFound tests the error and returns true only if the error is a wrong-size error and the actual size less than one.
func IsNotUnique ¶ added in v0.9.0
IsNotUnique tests the error and returns true only if the error is a wrong-size error and the actual size was more than one.
Types ¶
type AtLeast ¶
type AtLeast int64
AtLeast is a requirement that is met by the actual results being at least a specified value.
type Exactly ¶
type Exactly int64
Exactly is a requirement that is met by a number matching exactly.
type NoMoreThan ¶
type NoMoreThan int64
NoMoreThan is a requirement that is met by the actual results being no more than a specified value.
func (NoMoreThan) String ¶ added in v0.9.0
func (n NoMoreThan) String() string
type Quantifier ¶
type Quantifier int64
Quantifier is a requirement that is met by imprecise zero, singular or plural results. The value All will be automatically updated to match exactly some number known at call time.
const ( None Quantifier = iota One Many )
func (Quantifier) String ¶
func (q Quantifier) String() string
type Requirement ¶
type Requirement interface { String() string // contains filtered or unexported methods }
Requirement set an expectation on the outcome of a query.