eventstore

package
v1.1.1-beta Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConcurrencyConflict = errors.New("concurrency error, no rows were affected")
View Source
var ErrEmptyTableNameSupplied = errors.New("empty eventTableName supplied")

Functions

This section is empty.

Types

type CompletedFilterItemBuilder

type CompletedFilterItemBuilder interface {
	// OccurredFrom sets the lower boundary for occurredAt (including this timestamp) for the whole Filter.
	OccurredFrom(occurredAtFrom time.Time) CompletedFilterItemBuilderWithOccurredFrom

	// OccurredUntil sets the upper boundary for occurredAt (including this timestamp) for the whole Filter.
	//
	// Currently, there is NO check if OccurredUntil is later than OccurredFrom!
	OccurredUntil(occurredAtUntil time.Time) CompletedFilterItemBuilderWithOccurredUntil

	// OrMatching finalizes the current FilterItem and starts a new one.
	OrMatching() EmptyFilterItemBuilder

	// Finalize returns the Filter once it has at least one FilterItem with at least one EventType OR one Predicate.
	Finalize() Filter
}

type CompletedFilterItemBuilderWithOccurredFrom

type CompletedFilterItemBuilderWithOccurredFrom interface {
	// AndOccurredUntil sets the upper boundary for occurredAt (including this timestamp) for the whole Filter.
	//
	// Currently, there is NO check if AndOccurredUntil is later than OccurredFrom!
	AndOccurredUntil(occurredAtUntil time.Time) CompletedFilterItemBuilderWithOccurredFromToUntil

	// Finalize returns the Filter once it has at least one FilterItem with at least one EventType OR one Predicate.
	Finalize() Filter
}

type CompletedFilterItemBuilderWithOccurredFromToUntil

type CompletedFilterItemBuilderWithOccurredFromToUntil interface {
	// Finalize returns the Filter once it has at least one FilterItem with at least one EventType OR one Predicate.
	Finalize() Filter
}

type CompletedFilterItemBuilderWithOccurredUntil

type CompletedFilterItemBuilderWithOccurredUntil interface {
	// Finalize returns the Filter once it has at least one FilterItem with at least one EventType OR one Predicate.
	Finalize() Filter
}

type EmptyFilterItemBuilder

type EmptyFilterItemBuilder interface {
	// AnyEventTypeOf adds one or multiple EventTypes to the current FilterItem.
	//
	// It sanitizes the input:
	//	- removing empty EventTypes ("")
	//	- sorting the EventTypes
	//	- removing duplicate EventTypes
	AnyEventTypeOf(eventType FilterEventTypeString, eventTypes ...FilterEventTypeString) FilterItemBuilderLackingPredicates

	// AnyPredicateOf adds one or multiple FilterPredicate(s) to the current FilterItem.
	//
	// It sanitizes the input:
	//	- removing empty/partial FilterPredicate(s) (key or val is "")
	//	- sorting the FilterPredicate(s)
	//	- removing duplicate FilterPredicate(s)
	AnyPredicateOf(predicate FilterPredicate, predicates ...FilterPredicate) FilterItemBuilderLackingEventTypes

	// AllPredicatesOf adds one or multiple FilterPredicate(s) to the current FilterItem expecting ALL predicates to match.
	//
	// It sanitizes the input:
	//	- removing empty/partial FilterPredicate(s) (key or val is "")
	//	- sorting the FilterPredicate(s)
	//	- removing duplicate FilterPredicate(s)
	AllPredicatesOf(predicate FilterPredicate, predicates ...FilterPredicate) FilterItemBuilderLackingEventTypes
}

type Filter

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

func (Filter) Items

func (f Filter) Items() []FilterItem

func (Filter) OccurredFrom

func (f Filter) OccurredFrom() time.Time

func (Filter) OccurredUntil

func (f Filter) OccurredUntil() time.Time

type FilterBuilder

type FilterBuilder interface {
	// Matching starts a new FilterItem.
	Matching() EmptyFilterItemBuilder

	// MatchingAnyEvent directly creates an empty Filter.
	MatchingAnyEvent() Filter

	// OccurredFrom sets the lower boundary for occurredAt (including this timestamp) for the whole Filter.
	OccurredFrom(occurredAtFrom time.Time) CompletedFilterItemBuilderWithOccurredFrom

	// OccurredUntil sets the upper boundary for occurredAt (including this timestamp) for the whole Filter.
	//
	// Currently, there is NO check if OccurredUntil is later than OccurredFrom!
	OccurredUntil(occurredAtUntil time.Time) CompletedFilterItemBuilderWithOccurredUntil
}

FilterBuilder builds a generic event filter to be used in DB type-specific eventstore implementations to build queries for the specific query language, e.g.: Postgres, Mysql, MongoDB, ... It is designed with the idea to only allow "useful" Filter combinations for event-sourced workflows:

  • empty filter
  • (eventType)
  • (eventType OR eventType...)
  • (predicate)
  • (predicate OR predicate...)
  • (predicate AND predicate...)
  • (eventType AND predicate)
  • (eventType AND (predicate OR predicate...))
  • (eventType AND (predicate AND predicate...))
  • ((eventType OR eventType...) AND (predicate OR predicate...))
  • ((eventType OR eventType...) AND (predicate AND predicate...))
  • ((eventType AND predicate) OR (eventType AND predicate)...) -> multiple FilterItem(s)

