postgres

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 14 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 = 32
)

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 Backend

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

Backend implements timebox.Backend using Postgres

func Open

func Open(cfgs ...Config) (*Backend, error)

Open opens Postgres-backed Backend

func (*Backend) Append

func (b *Backend) Append(reqs ...timebox.AppendRequest) error

Append appends every request's events if each expected sequence matches

func (*Backend) Close

func (b *Backend) Close() error

Close closes the Postgres connection pool

func (*Backend) GetAggregateStatus

func (b *Backend) GetAggregateStatus(
	id timebox.AggregateID,
) (string, error)

GetAggregateStatus gets the current status for an aggregate

func (*Backend) ListAggregates

func (b *Backend) ListAggregates(
	typ timebox.ID,
) ([]timebox.AggregateID, error)

ListAggregates lists aggregate IDs of the given type, or of every type when it is empty

func (*Backend) ListAggregatesByStatus

func (b *Backend) ListAggregatesByStatus(
	q timebox.StatusQuery,
) ([]timebox.StatusEntry, error)

ListAggregatesByStatus lists aggregates matching the query

func (*Backend) ListAggregatesByTag

func (b *Backend) ListAggregatesByTag(
	tag string,
) ([]timebox.AggregateID, error)

ListAggregatesByTag lists aggregates for a tag

func (*Backend) LoadEvents

func (b *Backend) LoadEvents(
	req timebox.LoadEventsRequest,
) (*timebox.EventsResult, error)

LoadEvents loads events starting at fromSeq

func (*Backend) LoadSnapshot

func (b *Backend) LoadSnapshot(
	req timebox.LoadSnapshotRequest,
) (*timebox.SnapshotRecord, error)

LoadSnapshot loads the snapshot and trailing events for an aggregate

func (*Backend) NewStore

func (b *Backend) NewStore(cfgs ...timebox.Config) (*timebox.Store, error)

NewStore creates a Store using the current Postgres Backend

func (*Backend) SaveSnapshot

func (b *Backend) SaveSnapshot(
	req timebox.SnapshotRequest,
) error

SaveSnapshot saves a snapshot if the provided sequence is not older

type Config

type Config struct {
	URL       string
	Prefix    string
	MaxConns  int32
	Publisher timebox.Publisher
}

Config configures a Postgres Backend

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config populated with sensible defaults

func (Config) Validate

func (c Config) Validate() error

Validate reports whether the configuration contains invalid values

func (Config) With

func (c Config) With(other Config) Config

With overlays the non-zero values from other onto cfg

Jump to

Keyboard shortcuts

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