persistence

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package persistence defines the interfaces Ax uses to persist data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeginTx

func BeginTx(ctx context.Context) (Tx, Committer, error)

BeginTx starts a new transaction using the data store in ctx.

func GetOrBeginTx

func GetOrBeginTx(ctx context.Context) (Tx, Committer, error)

GetOrBeginTx returns the transaction stored in ctx, or starts a new one if ctx does not contain a transaction.

If a new transaction is started, the caller is said to "own" the transaction, that is, the caller is responsible for committing the transaction.

If ctx already contains a transaction, the caller is said to "participate" in the transaction, but is not responsible for committing. In this case, the returned Committer is configured such that Commit() and Rollback() are no-ops that always return nil.

func WithDataStore

func WithDataStore(parent context.Context, ds DataStore) context.Context

WithDataStore returns a new context derived from parent that contains a DataStore.

The data store can be retrieved from the context with GetDataStore().

func WithTx

func WithTx(parent context.Context, tx Tx) context.Context

WithTx returns a new context derived from parent that contains a transaction.

The transaction can be retrieved from the context with GetTx().

Types

type Committer

type Committer interface {
	// Commit applies the changes to the data store.
	Commit() error

	// Rollback discards the changes without applying them to the data store.
	Rollback() error
}

Committer is an interface used to commit and rollback persistence transactions.

type DataStore

type DataStore interface {
	// BeginTx starts a new transaction.
	BeginTx(ctx context.Context) (Tx, Committer, error)
}

DataStore is an interface for accessing a transactional data store.

func GetDataStore

func GetDataStore(ctx context.Context) (ds DataStore, ok bool)

GetDataStore returns the DataStore in ctx.

If ctx does not contain a data store then ok is false.

type InboundInjector

type InboundInjector struct {
	DataStore DataStore
	Next      endpoint.InboundPipeline
}

InboundInjector is an implementation of endpoint.InboundPipeline that injects a data store into the context.

func (*InboundInjector) Accept

Accept calls i.Next.Accept() with a context derived from ctx and containing i.DataStore.

func (*InboundInjector) Initialize

func (i *InboundInjector) Initialize(ctx context.Context, ep *endpoint.Endpoint) error

Initialize is called during initialization of the endpoint, after the transport is initialized. It can be used to inspect or further configure the endpoint as per the needs of the pipeline.

type OutboundInjector

type OutboundInjector struct {
	DataStore DataStore
	Next      endpoint.OutboundPipeline
}

OutboundInjector is an implementation of endpoint.OutboundPipeline that injects a data store into the context.

func (*OutboundInjector) Accept

Accept calls i.Next.Accept() with a context derived from ctx and containing i.DataStore.

func (*OutboundInjector) Initialize

func (i *OutboundInjector) Initialize(ctx context.Context, ep *endpoint.Endpoint) error

Initialize is called during initialization of the endpoint, after the transport is initialized. It can be used to inspect or further configure the endpoint as per the needs of the pipeline.

type Tx

type Tx interface {
	// DataStore returns the DataStore that the transaction operates on.
	DataStore() DataStore
}

Tx represents an atomic unit-of-work performed on a DataStore.

func GetTx

func GetTx(ctx context.Context) (tx Tx, ok bool)

GetTx returns the transaction stored in ctx.

If ctx does not contain a transaction then ok is false.

Transactions are made available via the context so that application-defined message handlers can optionally perform some additional storage operations within the same transaction as infrastructure features such as the outbox system.

Jump to

Keyboard shortcuts

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