Documentation
¶
Overview ¶
Package memoryprojection provides utilities for building in-memory projections.
Memory projections do not persist any state, and therefore may only be useful for testing or with an event-sourcing engine.
Index ¶
- func Query[T, R any, H MessageHandler[T]](p *Projection[T, H], q func(T) R) R
- type MessageHandler
- type NoCompactBehavior
- type Projection
- func (p *Projection[T, H]) CheckpointOffset(_ context.Context, id string) (uint64, error)
- func (p *Projection[T, H]) Compact(_ context.Context, s dogma.ProjectionCompactScope) error
- func (p *Projection[T, H]) Configure(c dogma.ProjectionConfigurer)
- func (p *Projection[T, H]) HandleEvent(_ context.Context, s dogma.ProjectionEventScope, m dogma.Event) (uint64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Query ¶
func Query[T, R any, H MessageHandler[T]](p *Projection[T, H], q func(T) R) R
Query queries a value of type T to produce a result of type R.
q is called with the current value, which may be read within the lifetime of the call to fn. fn MUST NOT retain a reference to the value after the call returns. fn MUST NOT modify the value.
Types ¶
type MessageHandler ¶
type MessageHandler[T any] interface { // Configure produces a configuration for this handler by calling methods on // the configurer c. // // The implementation MUST allow for multiple calls to Configure(). Each // call SHOULD produce the same configuration. // // The engine MUST call Configure() before calling HandleEvent(). It is // RECOMMENDED that the engine only call Configure() once per handler. Configure(c dogma.ProjectionConfigurer) // HandleEvent updates the projection to reflect the occurrence of an event. // It may do so by modifying v in-place then returning it, or by returning // an entirely new value. // // The engine MAY provide guarantees about the order in which event messages // will be passed to HandleEvent(), however in the interest of engine // portability the implementation SHOULD NOT assume that HandleEvent() will // be called with events in the same order that they were recorded. // // The engine MUST NOT call HandleEvent() with any message of a type that // has not been configured for consumption by a prior call to Configure(). // If any such message is passed, the implementation MUST panic with the // UnexpectedMessage value. // // The engine MAY call HandleEvent() from multiple goroutines concurrently. HandleEvent(v T, s dogma.ProjectionEventScope, m dogma.Event) (T, error) // Compact reduces the size of the projection's data. It may do so by // modifying v in-place then returning it, or by returning an entirely new // value. // // The implementation SHOULD attempt to decrease the size of the // projection's data by whatever means available. For example, it may delete // any unused data, or collapse multiple data sets into one. // // The engine SHOULD call Compact() repeatedly throughout the lifetime of // the projection. The precise scheduling of calls to Compact() are // engine-defined. It MAY be called concurrently with any other method. Compact(v T, s dogma.ProjectionCompactScope) T }
MessageHandler is a specialization of dogma.ProjectionMessageHandler that builds an in-memory projection represented by a value of type T.
type NoCompactBehavior ¶
type NoCompactBehavior[T any] struct{}
NoCompactBehavior can be embedded in MessageHandler implementations to indicate that the projection does not require its data to be compacted.
It provides an implementation of MessageHandler.Compact() that does nothing.
func (NoCompactBehavior[T]) Compact ¶
func (NoCompactBehavior[T]) Compact(v T, _ dogma.ProjectionCompactScope) T
Compact does nothing.
type Projection ¶
type Projection[T any, H MessageHandler[T]] struct { Handler H // contains filtered or unexported fields }
Projection is an in-memory projection that builds a value of type T.
func (*Projection[T, H]) CheckpointOffset ¶ added in v0.8.0
CheckpointOffset returns the offset at which the handler expects to resume handling events from a specific stream.
func (*Projection[T, H]) Compact ¶
func (p *Projection[T, H]) Compact(_ context.Context, s dogma.ProjectionCompactScope) error
Compact reduces the size of the projection's data.
func (*Projection[T, H]) Configure ¶
func (p *Projection[T, H]) Configure(c dogma.ProjectionConfigurer)
Configure produces a configuration for this handler by calling methods on the configurer c.
func (*Projection[T, H]) HandleEvent ¶
func (p *Projection[T, H]) HandleEvent( _ context.Context, s dogma.ProjectionEventScope, m dogma.Event, ) (uint64, error)
HandleEvent updates the projection to reflect the occurrence of an event.