postgres

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package postgres is the pgx implementation of metadata.Repository. It is the only code in the system that issues SQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repo

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

Repo persists File records in Postgres.

func New

func New(pool *pgxpool.Pool) *Repo

New returns a repository backed by the given pool.

func (*Repo) ClaimIdempotencyKey

func (r *Repo) ClaimIdempotencyKey(ctx context.Context, key string) (bool, *metadata.IdempotencyRecord, error)

ClaimIdempotencyKey inserts the key as pending, claiming it. If the key already exists, the insert no-ops and we read back the existing row so the caller can replay (completed) or reject (pending).

func (*Repo) Create

func (r *Repo) Create(ctx context.Context, f *metadata.File) error

Create inserts a new record. ID and StorageKey are supplied by the caller.

func (*Repo) CreateForKey

func (r *Repo) CreateForKey(ctx context.Context, f *metadata.File, key string) error

CreateForKey inserts the file row and marks the idempotency key completed in a single transaction. Atomicity matters: if the row committed but the key were left pending (two separate writes, crash in between), a retry after the key's TTL would create a duplicate file. One transaction closes that window.

func (*Repo) Delete

func (r *Repo) Delete(ctx context.Context, id string) error

Delete soft-deletes the record by ID, stamping deleted_at. The object is reclaimed later by GC. Returns metadata.ErrNotFound if no live row matched.

func (*Repo) Get

func (r *Repo) Get(ctx context.Context, id string) (*metadata.File, error)

Get returns the live (non-deleted) record by ID, or metadata.ErrNotFound.

func (*Repo) List

func (r *Repo) List(ctx context.Context, filter metadata.ListFilter) ([]*metadata.File, error)

List returns live records matching the filter, newest first, filtered by content type and/or JSONB tag containment, with keyset pagination. Ordering is by id descending — ids are UUIDv7, so id order is creation order and the primary-key index serves both the sort and the cursor bound.

func (*Repo) ListDeleted

func (r *Repo) ListDeleted(ctx context.Context, limit int) ([]*metadata.File, error)

ListDeleted returns up to limit soft-deleted records, oldest deletion first, so GC purges the longest-pending objects first.

func (*Repo) Purge

func (r *Repo) Purge(ctx context.Context, id string) error

Purge hard-deletes a soft-deleted record. The deleted_at guard prevents ever removing a live row through this path.

func (*Repo) PurgeIdempotencyKeys

func (r *Repo) PurgeIdempotencyKeys(ctx context.Context, before time.Time) (int, error)

PurgeIdempotencyKeys deletes keys older than the cutoff, returning the count.

func (*Repo) ReleaseIdempotencyKey

func (r *Repo) ReleaseIdempotencyKey(ctx context.Context, key string) error

ReleaseIdempotencyKey removes a still-pending claim (after a failed upload).

func (*Repo) StorageKeys

func (r *Repo) StorageKeys(ctx context.Context) (map[string]struct{}, error)

StorageKeys returns every storage key in the table (live or soft-deleted) as a set, so GC can identify stored objects with no backing row.

func (*Repo) UpdateMetadata

func (r *Repo) UpdateMetadata(ctx context.Context, id string, tags map[string]any, merge bool) (*metadata.File, error)

UpdateMetadata writes tags into the record's JSONB column: merged (||) when merge is true, replaced (=) otherwise.

Jump to

Keyboard shortcuts

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