Documentation ¶
Index ¶
- Variables
- type EventStore
- func (s *EventStore) Clear() error
- func (s *EventStore) Close()
- func (s *EventStore) Load(id eventhorizon.UUID) ([]eventhorizon.Event, error)
- func (s *EventStore) RegisterEventType(event eventhorizon.Event, factory func() eventhorizon.Event) error
- func (s *EventStore) Save(events []eventhorizon.Event) error
- func (s *EventStore) SetDB(db string)
- type ReadRepository
- func (r *ReadRepository) Clear() error
- func (r *ReadRepository) Close()
- func (r *ReadRepository) Find(id eventhorizon.UUID) (interface{}, error)
- func (r *ReadRepository) FindAll() ([]interface{}, error)
- func (r *ReadRepository) FindCustom(callback func(*mgo.Collection) *mgo.Query) ([]interface{}, error)
- func (r *ReadRepository) Remove(id eventhorizon.UUID) error
- func (r *ReadRepository) Save(id eventhorizon.UUID, model interface{}) error
- func (r *ReadRepository) SetDB(db string)
- func (r *ReadRepository) SetModel(factory func() interface{})
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 ErrCouldNotLoadAggregate = errors.New("could not load aggregate")
ErrCouldNotLoadAggregate is when an aggregate could not be loaded.
var ErrCouldNotMarshalEvent = errors.New("could not marshal event")
ErrCouldNotMarshalEvent is when an event could not be marshaled into BSON.
var ErrCouldNotSaveAggregate = errors.New("could not save aggregate")
ErrCouldNotSaveAggregate is when an aggregate could not be saved.
var ErrCouldNotUnmarshalEvent = errors.New("could not unmarshal event")
ErrCouldNotUnmarshalEvent is when an event could not be unmarshaled into a concrete type.
var ErrEventNotRegistered = errors.New("event not registered")
ErrEventNotRegistered is when an event is not registered.
var ErrInvalidEvent = errors.New("invalid event")
ErrInvalidEvent is when an event does not implement the Event interface.
var ErrModelNotSet = errors.New("model not set")
ErrModelNotSet is when an model is not set on a read repository.
var ErrNoDBSession = errors.New("no database session")
ErrNoDBSession is when no database session is set.
Functions ¶
This section is empty.
Types ¶
type EventStore ¶
type EventStore struct {
// contains filtered or unexported fields
}
EventStore implements an EventStore for MongoDB.
func NewEventStore ¶
func NewEventStore(eventBus eventhorizon.EventBus, url, database string) (*EventStore, error)
NewEventStore creates a new EventStore.
func NewEventStoreWithSession ¶
func NewEventStoreWithSession(eventBus eventhorizon.EventBus, session *mgo.Session, database string) (*EventStore, error)
NewEventStoreWithSession creates a new EventStore with a session.
func (*EventStore) Load ¶
func (s *EventStore) Load(id eventhorizon.UUID) ([]eventhorizon.Event, error)
Load loads all events for the aggregate id from the database. Returns ErrNoEventsFound if no events can be found.
func (*EventStore) RegisterEventType ¶
func (s *EventStore) RegisterEventType(event eventhorizon.Event, factory func() eventhorizon.Event) error
RegisterEventType registers an event factory for a event type. The factory is used to create concrete event types when loading from the database.
An example would be:
eventStore.RegisterEventType(&MyEvent{}, func() Event { return &MyEvent{} })
func (*EventStore) Save ¶
func (s *EventStore) Save(events []eventhorizon.Event) error
Save appends all events in the event stream to the database.
type ReadRepository ¶
type ReadRepository struct {
// contains filtered or unexported fields
}
ReadRepository implements an MongoDB repository of read models.
func NewReadRepository ¶
func NewReadRepository(url, database, collection string) (*ReadRepository, error)
NewReadRepository creates a new ReadRepository.
func NewReadRepositoryWithSession ¶
func NewReadRepositoryWithSession(session *mgo.Session, database, collection string) (*ReadRepository, error)
NewReadRepositoryWithSession creates a new ReadRepository with a session.
func (*ReadRepository) Clear ¶
func (r *ReadRepository) Clear() error
Clear clears the read model database.
func (*ReadRepository) Find ¶
func (r *ReadRepository) Find(id eventhorizon.UUID) (interface{}, error)
Find returns one read model with using an id. Returns ErrModelNotFound if no model could be found.
func (*ReadRepository) FindAll ¶
func (r *ReadRepository) FindAll() ([]interface{}, error)
FindAll returns all read models in the repository.
func (*ReadRepository) FindCustom ¶
func (r *ReadRepository) FindCustom(callback func(*mgo.Collection) *mgo.Query) ([]interface{}, error)
FindCustom uses a callback to specify a custom query.
func (*ReadRepository) Remove ¶
func (r *ReadRepository) Remove(id eventhorizon.UUID) error
Remove removes a read model with id from the repository. Returns ErrModelNotFound if no model could be found.
func (*ReadRepository) Save ¶
func (r *ReadRepository) Save(id eventhorizon.UUID, model interface{}) error
Save saves a read model with id to the repository.
func (*ReadRepository) SetDB ¶
func (r *ReadRepository) SetDB(db string)
SetDB sets the database session and database.
func (*ReadRepository) SetModel ¶
func (r *ReadRepository) SetModel(factory func() interface{})
SetModel sets a factory function that creates concrete model types.