mockdb

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatcherFunc

func MatcherFunc(object data.Object) expression.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.

func New

func New() data.Datastore

New returns a fully initialized Database object

Types

type Collection

type Collection map[string]data.Object

Collection is a mock table

type Datastore

type Datastore map[string]Collection

Datastore is a mock database

func (*Datastore) Close

func (db *Datastore) Close()

Close cleans up any remaining data created by the mock session.

func (*Datastore) Delete

func (db *Datastore) Delete(collection string, object data.Object, comment string) *derp.Error

Delete PERMANENTLY removes a record from the mock database.

func (*Datastore) List

func (db *Datastore) List(collection string, criteria expression.Expression, options ...option.Option) (data.Iterator, *derp.Error)

List retrieves a group of records as an Iterator.

func (*Datastore) Load

func (db *Datastore) Load(collection string, criteria expression.Expression, target data.Object) *derp.Error

Load retrieves a single record from the mock collection.

func (*Datastore) Save

func (db *Datastore) Save(collection string, object data.Object, comment string) *derp.Error

Save adds/inserts a new record into the mock database

func (*Datastore) Session

func (db *Datastore) Session(ctx context.Context) data.Session

Session returns a session that can be used as a mock database.

type Iterator

type Iterator struct {
	Data    []data.Object
	Options []option.Option
	Counter int
}

Iterator represents a generic set of data that can be returned by a datasource.

func NewIterator

func NewIterator(data []data.Object, options ...option.Option) *Iterator

NewIterator generates

func (*Iterator) Close

func (iterator *Iterator) Close() *derp.Error

Close prevents any further records from being read from the iterator

func (*Iterator) Len

func (iterator *Iterator) Len() int

Len returns the number of elements in the collection.

func (*Iterator) Less

func (iterator *Iterator) Less(i int, j int) bool

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

func (iterator *Iterator) Next(output data.Object) bool

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.

func (*Iterator) Reset

func (iterator *Iterator) Reset()

Reset moves the iterator back to the beginning of the dataaset

func (*Iterator) Swap

func (iterator *Iterator) Swap(i int, j int)

Swpa swpas the elements with indexes i and j

Jump to

Keyboard shortcuts

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