Documentation ¶
Index ¶
- Variables
- type Option
- type Repo
- func (r *Repo) Clear(ctx context.Context) error
- func (r *Repo) Close() error
- func (r *Repo) Collection(ctx context.Context, f func(context.Context, *mongo.Collection) error) error
- func (r *Repo) CreateIndex(ctx context.Context, field string) 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) FindCustom(ctx context.Context, ...) ([]interface{}, error)
- func (r *Repo) FindCustomIter(ctx context.Context, ...) (eh.Iter, error)
- func (r *Repo) FindOneCustom(ctx context.Context, ...) (eh.Entity, error)
- func (r *Repo) InnerRepo(ctx context.Context) 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 ( // ErrModelNotSet is when a model factory is not set on the Repo. ErrModelNotSet = errors.New("model not set") // ErrNoCursor is when a provided callback function returns a nil cursor. ErrNoCursor = errors.New("no cursor") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
Option is an option setter used to configure creation.
func WithConnectionCheck ¶
func WithConnectionCheck(h eh.EventHandler) Option
WithConnectionCheck adds an optional DB connection check when calling New().
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo implements an MongoDB repository for entities.
func IntoRepo ¶
IntoRepo tries to convert a eh.ReadRepo into a Repo by recursively looking at inner repos. Returns nil if none was found.
func NewRepoWithClient ¶
func NewRepoWithClient(client *mongo.Client, dbName, collection string, options ...Option) (*Repo, error)
NewRepoWithClient creates a new Repo with a client.
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 ¶
CreateIndex creates an index for a field.
func (*Repo) FindAll ¶
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 ErrNoCursor 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 ¶
func (r *Repo) FindOneCustom(ctx context.Context, f func(context.Context, *mongo.Collection) *mongo.SingleResult) (eh.Entity, error)
FindOneCustom uses a callback to specify a custom query for returning an entity.
func (*Repo) InnerRepo ¶
InnerRepo implements the InnerRepo method of the eventhorizon.ReadRepo interface.
func (*Repo) SetEntityFactory ¶
SetEntityFactory sets a factory function that creates concrete entity types.