eventstore

package
v0.0.0-...-301ae46 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2015 License: AGPL-3.0 Imports: 12 Imported by: 2

Documentation

Overview

Deals with persisting events to disk and querying them. No network is involved in any of the code in this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// The name of the stream to which this event shall be stored.
	Stream StreamName

	// The data that is to be stored for this event. Can be an
	// arbitrary byte slice.
	Data []byte
}

An event that has not yet been persisted to disk.

type EventId

type EventId []byte

type EventStore

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

Instance of an event store. All of its functions are threadsafe.

func New

func New(stor storage.Storage) (*EventStore, error)

Create a new event store instance.

func (*EventStore) Add

func (v *EventStore) Add(event Event) (EventId, error)

Store an event to the event store. Returns the unique event id that the event was stored under. As long as no error occurred, of course.

func (*EventStore) ListStreams

func (v *EventStore) ListStreams(start StreamName, maxItems int) chan StreamName

List the available streams through a stream.

func (*EventStore) Query

func (v *EventStore) Query(req QueryRequest) (chan StoredEvent, error)

Query events from an event store. If the request is malformed in any way, an error is returned. Otherwise, the query result is streamed through the res channel in chronological order.

Currently this function will make error checks synchronously. If all looks good, streaming the results through `res` is done asynchronously.

TODO: Also make the error checking asynchronously, to minimize IO blocking when calling this function.

func (*EventStore) RegisterPublishedEventsChannel

func (v *EventStore) RegisterPublishedEventsChannel(publisher chan StoredEvent)

Register a channel where are published events will be pushed to. Multiple channels can be registered.

type QueryRequest

type QueryRequest struct {
	Stream []byte
	FromId []byte
	ToId   []byte
}

A query request.

type StoredEvent

type StoredEvent struct {
	// The ID for the stored event. No other event exists with name
	// Stream and ID Id.
	Id EventId

	// The event that was persisted.
	Event
}

An event that has previously been persisted to disk.

type StreamName

type StreamName []byte

A stream name.

Jump to

Keyboard shortcuts

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