eventstore

package
v0.0.0-...-4b1ce38 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEntityNotFound = errors.New("entity not found by ID")

Functions

This section is empty.

Types

type ContextExecutor

type ContextExecutor interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}

ContextExecutor can perform SQL queries with context.

type EventStore

type EventStore[T esja.Entity[T]] interface {
	// Load fetches all events for the ID and returns a new instance of T based on them.
	Load(ctx context.Context, id string) (*T, error)

	// Save saves events recorded in the entity's stream.
	Save(ctx context.Context, entity *T) error
}

EventStore loads and saves T implementing esja.Entity.

type InMemoryStore

type InMemoryStore[T esja.Entity[T]] struct {
	// contains filtered or unexported fields
}

func NewInMemoryStore

func NewInMemoryStore[T esja.Entity[T]]() *InMemoryStore[T]

func (*InMemoryStore[T]) Load

func (i *InMemoryStore[T]) Load(_ context.Context, id string) (*T, error)

func (*InMemoryStore[T]) Save

func (i *InMemoryStore[T]) Save(_ context.Context, t *T) error

type PostgresSchemaAdapter

type PostgresSchemaAdapter[A any] struct{}

func NewPostgresSchemaAdapter

func NewPostgresSchemaAdapter[A any]() PostgresSchemaAdapter[A]

func (PostgresSchemaAdapter[A]) InitializeSchemaQuery

func (a PostgresSchemaAdapter[A]) InitializeSchemaQuery() string

func (PostgresSchemaAdapter[A]) InsertQuery

func (a PostgresSchemaAdapter[A]) InsertQuery(streamType string, events []storageEvent[A]) (string, []any, error)

func (PostgresSchemaAdapter[A]) SelectQuery

func (a PostgresSchemaAdapter[A]) SelectQuery(streamID string) (string, []any, error)

type SQLConfig

type SQLConfig[T any] struct {
	SchemaAdapter schemaAdapter[T]
	Mapper        transport.Mapper[T]
	Marshaler     transport.Marshaler
}

func NewMappingPostgresSQLConfig

func NewMappingPostgresSQLConfig[T any](
	supportedEvents []transport.Event[T],
) SQLConfig[T]

func NewMappingSQLiteConfig

func NewMappingSQLiteConfig[T any](
	supportedEvents []transport.Event[T],
) SQLConfig[T]

func NewPostgresSQLConfig

func NewPostgresSQLConfig[T any](
	supportedEvents []esja.Event[T],
) SQLConfig[T]

func NewSQLiteConfig

func NewSQLiteConfig[T any](
	supportedEvents []esja.Event[T],
) SQLConfig[T]

type SQLStore

type SQLStore[T esja.Entity[T]] struct {
	// contains filtered or unexported fields
}

SQLStore is an implementation of the EventStore interface using an SQLStore database.

func NewSQLStore

func NewSQLStore[T esja.Entity[T]](
	ctx context.Context,
	db ContextExecutor,
	config SQLConfig[T],
) (SQLStore[T], error)

NewSQLStore creates a new SQL EventStore.

func (SQLStore[T]) Load

func (s SQLStore[T]) Load(ctx context.Context, id string) (*T, error)

Load loads the entity from the database events.

func (SQLStore[T]) Save

func (s SQLStore[T]) Save(ctx context.Context, t *T) (err error)

Save saves the entity's queued events to the database.

type SQLiteSchemaAdapter

type SQLiteSchemaAdapter[A any] struct{}

func NewSQLiteSchemaAdapter

func NewSQLiteSchemaAdapter[A any]() SQLiteSchemaAdapter[A]

func (SQLiteSchemaAdapter[A]) InitializeSchemaQuery

func (a SQLiteSchemaAdapter[A]) InitializeSchemaQuery() string

func (SQLiteSchemaAdapter[A]) InsertQuery

func (a SQLiteSchemaAdapter[A]) InsertQuery(streamType string, events []storageEvent[A]) (string, []any, error)

func (SQLiteSchemaAdapter[A]) SelectQuery

func (a SQLiteSchemaAdapter[A]) SelectQuery(streamID string) (string, []any, error)

Jump to

Keyboard shortcuts

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