Documentation
¶
Overview ¶
Package dblog defines the shared user-facing contracts for database log backends.
Index ¶
- Variables
- func Bodies[T any](seq iter.Seq2[Event, error]) iter.Seq2[T, error]
- func ContextOf(options OpenOptions) context.Context
- func Events[T Event](decoder Decoder[T]) iter.Seq2[Event, error]
- func Filter(seq iter.Seq2[Event, error], predicates ...Predicate) iter.Seq2[Event, error]
- func Flashbacks(seq iter.Seq2[Event, error]) iter.Seq2[any, error]
- func RecoveryPlan(seq iter.Seq2[Event, error]) iter.Seq2[RecoveryStep, error]
- func Register(backend Backend) error
- type Backend
- type Checkpoint
- type Decoder
- type Event
- type OpenOption
- type OpenOptions
- type Position
- type Predicate
- type RecoveryStep
- type Registry
- type Reversible
- type SeqDecoder
- type Source
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidBackend is returned when a backend does not expose a driver. ErrInvalidBackend = errors.New("invalid backend") // ErrBackendExists is returned when a registry already has a driver. ErrBackendExists = errors.New("backend already registered") // ErrBackendNotFound is returned when a driver is not registered. ErrBackendNotFound = errors.New("backend not found") )
Functions ¶
func ContextOf ¶
func ContextOf(options OpenOptions) context.Context
ContextOf returns the context carried by open options, or context.Background.
func Flashbacks ¶
Flashbacks yields compensating operations from reversible events.
func RecoveryPlan ¶ added in v0.3.0
RecoveryPlan yields safe compensating operations with checkpoints.
Types ¶
type Backend ¶
type Backend interface {
Driver() string
Open(OpenOptions) (Decoder[Event], error)
}
Backend opens decoders for one database log driver.
type Checkpoint ¶
Checkpoint stores the last consumed event location for a source.
func CheckpointOf ¶
func CheckpointOf(event Event) Checkpoint
CheckpointOf returns a portable checkpoint for the event.
type Event ¶
type Event interface {
SourceDriver() string
SourceName() string
PositionDriver() string
PositionString() string
Kind() string
Raw() []byte
Body() any
}
Event is the minimal common shape shared by database log backends.
type OpenOption ¶
type OpenOption func(*openOptions)
OpenOption configures backend decoder creation.
func WithCheckpoint ¶
func WithCheckpoint(checkpoint Checkpoint) OpenOption
WithCheckpoint resumes an opened backend after a previously consumed event.
func WithContext ¶
func WithContext(ctx context.Context) OpenOption
WithContext sets the cancellation context used by context-aware backends.
func WithDSN ¶
func WithDSN(dsn string) OpenOption
WithDSN sets a backend-specific data source name.
func WithPath ¶
func WithPath(path string) OpenOption
WithPath opens a backend from a local path when supported.
func WithReader ¶
func WithReader(reader io.Reader) OpenOption
WithReader opens a backend from a stream when supported.
func WithSource ¶
func WithSource(source Source) OpenOption
WithSource sets the source metadata for opened events.
type OpenOptions ¶
OpenOptions exposes backend decoder creation options to backend packages.
type Position ¶
Position identifies a backend-specific location in a database log stream.
func PositionOf ¶
PositionOf returns the common position value for an event.
func StartPositionOf ¶
func StartPositionOf(options OpenOptions) Position
StartPositionOf returns the checkpoint position carried by open options.
type RecoveryStep ¶ added in v0.3.0
type RecoveryStep struct {
Checkpoint Checkpoint
Operation any
}
RecoveryStep is one safe compensating operation with its source checkpoint.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores backend drivers.
var DefaultRegistry Registry
DefaultRegistry is used by package-level Register and Open.
type Reversible ¶
Reversible is implemented by events that can emit a compensating operation.
type SeqDecoder ¶
type SeqDecoder struct {
// contains filtered or unexported fields
}
SeqDecoder adapts an event iterator to Decoder.
func NewSeqDecoder ¶
NewSeqDecoder creates a decoder from an event iterator.