postgres

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package postgres implements storage.Repository backed by PostgreSQL.

The records table uses a composite primary key (vault_id, record_type, record_id) that mirrors the key space used by the BBolt and in-memory backends. Envelope fields are stored as individual columns to avoid JSON serialisation overhead and to leverage native BYTEA storage for nonce and ciphertext data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureSchema

func EnsureSchema(ctx context.Context, pool *pgxpool.Pool) error

EnsureSchema creates the required tables and indexes if they do not exist. It is safe to call on every startup (all statements use IF NOT EXISTS).

Types

type EpochCache

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

EpochCache implements vault.EpochCache backed by PostgreSQL.

It uses a write-through cache: reads come from an in-memory map, writes persist to PostgreSQL and update the in-memory map atomically. This mirrors the BoltEpochCache pattern in vault/epochcache.go.

func NewEpochCache

func NewEpochCache(ctx context.Context, pool *pgxpool.Pool) (*EpochCache, error)

NewEpochCache returns a persistent epoch cache backed by PostgreSQL. It loads all existing entries into memory on initialisation.

func (*EpochCache) GetMaxEpochSeen

func (c *EpochCache) GetMaxEpochSeen(vaultID string) uint64

GetMaxEpochSeen returns the highest epoch seen for a vault.

func (*EpochCache) SetMaxEpochSeen

func (c *EpochCache) SetMaxEpochSeen(vaultID string, epoch uint64) error

SetMaxEpochSeen persists the new max epoch for a vault. It returns vault.ErrRollbackDetected if the provided epoch is less than the currently stored value.

type Store

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

Store implements storage.Repository backed by PostgreSQL.

func NewRepository

func NewRepository(pool *pgxpool.Pool) *Store

NewRepository returns a Repository backed by the given pgx connection pool.

func NewRepositoryFromDSN

func NewRepositoryFromDSN(ctx context.Context, dsn string) (*Store, error)

NewRepositoryFromDSN creates a connection pool from a DSN string, ensures the schema exists, and returns a new Repository.

func (*Store) Batch

func (s *Store) Batch(vaultID string, fn func(tx storage.BatchTx) error) error

func (*Store) Close

func (s *Store) Close()

Close closes the underlying connection pool.

func (*Store) Delete

func (s *Store) Delete(vaultID, recordType, recordID string) error

func (*Store) DeleteVault

func (s *Store) DeleteVault(vaultID string) error

func (*Store) Get

func (s *Store) Get(vaultID, recordType, recordID string) (*storage.Envelope, error)

func (*Store) List

func (s *Store) List(vaultID, recordType string) ([]string, error)

func (*Store) ListVaults

func (s *Store) ListVaults() ([]string, error)

func (*Store) Pool

func (s *Store) Pool() *pgxpool.Pool

Pool returns the underlying connection pool. This is useful for sharing the pool with other components such as the epoch cache.

func (*Store) Put

func (s *Store) Put(vaultID, recordType, recordID string, envelope *storage.Envelope) error

func (*Store) PutCAS

func (s *Store) PutCAS(vaultID, recordType, recordID string, expectedVersion uint64, envelope *storage.Envelope) error

Jump to

Keyboard shortcuts

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