If occurredFrom or/and occurredUntil are added to the Filter, this will be AND concatenated to the whole Filter, e.g.:

  • ((eventType AND (predicate OR predicate...)) AND (occurredAt >= _timestamp_))
  • ((eventType AND (predicate OR predicate...)) AND ((occurredAt >= occurredFrom) AND (occurredAt <= occurredUntil)))

func BuildEventFilter

func BuildEventFilter() FilterBuilder

BuildEventFilter creates a FilterBuilder which must eventually be finalized with Finalize() or MatchingAnyEvent().

type FilterEventTypeString

type FilterEventTypeString = string

type FilterItem

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

func (FilterItem) AllPredicatesMustMatch

func (fi FilterItem) AllPredicatesMustMatch() bool

func (FilterItem) EventTypes

func (fi FilterItem) EventTypes() []FilterEventTypeString

func (FilterItem) Predicates

func (fi FilterItem) Predicates() []FilterPredicate

type FilterItemBuilderLackingEventTypes

type FilterItemBuilderLackingEventTypes interface {
	// AndAnyEventTypeOf adds one or multiple EventTypes to the current FilterItem.
	//
	// It sanitizes the input:
	//	- removing empty EventTypes ("")
	//	- sorting the EventTypes
	//	- removing duplicate EventTypes
	AndAnyEventTypeOf(eventType FilterEventTypeString, eventTypes ...FilterEventTypeString) CompletedFilterItemBuilder

	// OccurredFrom sets the lower boundary for occurredAt (including this timestamp) for the whole Filter.
	OccurredFrom(occurredAtFrom time.Time) CompletedFilterItemBuilderWithOccurredFrom

	// OccurredUntil sets the upper boundary for occurredAt (including this timestamp) for the whole Filter.
	//
	// Currently, there is NO check if OccurredUntil is later than OccurredFrom!
	OccurredUntil(occurredAtUntil time.Time) CompletedFilterItemBuilderWithOccurredUntil

	// OrMatching finalizes the current FilterItem and starts a new one.
	OrMatching() EmptyFilterItemBuilder

	// Finalize returns the Filter once it has at least one FilterItem with at least one EventType OR one Predicate.
	Finalize() Filter
}

type FilterItemBuilderLackingPredicates

type FilterItemBuilderLackingPredicates interface {
	// AndAnyPredicateOf adds one or multiple FilterPredicate(s) to the current FilterItem expecting ANY predicate to match.
	//
	// It sanitizes the input:
	//	- removing empty/partial FilterPredicate(s) (key or val is "")
	//	- sorting the FilterPredicate(s)
	//	- removing duplicate FilterPredicate(s)
	AndAnyPredicateOf(predicate FilterPredicate, predicates ...FilterPredicate) CompletedFilterItemBuilder

	// AndAllPredicatesOf adds one or multiple FilterPredicate(s) to the current FilterItem expecting ALL predicates to match.
	//
	// It sanitizes the input:
	//	- removing empty/partial FilterPredicate(s) (key or val is "")
	//	- sorting the FilterPredicate(s)
	//	- removing duplicate FilterPredicate(s)
	AndAllPredicatesOf(predicate FilterPredicate, predicates ...FilterPredicate) CompletedFilterItemBuilder

	// OccurredFrom sets the lower boundary for occurredAt (including this timestamp) for the whole Filter.
	OccurredFrom(occurredAtFrom time.Time) CompletedFilterItemBuilderWithOccurredFrom

	// OccurredUntil sets the upper boundary for occurredAt (including this timestamp) for the whole Filter.
	//
	// Currently, there is NO check if OccurredUntil is later than OccurredFrom!
	OccurredUntil(occurredAtUntil time.Time) CompletedFilterItemBuilderWithOccurredUntil

	// OrMatching finalizes the current FilterItem and starts a new one.
	OrMatching() EmptyFilterItemBuilder

	// Finalize returns the Filter once it has at least one FilterItem with at least one EventType OR one Predicate.
	Finalize() Filter
}

type FilterKeyString

type FilterKeyString = string

type FilterPredicate

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

func (FilterPredicate) Key

func (FilterPredicate) Val

type FilterValString

type FilterValString = string

type MaxSequenceNumberUint

type MaxSequenceNumberUint = uint

MaxSequenceNumberUint is a type alias for uint, representing the maximum sequence number for a "dynamic event stream".

type StorableEvent

type StorableEvent struct {
	EventType    string
	OccurredAt   time.Time
	PayloadJSON  []byte
	MetadataJSON []byte
}

StorableEvent is a DTO (data transfer object) used by the EventStore to append events and query them back.

It is built on scalars to be completely agnostic of the implementation of Domain Events in the client code.

While its properties are exported, it should only be constructed with the supplied factory methods:

  • BuildStorableEvent
  • BuildStorableEventWithEmptyMetadata

func BuildStorableEvent

func BuildStorableEvent(eventType string, occurredAt time.Time, payloadJSON []byte, metadataJSON []byte) StorableEvent

BuildStorableEvent is a factory method for StorableEvent.

It populates the StorableEvent with the given scalar input.

func BuildStorableEventWithEmptyMetadata

func BuildStorableEventWithEmptyMetadata(eventType string, occurredAt time.Time, payloadJSON []byte) StorableEvent

BuildStorableEventWithEmptyMetadata is a factory method for StorableEvent.

It populates the StorableEvent with the given scalar input and creates valid empty JSON for MetadataJSON.

type StorableEvents

type StorableEvents = []StorableEvent

StorableEvents is an alias type for a slice of StorableEvent

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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