ehpg

package module
v0.0.0-...-1fc027f Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 9 Imported by: 0

README

EventHorizon with PostgreSQL

Features

  • EventStore
db := pg.Connect(&pg.Options{
  Addr:     os.Getenv("POSTGRES_ADDR"),
  Database: os.Getenv("POSTGRES_DB"),
  User:     os.Getenv("POSTGRES_USER"),
  Password: os.Getenv("POSTGRES_PASSWORD"),
})
defer db.Close()

store, err := ehpg.NewEventStore(db)

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 ErrCouldNotMarshalEvent = errors.New("could not marshal event")

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

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 ErrVersionConflict = errors.New("Can not create/update aggregate")

ErrConflictVersion is when a version conflict occurs when saving an aggregate.

View Source
var NewUUID = uuid.New

NewUUID for mocking in tests

Functions

This section is empty.

Types

type AggregateEvent

type AggregateEvent struct {
	EventID       uuid.UUID              `sql:"event_id,type:uuid,pk"`
	Namespace     string                 `sql:"namespace,type:varchar(250)"`
	AggregateID   uuid.UUID              `sql:"aggregate_id,type:uuid"`
	AggregateType eh.AggregateType       `sql:"aggregate_type,type:varchar(250)"`
	EventType     eh.EventType           `sql:"event_type,type:varchar(250)"`
	RawData       json.RawMessage        `sql:"data,type:jsonb"`
	Timestamp     time.Time              `sql:"timestamp"`
	Version       int                    `sql:"version"`
	Metadata      map[string]interface{} `sql:"metadata"`
	// contains filtered or unexported fields
}

type AggregateRecord

type AggregateRecord struct {
	Namespace   string    `sql:"namespace,type:varchar(250),pk"`
	AggregateID uuid.UUID `sql:"aggregate_id,type:uuid,pk"`
	Version     int       `sql:"version"`
	// contains filtered or unexported fields
}

type Encoder

type Encoder interface {
	Marshal(eh.EventData) ([]byte, error)
	Unmarshal(eh.EventType, []byte) (eh.EventData, error)
	String() string
}

type EventStore

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

EventStore implements an eh.EventStore for PostgreSQL.

func NewEventStore

func NewEventStore(db *pg.DB) (*EventStore, error)

NewEventStore creates a new EventStore.

func (*EventStore) Clear

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

Clear clears the event storage.

func (*EventStore) CreateTables

func (s *EventStore) CreateTables(opts *orm.CreateTableOptions) error

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) RenameEvent

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

RenameEvent renames all instances of the event type.

func (*EventStore) Replace

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

Replace an event, the version must match. Useful for maintenance actions. Returns ErrAggregateNotFound if there is no aggregate.

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.

Jump to

Keyboard shortcuts

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