ev

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: BSD-3-Clause Imports: 11 Imported by: 6

README

ev - Eventsourcing Playground

This project is learnings in building an eventstore and applications around it.

Feel free to explore.

For examples of use of this see <go.sour.is/tools>

Documentation

Overview

package es implements an event store and drivers for extending its functionality.

Index

Constants

View Source
const AllEvents = int64(AppendOnly >> 1)
View Source
const AppendOnly = ^uint64(0)

Variables

View Source
var ErrNoDriver = errors.New("no driver")
View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrShouldExist = event.ErrShouldExist
View Source
var ErrShouldNotExist = event.ErrShouldNotExist
View Source
var ErrWrongVersion = errors.New("wrong version")

Functions

func Create

func Create[A any, T PA[A]](ctx context.Context, es *EventStore, streamID string, fn func(context.Context, T) error) (agg T, err error)

Create uses fn to create a new aggregate and store in db.

func Init

func Init(ctx context.Context) error

func Register

func Register(ctx context.Context, name string, d driver.Driver) error

func Unwrap

func Unwrap[T any](t T) T

func Update

func Update[A any, T PA[A]](ctx context.Context, es *EventStore, streamID string, fn func(context.Context, T) error) (agg T, err error)

Update uses fn to update an exsisting aggregate and store in db.

func Upsert

func Upsert[A any, T PA[A]](ctx context.Context, es *EventStore, streamID string, fn func(context.Context, T) error) (agg T, err error)

Update uses fn to update an exsisting aggregate and store in db.

Types

type EventStore

type EventStore struct {
	driver.Driver
}

func Open

func Open(ctx context.Context, dsn string, options ...Option) (*EventStore, error)

func (*EventStore) Append

func (es *EventStore) Append(ctx context.Context, streamID string, events event.Events) (uint64, error)

func (*EventStore) EventStream

func (es *EventStore) EventStream() driver.EventStream

func (*EventStore) FirstIndex

func (es *EventStore) FirstIndex(ctx context.Context, streamID string) (uint64, error)

func (*EventStore) LastIndex

func (es *EventStore) LastIndex(ctx context.Context, streamID string) (uint64, error)

func (*EventStore) Load

func (es *EventStore) Load(ctx context.Context, agg event.Aggregate) error

func (*EventStore) Option

func (es *EventStore) Option(options ...Option)

func (*EventStore) Read

func (es *EventStore) Read(ctx context.Context, streamID string, after, count int64) (event.Events, error)

func (*EventStore) ReadN

func (es *EventStore) ReadN(ctx context.Context, streamID string, index ...uint64) (event.Events, error)

func (*EventStore) Save

func (es *EventStore) Save(ctx context.Context, agg event.Aggregate) (uint64, error)

func (*EventStore) Truncate

func (es *EventStore) Truncate(ctx context.Context, streamID string, index int64) error

type Option

type Option interface {
	Apply(*EventStore)
}

type PA

type PA[T any] interface {
	event.Aggregate
	*T
}

type PE

type PE[T any] interface {
	event.Event
	*T
}

Directories

Path Synopsis
package driver defines interfaces to be used by driver implementations.
package driver defines interfaces to be used by driver implementations.
mem-store
package memstore provides a driver that reads and writes events to memory.
package memstore provides a driver that reads and writes events to memory.
projecter
package projecter provides a driver middleware to derive new events from other events.
package projecter provides a driver middleware to derive new events from other events.
streamer
package streamer provides a driver to allow awaiting for new events to be added to a stream.
package streamer provides a driver to allow awaiting for new events to be added to a stream.
package event implements functionality for working with an eventstore.
package event implements functionality for working with an eventstore.
internal

Jump to

Keyboard shortcuts

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