Documentation
¶
Overview ¶
Package postgres is the pgx implementation of metadata.Repository. It is the only code in the system that issues SQL.
Index ¶
- type Repo
- func (r *Repo) ClaimIdempotencyKey(ctx context.Context, key string) (bool, *metadata.IdempotencyRecord, error)
- func (r *Repo) Create(ctx context.Context, f *metadata.File) error
- func (r *Repo) CreateForKey(ctx context.Context, f *metadata.File, key string) error
- func (r *Repo) Delete(ctx context.Context, id string) error
- func (r *Repo) Get(ctx context.Context, id string) (*metadata.File, error)
- func (r *Repo) List(ctx context.Context, filter metadata.ListFilter) ([]*metadata.File, error)
- func (r *Repo) ListDeleted(ctx context.Context, limit int) ([]*metadata.File, error)
- func (r *Repo) Purge(ctx context.Context, id string) error
- func (r *Repo) PurgeIdempotencyKeys(ctx context.Context, before time.Time) (int, error)
- func (r *Repo) ReleaseIdempotencyKey(ctx context.Context, key string) error
- func (r *Repo) StorageKeys(ctx context.Context) (map[string]struct{}, error)
- func (r *Repo) UpdateMetadata(ctx context.Context, id string, tags map[string]any, merge bool) (*metadata.File, error)
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 (*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) CreateForKey ¶
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 ¶
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) List ¶
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 ¶
ListDeleted returns up to limit soft-deleted records, oldest deletion first, so GC purges the longest-pending objects first.
func (*Repo) Purge ¶
Purge hard-deletes a soft-deleted record. The deleted_at guard prevents ever removing a live row through this path.
func (*Repo) PurgeIdempotencyKeys ¶
PurgeIdempotencyKeys deletes keys older than the cutoff, returning the count.
func (*Repo) ReleaseIdempotencyKey ¶
ReleaseIdempotencyKey removes a still-pending claim (after a failed upload).
func (*Repo) StorageKeys ¶
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.