mongodb

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCouldNotClearDB = errors.New("could not clear database")

ErrCouldNotClearDB is when the database could not be cleared.

View Source
var ErrCouldNotDialDB = errors.New("could not dial database")

ErrCouldNotDialDB is when the database could not be dialed.

View Source
var ErrInvalidQuery = errors.New("invalid query")

ErrInvalidQuery is when a query was not returned from the callback to FindCustom.

View Source
var ErrModelNotSet = errors.New("model not set")

ErrModelNotSet is when an model factory is not set on the Repo.

View Source
var ErrNoDBSession = errors.New("no database session")

ErrNoDBSession is when no database session is set.

Functions

This section is empty.

Types

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

Repo implements an MongoDB repository for entities.

func NewRepo

func NewRepo(url, dbPrefix, collection string) (*Repo, error)

NewRepo creates a new Repo.

func NewRepoWithSession

func NewRepoWithSession(session *mgo.Session, dbPrefix, collection string) (*Repo, error)

NewRepoWithSession creates a new Repo with a session.

func Repository

func Repository(repo eh.ReadRepo) *Repo

Repository returns a parent ReadRepo if there is one.

func (*Repo) Clear

func (r *Repo) Clear(ctx context.Context) error

Clear clears the read model database.

func (*Repo) Close

func (r *Repo) Close()

Close closes a database session.

func (*Repo) Collection

func (r *Repo) Collection(ctx context.Context, f func(*mgo.Collection) error) error

Collection lets the function do custom actions on the collection.

func (*Repo) Find

func (r *Repo) Find(ctx context.Context, id eh.UUID) (eh.Entity, error)

Find implements the Find method of the eventhorizon.ReadRepo interface.

func (*Repo) FindAll

func (r *Repo) FindAll(ctx context.Context) ([]eh.Entity, error)

FindAll implements the FindAll method of the eventhorizon.ReadRepo interface.

func (*Repo) FindCustom

func (r *Repo) FindCustom(ctx context.Context, callback func(*mgo.Collection) *mgo.Query) ([]interface{}, error)

FindCustom uses a callback to specify a custom query for returning models. It can also be used to do queries that does not map to the model by executing the query in the callback and returning nil to block a second execution of the same query in FindCustom. Expect a ErrInvalidQuery if returning a nil query from the callback.

func (*Repo) FindCustomIter

func (r *Repo) FindCustomIter(ctx context.Context, callback func(*mgo.Collection) *mgo.Query) (eh.Iter, error)

FindCustomIter returns a mgo cursor you can use to stream results of very large datasets

func (*Repo) Parent

func (r *Repo) Parent() eh.ReadRepo

Parent implements the Parent method of the eventhorizon.ReadRepo interface.

func (*Repo) Remove

func (r *Repo) Remove(ctx context.Context, id eh.UUID) error

Remove implements the Remove method of the eventhorizon.WriteRepo interface.

func (*Repo) Save

func (r *Repo) Save(ctx context.Context, entity eh.Entity) error

Save implements the Save method of the eventhorizon.WriteRepo interface.

func (*Repo) SetEntityFactory

func (r *Repo) SetEntityFactory(f func() eh.Entity)

SetEntityFactory sets a factory function that creates concrete entity types.

Jump to

Keyboard shortcuts

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