rangedb

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2019 License: BSD-3-Clause Imports: 2 Imported by: 4

README

RangeDB

Build Status Go Report Card Test Coverage Maintainability GoDoc Go Version Release License

An event store database in Go. This package includes a stand-alone database and web server along with a library for embedding event sourced applications.

Examples are provided here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEventStream

func GetEventStream(message AggregateMessage) string

GetEventStream returns the stream name for an event.

func GetEventsByAggregateTypes

func GetEventsByAggregateTypes(store Store, aggregateTypes ...string) []<-chan *Record

GetEventsByAggregateTypes returns a slice of Record channels by aggregateType.

func GetStream

func GetStream(aggregateType, aggregateID string) string

GetStream returns the stream name for an aggregateType and aggregateID.

func MergeRecordChannelsInOrder

func MergeRecordChannelsInOrder(channels []<-chan *Record) <-chan *Record

MergeRecordChannelsInOrder combines record channels ordered by record.GlobalSequenceNumber.

func ReplayEvents

func ReplayEvents(store Store, subscribers ...RecordSubscriber)

ReplayEvents applies all events to each subscriber.

Types

type AggregateMessage

type AggregateMessage interface {
	AggregateID() string
	AggregateType() string
}

AggregateMessage is the interface that supports building an event stream name.

type Event

type Event interface {
	AggregateMessage
	EventType() string
}

Event is the interface that defines the required event methods.

type Record

type Record struct {
	AggregateType        string      `msgpack:"a" json:"aggregateType"`
	AggregateID          string      `msgpack:"i" json:"aggregateID"`
	GlobalSequenceNumber uint64      `msgpack:"g" json:"globalSequenceNumber"`
	StreamSequenceNumber uint64      `msgpack:"s" json:"sequenceNumber"`
	InsertTimestamp      uint64      `msgpack:"u" json:"insertTimestamp"`
	EventID              string      `msgpack:"e" json:"eventID"`
	EventType            string      `msgpack:"t" json:"eventType"`
	Data                 interface{} `msgpack:"d" json:"data"`
	Metadata             interface{} `msgpack:"m" json:"metadata"`
}

Record contains event data and metadata.

type RecordIoStream

type RecordIoStream interface {
	Read(io.Reader) (<-chan *Record, <-chan error)
	Write(io.Writer, <-chan *Record) <-chan error
	Bind(events ...Event)
}

RecordIoStream is the interface that (de)serializes a stream of Records.

type RecordSerializer

type RecordSerializer interface {
	Serialize(record *Record) ([]byte, error)
	Deserialize(data []byte) (*Record, error)
	Bind(events ...Event)
}

RecordSerializer is the interface that (de)serializes Records.

type RecordSubscriber

type RecordSubscriber interface {
	Accept(record *Record)
}

RecordSubscriber is the interface that defines how a projection receives Records.

type Store

type Store interface {
	AllEvents() <-chan *Record
	EventsByStream(stream string) <-chan *Record
	EventsByStreamStartingWith(stream string, eventNumber uint64) <-chan *Record
	EventsByAggregateType(aggregateType string) <-chan *Record
	EventsByAggregateTypes(aggregateTypes ...string) <-chan *Record
	EventsByAggregateTypeStartingWith(aggregateType string, eventNumber uint64) <-chan *Record
	Save(event Event, metadata interface{}) error
	SaveEvent(aggregateType, aggregateID, eventType, eventID string, event, metadata interface{}) error
	Subscribe(subscribers ...RecordSubscriber)
	SubscribeAndReplay(subscribers ...RecordSubscriber)
}

Store is the interface that stores and retrieves event records.

Jump to

Keyboard shortcuts

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