postgres

package
v0.0.0-...-2fcb348 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultURL is the default Postgres connection URL
	DefaultURL = "postgres://localhost:5432/postgres?sslmode=disable"

	// DefaultPrefix is the default logical store namespace
	DefaultPrefix = "timebox"

	// DefaultMaxConns is the default pgx pool size
	DefaultMaxConns = 96
)

Variables

View Source
var (
	// ErrURLRequired indicates URL must be provided
	ErrURLRequired = errors.New("postgres URL is required")

	// ErrPrefixRequired indicates Prefix must be provided
	ErrPrefixRequired = errors.New("prefix is required")

	// ErrInvalidMaxConns indicates MaxConns must be positive
	ErrInvalidMaxConns = errors.New("max conns must be positive")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	URL      string
	Prefix   string
	MaxConns int32
}

Config configures Postgres persistence

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config populated with sensible defaults

func (Config) Validate

func (cfg Config) Validate() error

Validate reports whether the configuration contains invalid values

func (Config) With

func (cfg Config) With(other Config) Config

With overlays the non-zero values from other onto cfg

type Persistence

type Persistence struct {
	timebox.AlwaysReady
	Config
	// contains filtered or unexported fields
}

Persistence implements timebox.Persistence using Postgres

func NewPersistence

func NewPersistence(cfgs ...Config) (*Persistence, error)

NewPersistence creates Postgres-backed Persistence

func (*Persistence) Append

func (p *Persistence) Append(req timebox.AppendRequest) error

Append appends events if the expected sequence matches

func (*Persistence) Close

func (p *Persistence) Close() error

Close closes the Postgres connection pool

func (*Persistence) GetAggregateStatus

func (p *Persistence) GetAggregateStatus(
	id timebox.AggregateID,
) (string, error)

GetAggregateStatus gets the current status for an aggregate

func (*Persistence) ListAggregates

func (p *Persistence) ListAggregates(
	id timebox.AggregateID,
) ([]timebox.AggregateID, error)

ListAggregates lists aggregate IDs matching the given prefix

func (*Persistence) ListAggregatesByLabel

func (p *Persistence) ListAggregatesByLabel(
	label, value string,
) ([]timebox.AggregateID, error)

ListAggregatesByLabel lists aggregates for a label/value pair

func (*Persistence) ListAggregatesByStatus

func (p *Persistence) ListAggregatesByStatus(
	status string,
) ([]timebox.StatusEntry, error)

ListAggregatesByStatus lists aggregates for the given status

func (*Persistence) ListLabelValues

func (p *Persistence) ListLabelValues(label string) ([]string, error)

ListLabelValues lists values currently used for a label

func (*Persistence) LoadEvents

func (p *Persistence) LoadEvents(
	req timebox.LoadEventsRequest,
) (*timebox.EventsResult, error)

LoadEvents loads events starting at fromSeq

func (*Persistence) LoadSnapshot

func (p *Persistence) LoadSnapshot(
	req timebox.LoadSnapshotRequest,
) (*timebox.SnapshotRecord, error)

LoadSnapshot loads the snapshot and trailing events for an aggregate

func (*Persistence) NewStore

func (p *Persistence) NewStore(cfg timebox.Config) (*timebox.Store, error)

NewStore creates a Store using the current Postgres Persistence

func (*Persistence) SaveSnapshot

func (p *Persistence) SaveSnapshot(
	req timebox.SnapshotRequest,
) error

SaveSnapshot saves a snapshot if the provided sequence is not older

Jump to

Keyboard shortcuts

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