dynamoprojection

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 12 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 CreateTable

func CreateTable(
	ctx context.Context,
	c *dynamodb.Client,
	name string,
	options ...TableOption,
) error

CreateTable creates an AWS DynamoDB table that stores information about projection resource versions.

Each running Dogma instance SHOULD use a different table. It does not return an error if the table already exists.

See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html

func DeleteTable

func DeleteTable(
	ctx context.Context,
	c *dynamodb.Client,
	name string,
	options ...TableOption,
) error

DeleteTable deletes an AWS DynamoDB table.

It is used to delete tables created using CreateTable().

It does not return an error if the table does not exist.

func New

New returns a new Dogma projection message handler by binding a DynamoDB-specific projection handler to an AWS DynamoDB client.

t is the name of a DynamoDB table that stores information about projection resource versions. Each running Dogma instance SHOULD use a different table.

If c is nil the returned handler will return an error whenever a DynamoDB API call is made.

func WithDecorateDeleteItem

func WithDecorateDeleteItem(
	dec func(*dynamodb.DeleteItemInput) []func(*dynamodb.Options),
) interface {
	HandlerOption
	ResourceRepositoryOption
}

WithDecorateDeleteItem adds a decorator for DynamoDB DeleteItem operations.

The decorator function may modify the input structure in-place. It returns a slice of DynamoDB request.Option values that are applied to the API request.

func WithDecorateGetItem

func WithDecorateGetItem(
	dec func(*dynamodb.GetItemInput) []func(*dynamodb.Options),
) interface {
	HandlerOption
	ResourceRepositoryOption
}

WithDecorateGetItem adds a decorator for DynamoDB GetItem operations.

The decorator function may modify the input structure in-place. It returns a slice of DynamoDB request.Option values that are applied to the API request.

func WithDecoratePutItem

func WithDecoratePutItem(
	dec func(*dynamodb.PutItemInput) []func(*dynamodb.Options),
) interface {
	HandlerOption
	ResourceRepositoryOption
}

WithDecoratePutItem adds a decorator for DynamoDB PutItem operations.

The decorator function may modify the input structure in-place. It returns a slice of DynamoDB request.Option values that are applied to the API request.

func WithDecorateTransactWriteItems

func WithDecorateTransactWriteItems(
	dec func(*dynamodb.TransactWriteItemsInput) []func(*dynamodb.Options),
) interface {
	HandlerOption
	ResourceRepositoryOption
}

WithDecorateTransactWriteItems adds a decorator for DynamoDB TransactWriteItems operations.

The decorator function may modify the input structure in-place. It returns a slice of DynamoDB request.Option values that are applied to the API request.

Warning! The order of the TransactWriteItems in the input structure is meaningful to both DynamoDB and this package. Specifically, the first item is used to update the projection's resource versions; it MUST NOT be modified or reordered.

Types

type HandlerOption

type HandlerOption interface {
	// contains filtered or unexported methods
}

HandlerOption is used to alter the behavior of AWS DynamoDB projection handler.

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.
	//
	// 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.
	//
	// 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 supplied context parameter SHOULD have a deadline. The implementation
	// SHOULD NOT impose its own deadline. Instead a suitable timeout duration
	// can be suggested to the engine via the handler's TimeoutHint() method.
	//
	// 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, s dogma.ProjectionEventScope, m dogma.Message) ([]types.TransactWriteItem, error)

	// TimeoutHint returns a duration that is suitable for computing a deadline
	// for the handling of the given message by this handler.
	//
	// The hint SHOULD be as short as possible. The implementation MAY return a
	// zero-value to indicate that no hint can be made.
	//
	// The engine SHOULD use a duration as close as possible to the hint. Use of
	// a duration shorter than the hint is NOT RECOMMENDED, as this will likely
	// lead to repeated message handling failures.
	TimeoutHint(m dogma.Message) time.Duration

	// 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, client *dynamodb.Client, s dogma.ProjectionCompactScope) error
}

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

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

Compact returns nil.

type ResourceRepository

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

ResourceRepository is an implementation of resource.Repository that stores resources versions in AWS DynamoDB.

func NewResourceRepository

func NewResourceRepository(
	client *dynamodb.Client,
	key, occTable string,
	options ...ResourceRepositoryOption,
) *ResourceRepository

NewResourceRepository returns a new DynamoDB resource repository.

func (*ResourceRepository) DeleteResource

func (rr *ResourceRepository) DeleteResource(ctx context.Context, r []byte) error

DeleteResource removes all information about the resource r.

func (*ResourceRepository) ResourceVersion

func (rr *ResourceRepository) ResourceVersion(ctx context.Context, r []byte) ([]byte, error)

ResourceVersion returns the version of the resource r.

func (*ResourceRepository) StoreResourceVersion

func (rr *ResourceRepository) StoreResourceVersion(ctx context.Context, r, v []byte) error

StoreResourceVersion sets the version of the resource r to v without checking the current version.

func (*ResourceRepository) UpdateResourceVersion

func (rr *ResourceRepository) UpdateResourceVersion(
	ctx context.Context,
	r, c, n []byte,
) (ok bool, _ 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) UpdateResourceVersionAndTransactionItems

func (rr *ResourceRepository) UpdateResourceVersionAndTransactionItems(
	ctx context.Context,
	r, c, n []byte,
	items ...types.TransactWriteItem,
) (ok bool, err error)

UpdateResourceVersionAndTransactionItems updates the version of the resource r to n and the given items within the same transaction.

If c is not the current version of r, it returns false and no update occurs.

type ResourceRepositoryOption

type ResourceRepositoryOption interface {
	// contains filtered or unexported methods
}

ResourceRepositoryOption is used to alter the behavior of a ResourceRepository.

type TableOption

type TableOption interface {
	// contains filtered or unexported methods
}

TableOption is used to alter the behavior of oeprations that manipulate DynamoDB tables.

func WithDecorateCreateTable

func WithDecorateCreateTable(
	dec func(*dynamodb.CreateTableInput) []func(*dynamodb.Options),
) TableOption

WithDecorateCreateTable adds a decorator for DynamoDB CreateTable operations.

The decorator function may modify the input structure in-place. It returns a slice of DynamoDB request.Option values that are applied to the API request.

func WithDecorateDeleteTable

func WithDecorateDeleteTable(
	dec func(*dynamodb.DeleteTableInput) []func(*dynamodb.Options),
) TableOption

WithDecorateDeleteTable adds a decorator for DynamoDB DeleteTable operations.

The decorator function may modify the input structure in-place. It returns a slice of DynamoDB request.Option values that are applied to the API request.

Directories

Path Synopsis
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.
internal

Jump to

Keyboard shortcuts

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