dynamoprojection

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package dynamoprojection provides utilities for building AWS DynamoDB-based projections.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(
	client *dynamodb.Client,
	table string,
	handler MessageHandler,
	options ...Option,
) dogma.ProjectionMessageHandler

New returns a new dogma.ProjectionMessageHandler that binds a DynamoDB-specific MessageHandler to a DynamoDB client.

The handler stores information about the projection's checkpoint offsets in the given table. Each application should have its own DynamoDB table.

Types

type MessageHandler

type MessageHandler interface {
	// Configure declares the handler's configuration by calling methods on c.
	//
	// The configuration includes the handler's identity and message routes.
	//
	// The engine calls this method at least once during startup. It must
	// produce the same configuration each time it's called.
	Configure(c dogma.ProjectionConfigurer)

	// HandleEvent updates the projection to reflect the occurrence of a
	// [dogma.Event].
	//
	// The changes to be made are returned as a slice of transaction items,
	// which may be empty. The items are applied to DynamoDB in a single
	// transaction.
	HandleEvent(ctx context.Context, s dogma.ProjectionEventScope, m dogma.Event) ([]types.TransactWriteItem, error)

	// Compact reduces the projection's size by removing or consolidating data.
	//
	// The handler might delete obsolete entries, merge fine-grained data into
	// summaries. The specific strategy depends on the projection's purpose and
	// access patterns.
	//
	// The implementation should perform compaction incrementally to make some
	// progress even if ctx reaches its deadline.
	//
	// The engine may call this method at any time, including in parallel with
	// handling an event.
	//
	// Not all projections need compaction. Embed [NoCompactBehavior] in the
	// handler to indicate compaction not required.
	Compact(ctx context.Context, client *dynamodb.Client, s dogma.ProjectionCompactScope) error

	// Reset clears all projection data.
	//
	// The changes to be made are returned as a slice of transaction items,
	// which may be empty. The items are applied to DynamoDB in a single
	// transaction.
	//
	// Not all projections can be reset. Embed [NoResetBehavior] in the handler
	// to indicate that reset is not supported.
	Reset(ctx context.Context, s dogma.ProjectionResetScope) ([]types.TransactWriteItem, error)
}

MessageHandler is a specialization of dogma.ProjectionMessageHandler that persists to AWS DynamoDB.

type NoCompactBehavior

type NoCompactBehavior struct{}

NoCompactBehavior is an embeddable type for MessageHandler implementations that don't require compaction.

Embed this type in a MessageHandler when projection data doesn't grow unbounded or when an external system handles compaction.

func (NoCompactBehavior) Compact

Compact returns nil.

type NoResetBehavior added in v0.9.0

type NoResetBehavior struct{}

NoResetBehavior is an embeddable type for MessageHandler implementations that don't support resetting their state.

Embed this type in a MessageHandler when resetting projection data isn't feasible or required.

func (NoResetBehavior) Reset added in v0.9.0

Reset returns an error indicating that reset is not supported.

type Option added in v0.9.0

type Option func(*adaptor)

Option is a functional option that changes the behavior of New.

func WithRequestHook added in v0.9.0

func WithRequestHook(fn func(any) []func(*dynamodb.Options)) Option

WithRequestHook is an Option that configures fn as a pre-request hook.

Before each DynamoDB API request, fn is passed a pointer to the input struct, e.g. dynamodb.GetItemInput, which it may modify in-place. It may be called with any DynamoDB request type. The types of requests used may change in any version without notice.

Any functions returned by fn will be applied to the request's options before the request is sent.

Directories

Path Synopsis
internal
dynamox
Package dynamox contains DynamoDB utilities.
Package dynamox contains DynamoDB utilities.
fixtures
Package fixtures is a set of test fixtures and mocks for DynamoDB projections.
Package fixtures is a set of test fixtures and mocks for DynamoDB projections.

Jump to

Keyboard shortcuts

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