postgres

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package postgres provides the PostgreSQL-backed implementation of the workflow.Repository port, built on native pgx.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repository

type Repository struct{}

Repository implements workflow.Repository using pgx. It is stateless: every method receives the pgxtx.DBTX to run against, so the caller decides whether to use a plain pool connection or an existing transaction.

func NewRepository

func NewRepository() *Repository

NewRepository creates a stateless PostgreSQL-backed workflow repository.

func (*Repository) AppendEvent

func (r *Repository) AppendEvent(ctx context.Context, db pgxtx.DBTX, e *workflow.Event) error

AppendEvent inserts e, computing its Seq in SQL as COALESCE(MAX(seq), 0) + 1 for the case so concurrent appends cannot silently collide — the UNIQUE(case_id, seq) constraint is the backstop. e.Seq is overwritten with the value actually persisted.

func (*Repository) Create

func (r *Repository) Create(ctx context.Context, db pgxtx.DBTX, c *workflow.Case) error

Create inserts a new case. A unique-violation on (domain, external_id) is mapped to workflow.ErrCaseExists.

func (*Repository) GetByExternalID

func (r *Repository) GetByExternalID(ctx context.Context, db pgxtx.DBTX, domain, externalID string) (*workflow.Case, error)

GetByExternalID retrieves a single case by its (domain, external_id) pair.

func (*Repository) GetByID

func (r *Repository) GetByID(ctx context.Context, db pgxtx.DBTX, id uuid.UUID) (*workflow.Case, error)

GetByID retrieves a single case by its primary key.

func (*Repository) ListByEligibility

func (r *Repository) ListByEligibility(ctx context.Context, db pgxtx.DBTX, f workflow.InboxFilter) ([]workflow.Case, error)

ListByEligibility returns open cases matching f. States, when non-empty, restricts results to cases whose current node is one of those IDs — the mapping from Position/Unit to that set of node IDs is resolved by the caller (see workflow.Engine.EligibilityFor), not by this query.

func (*Repository) ListEvents

func (r *Repository) ListEvents(ctx context.Context, db pgxtx.DBTX, caseID uuid.UUID) ([]workflow.Event, error)

ListEvents returns every event for caseID, ordered by seq ascending.

func (*Repository) Update

func (r *Repository) Update(ctx context.Context, db pgxtx.DBTX, c *workflow.Case) error

Update persists every mutable field of c.

Jump to

Keyboard shortcuts

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