mongo

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventStore

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

EventStore is the MongoDB event.Store.

func NewEventStore

func NewEventStore(enc codec.Encoding, opts ...EventStoreOption) *EventStore

NewEventStore returns a MongoDB event.Store.

func (*EventStore) Client

func (s *EventStore) Client() *mongo.Client

Client returns the underlying mongo.Client. If no mongo.Client is provided with the Client option, Client returns nil until the connection to MongoDB has been established by either explicitly calling s.Connect or implicitly by calling s.Insert, s.Find, s.Delete or s.Query. Otherwise Client returns the provided mongo.Client.

func (*EventStore) Collection

func (s *EventStore) Collection() *mongo.Collection

Collection returns the underlying *mongo.Collection where the Events are stored in. Collection returns nil until the connection to MongoDB has been established by either explicitly calling s.Connect or implicitly by calling s.Insert, s.Find, s.Delete or s.Query.

func (*EventStore) Connect

func (s *EventStore) Connect(ctx context.Context, opts ...*options.ClientOptions) (*mongo.Client, error)

Connect establishes the connection to the underlying MongoDB and returns the mongo.Client. Connect doesn't need to be called manually as it's called automatically on the first call to s.Insert, s.Find, s.Delete or s.Query. Use Connect if you want to explicitly control when to connect to MongoDB.

func (*EventStore) Database

func (s *EventStore) Database() *mongo.Database

Database returns the underlying mongo.Database. Database returns nil until the connection to MongoDB has been established by either explicitly calling s.Connect or implicitly by calling s.Insert, s.Find, s.Delete or s.Query.

func (*EventStore) Delete

func (s *EventStore) Delete(ctx context.Context, events ...event.Event) error

Delete deletes the given Event from the database.

func (*EventStore) Find

func (s *EventStore) Find(ctx context.Context, id uuid.UUID) (event.Event, error)

Find returns the Event with the specified UUID from the database if it exists.

func (*EventStore) Insert

func (s *EventStore) Insert(ctx context.Context, events ...event.Event) error

Insert saves the given Events into the database.

func (*EventStore) Query

func (s *EventStore) Query(ctx context.Context, q event.Query) (<-chan event.Event, <-chan error, error)

Query queries the database for events filtered by Query q and returns an event.Stream for those events.

func (*EventStore) StateCollection

func (s *EventStore) StateCollection() *mongo.Collection

StateCollection returns the underlying *mongo.Collection where Aggregate states are stored in. StateCollection returns nil until the connection to MongoDB has been established by either explicitly calling s.Connect or implicitly by calling s.Insert, s.Find, s.Delete or s.Query.

type EventStoreOption

type EventStoreOption func(*EventStore)

EventStoreOption is an EventStore option.

func Client

func Client(c *mongo.Client) EventStoreOption

Client returns an Option that specifies the underlying mongo.Client to be used by the Store.

func Collection

func Collection(name string) EventStoreOption

Collection returns an Option that sets the mongo collection where the Events are stored in.

func Database

func Database(name string) EventStoreOption

Database returns an Option that sets the mongo database to use for the events.

func StateCollection

func StateCollection(name string) EventStoreOption

StateCollection returns an Option that specifies the name of the Collection where the current state of Aggregates are stored in.

func Transactions

func Transactions(tx bool) EventStoreOption

Transactions returns an Option that, if tx is true, configures a Store to use MongoDB Transactions when inserting Events.

Transactions can only be used in replica sets or sharded clusters: https://docs.mongodb.com/manual/core/transactions/

func URL

func URL(url string) EventStoreOption

URL returns an Option that specifies the URL to the MongoDB instance. An empty URL means "use the default".

Defaults to the environment variable "MONGO_URL".

func ValidateVersions

func ValidateVersions(v bool) EventStoreOption

ValidateVersions returns an Option that enables validation of Event versions before inserting them into the Store.

Defaults to true.

type VersionError

type VersionError struct {
	// AggregateName is the name of the Aggregate.
	AggregateName string

	// AggregateID is the UUID of the Aggregate.
	AggregateID uuid.UUID

	// CurrentVersion is the current version of the Aggregate.
	CurrentVersion int

	// Event is the event with the invalid version.
	Event event.Event
}

A VersionError means the insertion of Events failed because at least one of the Events has an invalid/inconsistent version.

func (*VersionError) Error

func (err *VersionError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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