postgres

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package postgres implements notify's durable inbox on a host-owned PostgreSQL pool. Hosts explicitly migrate before use and authorize every recipient. It starts no workers, sends no messages and never owns the host's pool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, pool *pgxpool.Pool, schema string) error

Migrate applies this library's versioned migrations in a transaction. The host creates the schema and supplies a pool with DDL permission.

func MigrateDB

func MigrateDB(ctx context.Context, db *sql.DB, schema string) error

MigrateDB is Migrate for a host's database/sql DDL connection.

Types

type Config

type Config struct{ Schema, Scope string }

Config binds a store to one local application/tenant scope in a migrated schema.

type Store

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

Store retains notices and actionable items. Scope and recipients are data isolation boundaries; authorization remains with the host.

func New

func New(pool *pgxpool.Pool, cfg Config) (*Store, error)

New binds an existing pool; it neither migrates nor opens connections.

func (*Store) EraseRecipient

func (s *Store) EraseRecipient(ctx context.Context, r notify.Recipient) error

EraseRecipient deletes an inbox and permanently fences delayed publications. This is account erasure, not the operation for dismissing one item.

func (*Store) EraseRecipientTx

func (s *Store) EraseRecipientTx(ctx context.Context, tx pgx.Tx, r notify.Recipient) error

EraseRecipientTx joins account erasure in the host's transaction.

func (*Store) Get

func (s *Store) Get(ctx context.Context, r notify.Recipient, id string) (notify.Item, error)

Get reads a named receipt, including an archived one, for its recipient.

func (*Store) GetRecipients

func (s *Store) GetRecipients(ctx context.Context, rs []notify.Recipient, id string) (notify.Item, error)

GetRecipients reads a receipt only when its recipient is in the host's fresh authorized set. An absent or newly unlinked recipient reads as not found.

func (*Store) List

List reads one authorized recipient's inbox, newest first. Restart scans from an empty cursor to discover late commits; cursors are not delivery watermarks.

func (*Store) ListRecipients

func (s *Store) ListRecipients(ctx context.Context, recipients []notify.Recipient, o notify.ListOptions) (notify.Page, error)

ListRecipients reads only the recipients the host authorized for this request. Filtering happens in SQL before pagination, so an unlinked recipient consumes no page slots. Empty recipients returns an empty page. Cursors bind the normalized recipient set and filters; restart paging after access changes.

func (*Store) Publish

func (s *Store) Publish(ctx context.Context, in notify.Input) (notify.Item, error)

Publish inserts once per origin and recipient. Retries preserve content and every local read/workflow transition, including after a crash before an ack.

func (*Store) PublishTx

func (s *Store) PublishTx(ctx context.Context, tx pgx.Tx, in notify.Input) (notify.Item, error)

PublishTx joins the domain change's transaction. The transaction must reach the same database as the store; the caller commits or rolls it back.

func (*Store) SetDismissed

func (s *Store) SetDismissed(ctx context.Context, r notify.Recipient, id string, dismissed bool) (notify.Item, error)

SetDismissed archives or restores a recipient's receipt, independently of read state and domain/workflow resolution.

func (*Store) SetDismissedRecipients

func (s *Store) SetDismissedRecipients(ctx context.Context, rs []notify.Recipient, id string, dismissed bool) (notify.Item, error)

SetDismissedRecipients changes only a receipt in the host's currently authorized set. Retried dismissal preserves its original timestamp.

func (*Store) SetRead

func (s *Store) SetRead(ctx context.Context, r notify.Recipient, id string, read bool) (notify.Item, error)

SetRead changes only local read state. It never resolves an actionable item.

func (*Store) SetReadRecipients

func (s *Store) SetReadRecipients(ctx context.Context, rs []notify.Recipient, id string, read bool) (notify.Item, error)

SetReadRecipients updates authorized receipt state and returns the canonical item/revision. Reading does not dismiss the receipt or resolve a workflow.

func (*Store) Transition

func (s *Store) Transition(ctx context.Context, r notify.Recipient, id string, revision int64, status notify.Status) (notify.Item, error)

Transition changes workflow state under optimistic concurrency. The caller must perform/authorize any domain action first, or use TransitionTx in the same transaction as that action. General notices cannot become work items.

func (*Store) TransitionTx

func (s *Store) TransitionTx(ctx context.Context, tx pgx.Tx, r notify.Recipient, id string, revision int64, status notify.Status) (notify.Item, error)

TransitionTx joins a host's transaction; reading and resolving remain separate.

Jump to

Keyboard shortcuts

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