dynamodb

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

Event Horizon Dynamo

Event Horizon Dynamo contains the DynamoDB driver for Event Horizon a CQRS/ES toolkit for Go.

Usage

See the Event Horizon example folder for a few examples to get you started and replace the storage drivers (event store and/or repo)

Development

To develop Event Horizon Dynamo you need to have Docker and Docker Compose installed.

To start all needed services and run all tests, simply run make:

make

To manually run the services and stop them:

make services
make stop

When the services are running testing can be done either locally or with Docker:

make test
make test_docker
go test ./...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCouldNotClearDB = errors.New("could not clear database")

ErrCouldNotClearDB is when the database could not be cleared.

View Source
var ErrCouldNotDialDB = errors.New("could not dial database")

ErrCouldNotDialDB is when the database could not be dialed.

View Source
var ErrCouldNotMarshalEvent = errors.New("could not marshal event")

ErrCouldNotMarshalEvent is when an event could not be marshaled into BSON.

View Source
var ErrCouldNotSaveAggregate = errors.New("could not save aggregate")

ErrCouldNotSaveAggregate is when an aggregate could not be saved.

View Source
var ErrCouldNotUnmarshalEvent = errors.New("could not unmarshal event")

ErrCouldNotUnmarshalEvent is when an event could not be unmarshaled into a concrete type.

View Source
var ErrModelNotSet = errors.New("model not set")

ErrModelNotSet is when an model factory is not set on the Repo.

Functions

This section is empty.

Types

type EventStore

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

EventStore implements an EventStore for DynamoDB.

func NewEventStore

func NewEventStore(tablePrefix string, options ...Option) (*EventStore, error)

NewEventStore creates a new EventStore.

func (*EventStore) CreateTable

func (s *EventStore) CreateTable(ctx context.Context) error

CreateTable creates the table if it is not already existing and correct.

func (*EventStore) DeleteTable

func (s *EventStore) DeleteTable(ctx context.Context) error

DeleteTable deletes the event table.

func (*EventStore) Load

func (s *EventStore) Load(ctx context.Context, id uuid.UUID) ([]eh.Event, error)

Load implements the Load method of the eventhorizon.EventStore interface.

func (*EventStore) LoadAll

func (s *EventStore) LoadAll(ctx context.Context) ([]eh.Event, error)

LoadAll will load all the events from the event store (useful to replay events)

func (*EventStore) RenameEvent

func (s *EventStore) RenameEvent(ctx context.Context, from, to eh.EventType) error

RenameEvent implements the RenameEvent method of the eventhorizon.EventStore interface.

func (*EventStore) Replace

func (s *EventStore) Replace(ctx context.Context, event eh.Event) error

Replace implements the Replace method of the eventhorizon.EventStore interface.

func (*EventStore) Save

func (s *EventStore) Save(ctx context.Context, events []eh.Event, originalVersion int) error

Save implements the Save method of the eventhorizon.EventStore interface.

type IndexInput

type IndexInput struct {
	IndexName         string
	PartitionKey      string
	PartitionKeyValue interface{}
	SortKey           string
	SortKeyValue      interface{}
}

IndexInput is all the params we need to filter on an index

type Option

type Option func(*EventStore) error

Option is an option setter used to configure creation.

func WithDynamoDB

func WithDynamoDB(sess *session.Session) Option

WithDBName uses a custom DB name function.

func WithEventHandler

func WithEventHandler(h eh.EventHandler) Option

WithEventHandler adds an event handler that will be called when saving events. An example would be to add an event bus to publish events.

type OptionRepo

type OptionRepo func(*Repo) error

Option is an option setter used to configure creation.

func WithRepoDynamoDB

func WithRepoDynamoDB(sess *session.Session) OptionRepo

WithRepoDBName uses a custom DB name function.

func WithRepoEntityFactoryFunc

func WithRepoEntityFactoryFunc(f func() eh.Entity) OptionRepo

func WithRepoPrefixAsTableName

func WithRepoPrefixAsTableName() OptionRepo

WithPrefixAsDBName uses only the prefix as DB name, without namespace support.

func WithRepoTableName

func WithRepoTableName(tableName func(context.Context) string) OptionRepo

WithDBName uses a custom DB name function.

type Repo

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

Repo implements a DynamoDB repository for entities.

func NewRepo

func NewRepo(tablePrefix string, options ...OptionRepo) (*Repo, error)

NewRepo creates a new Repo.

func (*Repo) CreateTable

func (r *Repo) CreateTable(ctx context.Context) error

func (*Repo) DeleteTable added in v0.0.5

func (r *Repo) DeleteTable(ctx context.Context) error

func (*Repo) Find

func (r *Repo) Find(ctx context.Context, id uuid.UUID) (eh.Entity, error)

Find implements the Find method of the eventhorizon.ReadRepo interface.

func (*Repo) FindAll

func (r *Repo) FindAll(ctx context.Context) ([]eh.Entity, error)

FindAll implements the FindAll method of the eventhorizon.ReadRepo interface.

func (*Repo) FindWithFilter

func (r *Repo) FindWithFilter(ctx context.Context, expr string, args ...interface{}) ([]eh.Entity, error)

FindWithFilter allows to find entities with a filter

func (*Repo) FindWithFilterUsingIndex

func (r *Repo) FindWithFilterUsingIndex(ctx context.Context, indexInput IndexInput, filterQuery string, filterArgs ...interface{}) ([]eh.Entity, error)

FindWithFilterUsingIndex allows to find entities with a filter using an index

func (*Repo) Parent

func (r *Repo) Parent() eh.ReadRepo

Parent implements the Parent method of the eventhorizon.ReadRepo interface.

func (*Repo) Remove

func (r *Repo) Remove(ctx context.Context, id uuid.UUID) error

Remove implements the Remove method of the eventhorizon.WriteRepo interface.

func (*Repo) Save

func (r *Repo) Save(ctx context.Context, entity eh.Entity) error

Save implements the Save method of the eventhorizon.WriteRepo interface.

func (*Repo) SetEntityFactory

func (r *Repo) SetEntityFactory(f func() eh.Entity)

SetEntityFactory sets a factory function that creates concrete entity types.

Jump to

Keyboard shortcuts

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