mongodb

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: Apache-2.0 Imports: 12 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCouldNotDialDB is when the database could not be dialed.
	ErrCouldNotDialDB = errors.New("could not dial database")
	// ErrNoDBClient is when no database client is set.
	ErrNoDBClient = errors.New("no database client")
	// ErrCouldNotClearDB is when the database could not be cleared.
	ErrCouldNotClearDB = errors.New("could not clear database")
	// ErrModelNotSet is when an model factory is not set on the Repo.
	ErrModelNotSet = errors.New("model not set")
	// ErrInvalidQuery is when a query was not returned from the callback to FindCustom.
	ErrInvalidQuery = errors.New("invalid query")
)

Functions

This section is empty.

Types

type Option added in v0.7.0

type Option func(*Repo) error

Option is an option setter used to configure creation.

type Repo

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

Repo implements an MongoDB repository for entities.

func IntoRepo added in v0.14.0

func IntoRepo(ctx context.Context, repo eh.ReadRepo) *Repo

IntoRepo tries to convert a eh.ReadRepo into a Repo by recursively looking at inner repos. Returns nil if none was found.

func NewRepo

func NewRepo(uri, db, collection string, options ...Option) (*Repo, error)

NewRepo creates a new Repo.

func NewRepoWithClient added in v0.6.0

func NewRepoWithClient(client *mongo.Client, db, collection string, options ...Option) (*Repo, error)

NewRepoWithClient creates a new Repo with a client.

func (*Repo) Clear

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

Clear clears the read model database.

func (*Repo) Close

func (r *Repo) Close(ctx context.Context)

Close closes a database session.

func (*Repo) Collection

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

Collection lets the function do custom actions on the collection.

func (*Repo) CreateIndex added in v0.14.1

func (r *Repo) CreateIndex(ctx context.Context, field string) error

CreateIndex creates an index for a field.

func (*Repo) Find

func (r *Repo) Find(ctx context.Context, id uuid.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, f func(context.Context, *mongo.Collection) (*mongo.Cursor, error)) ([]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, f func(context.Context, *mongo.Collection) (*mongo.Cursor, error)) (eh.Iter, error)

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

func (*Repo) InnerRepo added in v0.14.0

func (r *Repo) InnerRepo(ctx context.Context) eh.ReadRepo

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

func (*Repo) Remove

func (r *Repo) Remove(ctx context.Context, id uuid.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