Documentation
¶
Overview ¶
Package boltprojection provides utilities for building BoltDB-based projections.
Index ¶
- func New(db *bbolt.DB, h MessageHandler) dogma.ProjectionMessageHandler
- type MessageHandler
- type NoCompactBehavior
- type ResourceRepository
- func (rr *ResourceRepository) DeleteResource(_ context.Context, r []byte) error
- func (rr *ResourceRepository) ResourceVersion(_ context.Context, r []byte) ([]byte, error)
- func (rr *ResourceRepository) StoreResourceVersion(_ context.Context, r, v []byte) error
- func (rr *ResourceRepository) UpdateResourceVersion(_ context.Context, r, c, n []byte) (ok bool, err error)
- func (rr *ResourceRepository) UpdateResourceVersionFn(ctx context.Context, r, c, n []byte, fn func(context.Context, *bbolt.Tx) error) (ok bool, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New( db *bbolt.DB, h MessageHandler, ) dogma.ProjectionMessageHandler
New returns a new Dogma projection message handler by binding a BoltDB-specific projection handler to a BoltDB database.
If db is nil the returned handler will return an error whenever an operation that requires the database is performed.
Types ¶
type MessageHandler ¶
type MessageHandler 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.
//
// Changes to the projection state MUST be performed within the supplied
// transaction.
//
// If nil is returned, the projection state has been persisted successfully.
//
// If an error is returned, the projection SHOULD be left in the state it
// was before HandleEvent() was called.
//
// The engine SHOULD provide "at-least-once" delivery guarantees to the
// handler. That is, the engine should call HandleEvent() with the same
// event message until a nil error is returned.
//
// 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(ctx context.Context, tx *bbolt.Tx, s dogma.ProjectionEventScope, m dogma.Event) error
// Compact reduces the size of the projection's data.
//
// 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 context MAY have a deadline. The implementation SHOULD compact data
// using multiple small transactions, such that if the deadline is reached a
// future call to Compact() does not need to compact the same data.
//
// 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(ctx context.Context, db *bbolt.DB, s dogma.ProjectionCompactScope) error
}
MessageHandler is a specialization of dogma.ProjectionMessageHandler that persists to a BoltDB database.
type NoCompactBehavior ¶
type NoCompactBehavior 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 always returns a nil error.
func (NoCompactBehavior) Compact ¶
func (NoCompactBehavior) Compact( context.Context, *bbolt.DB, dogma.ProjectionCompactScope, ) error
Compact returns nil.
type ResourceRepository ¶ added in v0.6.4
type ResourceRepository struct {
// contains filtered or unexported fields
}
ResourceRepository is an implementation of resource.Repository that stores resources versions in a BoltDB database.
func NewResourceRepository ¶ added in v0.6.4
func NewResourceRepository( db *bbolt.DB, key string, ) *ResourceRepository
NewResourceRepository returns a new BoltDB resource repository.
func (*ResourceRepository) DeleteResource ¶ added in v0.6.4
func (rr *ResourceRepository) DeleteResource(_ context.Context, r []byte) error
DeleteResource removes all information about the resource r.
func (*ResourceRepository) ResourceVersion ¶ added in v0.6.4
ResourceVersion returns the version of the resource r.
func (*ResourceRepository) StoreResourceVersion ¶ added in v0.6.4
func (rr *ResourceRepository) StoreResourceVersion(_ context.Context, r, v []byte) error
StoreResourceVersion sets the version of the resource r to v without checking the current version.
func (*ResourceRepository) UpdateResourceVersion ¶ added in v0.6.4
func (rr *ResourceRepository) UpdateResourceVersion( _ context.Context, r, c, n []byte, ) (ok bool, err error)
UpdateResourceVersion updates the version of the resource r to n.
If c is not the current version of r, it returns false and no update occurs.
func (*ResourceRepository) UpdateResourceVersionFn ¶ added in v0.6.4
func (rr *ResourceRepository) UpdateResourceVersionFn( ctx context.Context, r, c, n []byte, fn func(context.Context, *bbolt.Tx) error, ) (ok bool, err error)
UpdateResourceVersionFn updates the version of the resource r to n and performs a user-defined operation within the same transaction.
If c is not the current version of r, it returns false and no update occurs.