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 ¶
- func EnsureSchema(ctx context.Context, pool *pgxpool.Pool) error
- type EpochCache
- type Store
- func (s *Store) Batch(vaultID string, fn func(tx storage.BatchTx) error) error
- func (s *Store) Close()
- func (s *Store) Delete(vaultID, recordType, recordID string) error
- func (s *Store) DeleteVault(vaultID string) error
- func (s *Store) Get(vaultID, recordType, recordID string) (*storage.Envelope, error)
- func (s *Store) List(vaultID, recordType string) ([]string, error)
- func (s *Store) ListVaults() ([]string, error)
- func (s *Store) Pool() *pgxpool.Pool
- func (s *Store) Put(vaultID, recordType, recordID string, envelope *storage.Envelope) error
- func (s *Store) PutCAS(vaultID, recordType, recordID string, expectedVersion uint64, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
NewRepository returns a Repository backed by the given pgx connection pool.
func NewRepositoryFromDSN ¶
NewRepositoryFromDSN creates a connection pool from a DSN string, ensures the schema exists, and returns a new Repository.
func (*Store) DeleteVault ¶
func (*Store) ListVaults ¶
func (*Store) Pool ¶
Pool returns the underlying connection pool. This is useful for sharing the pool with other components such as the epoch cache.