sql

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2019 License: MIT Imports: 6 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConnFailedToAcquire occurs when a connection cannot be acquired within the timelimit
	ErrConnFailedToAcquire = errors.New("goengine: unable to acquire projection lock")
	// ErrProjectionFailedToLock occurs when the projector cannot acquire the projection lock
	ErrProjectionFailedToLock = errors.New("goengine: unable to acquire projection lock")
	// ErrProjectionPreviouslyLocked occurs when a projection was lock was acquired but a previous lock is still in place
	ErrProjectionPreviouslyLocked = errors.New("goengine: unable to lock projection due to a previous lock being in place")
	// ErrNoProjectionRequired occurs when a notification was being acquired but the projection was already at the indicated position
	ErrNoProjectionRequired = errors.New("goengine: no projection acquisition required")
)

Functions

This section is empty.

Types

type EventStreamLoader

type EventStreamLoader func(ctx context.Context, conn *sql.Conn, notification *ProjectionNotification, position int64) (goengine.EventStream, error)

EventStreamLoader loads a event stream based on the provided notification and state

type Execer

type Execer interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}

Execer a interface used to execute a query on a sql.DB, sql.Conn or sql.Tx

type Listener

type Listener interface {
	// Listen starts listening to the event stream and call the trigger when a event was appended
	Listen(ctx context.Context, trigger ProjectionTrigger) error
}

Listener listens to a event stream and triggers a notification when a event was appended

type MessageFactory

type MessageFactory interface {
	// CreateEventStream reconstructs the message from the provided rows
	CreateEventStream(rows *sql.Rows) (goengine.EventStream, error)
}

MessageFactory reconstruct messages from the database

type PersistenceStrategy

type PersistenceStrategy interface {
	CreateSchema(tableName string) []string
	ColumnNames() []string
	PrepareData([]goengine.Message) ([]interface{}, error)
	GenerateTableName(streamName goengine.StreamName) (string, error)
}

PersistenceStrategy interface describes strategy of persisting messages in the database

type ProjectionErrorAction

type ProjectionErrorAction int

ProjectionErrorAction a type containing the action that the projector should take after an error

const (
	// ProjectionFail indicated that the projection failed and cannot be recovered
	// This means that a human as a service is needed
	ProjectionFail ProjectionErrorAction = iota
	// ProjectionRetry indicated that the notification should be retried
	// This can be used in combination with retry mechanism in the ProjectorErrorCallback
	ProjectionRetry ProjectionErrorAction = iota
	// ProjectionIgnoreError indicated that the projection failed but the failure can be ignored
	// This can be used when the ProjectorErrorCallback recovered the system from the error
	ProjectionIgnoreError ProjectionErrorAction = iota
)

type ProjectionErrorCallback

type ProjectionErrorCallback func(err error, notification *ProjectionNotification) ProjectionErrorAction

ProjectionErrorCallback is a function used to determin what action to take based on a failed projection

type ProjectionHandlerError

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

ProjectionHandlerError an error indicating that a projection handler failed

func NewProjectionHandlerError

func NewProjectionHandlerError(err error) *ProjectionHandlerError

NewProjectionHandlerError return a ProjectionHandlerError with the cause being the provided error

func (*ProjectionHandlerError) Cause

func (e *ProjectionHandlerError) Cause() error

Cause returns the actual projection errors. This also adds support for github.com/pkg/errors.Cause

func (*ProjectionHandlerError) Error

func (e *ProjectionHandlerError) Error() string

Error return the error message

type ProjectionNotification

type ProjectionNotification struct {
	No          int64  `json:"no"`
	AggregateID string `json:"aggregate_id"`
}

ProjectionNotification is a representation of the data provided by database notify

type ProjectionRawState

type ProjectionRawState struct {
	Position        int64
	ProjectionState []byte
}

ProjectionRawState the raw projection projectionState returned by ProjectionStorage.Acquire

type ProjectionState

type ProjectionState struct {
	Position        int64
	ProjectionState interface{}
}

ProjectionState is a projection projectionState

type ProjectionStateDecoder added in v0.9.0

type ProjectionStateDecoder func(data []byte) (interface{}, error)

ProjectionStateDecoder is a func to unmarshal the ProjectionRawState.ProjectionState

type ProjectionStateEncoder added in v0.9.0

type ProjectionStateEncoder func(interface{}) ([]byte, error)

ProjectionStateEncoder is a func to marshal the ProjectionState.ProjectionState

type ProjectionStateInitializer added in v0.9.0

type ProjectionStateInitializer func(ctx context.Context) (interface{}, error)

ProjectionStateInitializer is a func to initialize a ProjectionState.ProjectionState

type ProjectionStorage added in v0.9.0

type ProjectionStorage interface {
	// PersistState persists the state of the projection
	PersistState(conn Execer, notification *ProjectionNotification, state ProjectionState) error

	// Acquire this function is used to acquire the projection and it's projectionState
	// A projection can only be acquired once and must be released using the returned func
	Acquire(ctx context.Context, conn *sql.Conn, notification *ProjectionNotification) (func(), *ProjectionRawState, error)
}

ProjectionStorage is an interface for handling the projection storage

type ProjectionTrigger

type ProjectionTrigger func(ctx context.Context, notification *ProjectionNotification) error

ProjectionTrigger triggers the notification for processing

type Queryer

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

Queryer an interface used to query a sql.DB, sql.Conn or sql.Tx

type ReadOnlyEventStore

type ReadOnlyEventStore interface {
	// LoadWithConnection returns a eventstream based on the provided constraints using the provided Queryer
	LoadWithConnection(ctx context.Context, conn Queryer, streamName goengine.StreamName, fromNumber int64, count *uint, metadataMatcher metadata.Matcher) (goengine.EventStream, error)
}

ReadOnlyEventStore an interface describing a readonly event store that supports providing a SQL conn

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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