Documentation
¶
Index ¶
- Variables
- type Repo
- func (r *Repo) Clear(ctx context.Context) error
- func (r *Repo) Close(ctx context.Context)
- func (r *Repo) Collection(ctx context.Context, f func(context.Context, *mongo.Collection) error) error
- func (r *Repo) Find(ctx context.Context, id uuid.UUID) (eh.Entity, error)
- func (r *Repo) FindAll(ctx context.Context) ([]eh.Entity, error)
- func (r *Repo) FindAllWithFilter(ctx context.Context, filter interface{}) ([]eh.Entity, error)
- func (r *Repo) FindCustom(ctx context.Context, ...) ([]interface{}, error)
- func (r *Repo) FindCustomIter(ctx context.Context, ...) (eh.Iter, error)
- func (r *Repo) FindOneCustom(ctx context.Context, ...) (*mongo.SingleResult, error)
- func (r *Repo) FindOneCustomWithFilter(ctx context.Context, filter bson.M) (*mongo.SingleResult, error)
- func (r *Repo) Parent() eh.ReadRepo
- func (r *Repo) Remove(ctx context.Context, id uuid.UUID) error
- func (r *Repo) Save(ctx context.Context, entity eh.Entity) error
- func (r *Repo) SetEntityFactory(f func() eh.Entity)
Constants ¶
This section is empty.
Variables ¶
var ErrCouldNotClearDB = errors.New("could not clear database")
ErrCouldNotClearDB is when the database could not be cleared.
var ErrCouldNotDialDB = errors.New("could not dial database")
ErrCouldNotDialDB is when the database could not be dialed.
var ErrInvalidQuery = errors.New("invalid query")
ErrInvalidQuery is when a query was not returned from the callback to FindCustom.
var ErrModelNotSet = errors.New("model not set")
ErrModelNotSet is when an model factory is not set on the Repo.
var ErrNoDBClient = errors.New("no database client")
ErrNoDBClient is when no database client 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 NewRepoWithClient ¶ added in v0.6.1
NewRepoWithClient creates a new Repo with a client.
func Repository ¶
Repository returns a parent ReadRepo if there is one.
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) FindAll ¶
FindAll implements the FindAll method of the eventhorizon.ReadRepo interface.
func (*Repo) FindAllWithFilter ¶ added in v0.8.1
FindAllWithFilter implements the FindAllWithFilter 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) FindOneCustom ¶ added in v0.7.1
func (r *Repo) FindOneCustom(ctx context.Context, f func(context.Context, *mongo.Collection) *mongo.SingleResult) (*mongo.SingleResult, error)
FindOneCustom returns a mongo single result
func (*Repo) FindOneCustomWithFilter ¶ added in v0.7.1
func (*Repo) SetEntityFactory ¶
SetEntityFactory sets a factory function that creates concrete entity types.