mockdb

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2021 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.Server

New returns a fully initialized Database object

Types

type Collection

type Collection struct {
	Server  *Server
	Context context.Context
	Name    string
}

Collection is a mock database collection

func (Collection) Delete added in v0.3.8

func (collection Collection) Delete(object data.Object, comment string) error

Delete PERMANENTLY removes a record from the mock database.

func (Collection) List added in v0.3.8

func (collection Collection) List(criteria expression.Expression, options ...option.Option) (data.Iterator, error)

List retrieves a group of records as an Iterator.

func (Collection) Load added in v0.3.8

func (collection Collection) Load(criteria expression.Expression, target data.Object) error

Load retrieves a single record from the mock collection.

func (Collection) Save added in v0.3.8

func (collection Collection) Save(object data.Object, comment string) error

Save adds/inserts a new record into the 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() error

Close prevents any further records from being read from the iterator

func (*Iterator) Count added in v0.9.0

func (iterator *Iterator) Count() int

Count returns the total number of records contained in this 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

type Server added in v0.3.6

type Server map[string][]data.Object

Server is a mock database

func (Server) Session added in v0.3.6

func (server Server) Session(ctx context.Context) (data.Session, error)

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

type Session added in v0.3.2

type Session struct {
	Server  *Server
	Context context.Context
}

Session is a mock database session

func (Session) Close added in v0.3.2

func (session Session) Close()

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

func (Session) Collection added in v0.3.8

func (session Session) Collection(collection string) data.Collection

Collection returns a reference to a collection of records

Jump to

Keyboard shortcuts

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