postgres

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package postgres implements engine.CheckpointStore on top of PostgreSQL.

The driver is github.com/jackc/pgx/v5 (used directly via pgxpool; no database/sql layer). Suitable for multi-process daemons, horizontally scaled vesseld fleets, and production durability requirements where SQLite's single-writer model is insufficient.

Usage

store, err := postgres.Open(ctx, "postgres://flowcraft:secret@db:5432/flowcraft?sslmode=disable")
if err != nil { return err }
defer store.Close()

// Wire into engine.LoadAndResume / engine.Host.Checkpointer.

Schema

One row per ExecID; Save uses INSERT ... ON CONFLICT DO UPDATE so the table always holds the latest checkpoint per execution. Migrations run idempotently inside Open; expose [Migrate] for callers that want explicit control.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*config)

Option configures Open / Wrap.

func WithTable

func WithTable(name string) Option

WithTable overrides the table name (default "engine_checkpoints"). Useful for multi-tenant deployments that namespace tables per vessel.

type Store

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

Store persists engine.Checkpoint records in a PostgreSQL table. One row per ExecID; Save UPSERTs the latest snapshot. Safe for concurrent use across goroutines and processes (the unique constraint on exec_id makes the UPSERT idempotent).

func Open

func Open(ctx context.Context, dsn string, opts ...Option) (*Store, error)

Open creates a Store backed by a fresh pgxpool.Pool against dsn. The Store takes ownership of the pool — closing the Store closes the pool. Migrations are run synchronously before Open returns.

func Wrap

func Wrap(pool *pgxpool.Pool, opts ...Option) *Store

Wrap builds a Store on top of an existing pgxpool.Pool. The caller retains ownership of pool; closing the Store does not close it. Migrate must be called before any Save / Load when callers use Wrap.

func (*Store) Close

func (s *Store) Close() error

Close releases resources owned by the Store. Safe to call repeatedly; only the first call has an effect when the Store owns its pool.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, execID string) error

Delete removes the checkpoint for execID. Missing exec ids are a no-op (no error). Implements engine.CheckpointDeleter.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]string, error)

List enumerates persisted exec ids. Implements engine.CheckpointLister.

func (*Store) Load

func (s *Store) Load(ctx context.Context, execID string) (*engine.Checkpoint, error)

Load returns the latest checkpoint for execID, or (nil, nil) if none exists.

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context) error

Migrate creates the checkpoint table if it does not yet exist. Run automatically by Open; expose for callers that build the Store via Wrap.

func (*Store) Save

func (s *Store) Save(ctx context.Context, cp engine.Checkpoint) error

Save persists cp, overwriting any existing record with the same ExecID.

Jump to

Keyboard shortcuts

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