Documentation
¶
Overview ¶
Package mockdb provides a mock implementation of a data store for testing purposes.
Index ¶
- func MatcherFunc(object data.Object) exp.MatcherFunc
- type Collection
- func (collection Collection) Context() context.Context
- func (collection Collection) Count(criteria exp.Expression, _ ...option.Option) (int64, error)
- func (collection Collection) Delete(object data.Object, comment string) error
- func (collection Collection) HardDelete(criteria exp.Expression) error
- func (collection Collection) Iterator(criteria exp.Expression, options ...option.Option) (data.Iterator, error)
- func (collection Collection) Load(criteria exp.Expression, target data.Object, _ ...option.Option) error
- func (collection Collection) Query(_ any, _ exp.Expression, _ ...option.Option) error
- func (collection Collection) Save(object data.Object, comment string) error
- type Iterator
- func (iterator *Iterator) Close() error
- func (iterator *Iterator) Count() int
- func (iterator *Iterator) Error() error
- func (iterator *Iterator) Len() int
- func (iterator *Iterator) Less(i int, j int) bool
- func (iterator *Iterator) Next(output any) bool
- func (iterator *Iterator) Reset()
- func (iterator *Iterator) Swap(i int, j int)
- type Server
- type Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MatcherFunc ¶
func MatcherFunc(object data.Object) exp.MatcherFunc
MatcherFunc is a helper function that uses reflection to look inside a generic data.Object and match it. Because it uses reflection, it should be considered SLOW, and only be used in the mock library.
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection is a mock database collection
func (Collection) Context ¶
func (collection Collection) Context() context.Context
Context returns the context for this collection
func (Collection) Count ¶ added in v0.28.0
func (collection Collection) Count(criteria exp.Expression, _ ...option.Option) (int64, error)
Count returns the number of records in the mock collection that match the criteria.
func (Collection) Delete ¶
func (collection Collection) Delete(object data.Object, comment string) error
Delete soft deletes removes a record from the mock database.
func (Collection) HardDelete ¶ added in v0.1.0
func (collection Collection) HardDelete(criteria exp.Expression) error
HardDelete PERMANENTLY removes records from the mock database that match the criteria.
func (Collection) Iterator ¶ added in v0.28.0
func (collection Collection) Iterator(criteria exp.Expression, options ...option.Option) (data.Iterator, error)
Iterator retrieves a group of records as an Iterator.
func (Collection) Load ¶
func (collection Collection) Load(criteria exp.Expression, target data.Object, _ ...option.Option) error
Load retrieves a single record from the mock collection.
func (Collection) Query ¶ added in v0.2.2
func (collection Collection) Query(_ any, _ exp.Expression, _ ...option.Option) error
Query retrieves multiple records from the mock collection.
type Iterator ¶
Iterator represents a generic set of data that can be returned by a datasource.
func NewIterator ¶
NewIterator returns a fully initialized Iterator over the provided objects.
func (*Iterator) Error ¶ added in v0.21.0
Error returns the most recent error encountered by the iterator (always nil for the mock).
func (*Iterator) Less ¶
Less reports whether the element with index i should sort before the element with index j. A return value of TRUE means that the item in position "i" should appear ahead of the item in position "j".
func (*Iterator) Next ¶
Next moves the Iterator to the next position in the dataset. If there is another record in the dataset, it returns TRUE, and writes the next record to the "output" variable. If there are no more records, it returns FALSE.
type Server ¶
Server is a mock database
func New ¶
func New() *Server
New returns a fully initialized Server. The pointer is the store's identity: every Session and Collection shares it, so writes are visible across them.
func (*Server) WithTransaction ¶ added in v0.31.0
func (server *Server) WithTransaction(ctx context.Context, fn data.TransactionCallbackFunc) (any, error)
WithTransaction executes a callback function within the context of a transaction.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a mock database session
func (Session) Close ¶
func (session Session) Close()
Close cleans up any remaining data created by the mock session.
func (Session) Collection ¶
func (session Session) Collection(collection string) data.Collection
Collection returns a reference to a collection of records