Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entity ¶
type Entity[T any] interface { // Stream exposes a pointer to the internal entity's Stream. Stream() *Stream[T] // NewWithStream returns a new instance of T // with the provided Stream queue injected. NewWithStream(*Stream[T]) *T }
Entity represents the event-sourced type saved and loaded by the event store. In DDD terms, it is the "aggregate root".
In order for your domain type to implement Entity:
- Keep *Stream in a field.
- Implement the interface methods in accordance with its description.
Then an EventStore will be able to store and load it.
Example:
type User struct { stream *esja.Stream[User] id string } func (u User) Stream() *esja.Stream[User] { return u.stream } func (u User) NewWithStream(stream *esja.Stream[User]) *User { return &User{stream: stream} }
type Stream ¶
type Stream[T any] struct { // contains filtered or unexported fields }
Stream represents a queue of events and basic stream properties.
func NewStreamWithType ¶
NewStreamWithType creates a new instance of a Stream with provided ID and custom type.
func (*Stream[T]) PopEvents ¶
func (s *Stream[T]) PopEvents() []VersionedEvent[T]
PopEvents returns the slice of queued VersionedEvents and clears it.
type VersionedEvent ¶
VersionedEvent is an event with a corresponding stream version.
Click to show internal directories.
Click to hide internal directories.