postgres

package
v1.109.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package postgres provides PostgreSQL storage for prompts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store implements prompt.Store using PostgreSQL.

func New

func New(db *sql.DB) *Store

New creates a new PostgreSQL prompt store.

func (*Store) ApproveVersion added in v1.108.0

func (s *Store) ApproveVersion(ctx context.Context, promptID string, version int, approver string) (*prompt.Prompt, error)

ApproveVersion applies draft version's snapshot to the live prompt row, marks the prompt approved with approver's stamp, binds the same stamp to the version row, and supersedes any other pending drafts. Returns the updated prompt.

func (*Store) Count

func (s *Store) Count(ctx context.Context, filter prompt.ListFilter) (int, error)

Count returns the number of prompts matching the filter.

func (*Store) Create

func (s *Store) Create(ctx context.Context, p *prompt.Prompt) error

Create persists a new prompt. If p.ID is empty the database generates one. Every non-system prompt is created with version 1 and a matching applied snapshot in prompt_versions, in one transaction; system rows (read-only config mirrors re-ingested at startup) are never versioned.

func (*Store) CreateCollection added in v1.109.0

func (s *Store) CreateCollection(ctx context.Context, c *prompt.Collection) error

CreateCollection persists a new collection, generating its ID.

func (*Store) CreateDraftVersion added in v1.108.0

func (s *Store) CreateDraftVersion(ctx context.Context, promptID string, proposed *prompt.Prompt, author string) (int, error)

CreateDraftVersion snapshots proposed's versioned fields as a new draft version of the prompt without touching the live row, returning the new version number. System rows are read-only config mirrors and refuse drafts.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, name string) error

Delete removes a non-personal prompt by name.

func (*Store) DeleteByID

func (s *Store) DeleteByID(ctx context.Context, id string) error

DeleteByID removes a prompt by ID.

func (*Store) DeleteCollection added in v1.109.0

func (s *Store) DeleteCollection(ctx context.Context, id string) error

DeleteCollection removes a collection. The collection_id FK is ON DELETE SET NULL, so member prompts are released to the uncollected group.

func (*Store) Get

func (s *Store) Get(ctx context.Context, name string) (*prompt.Prompt, error)

Get retrieves a non-personal (global or persona) prompt by name. Personal prompts are per-owner; use GetPersonal. Returns nil, nil if not found.

func (*Store) GetByID

func (s *Store) GetByID(ctx context.Context, id string) (*prompt.Prompt, error)

GetByID retrieves a prompt by ID. Returns nil, nil if not found.

func (*Store) GetCollection added in v1.109.0

func (s *Store) GetCollection(ctx context.Context, id string) (*prompt.Collection, error)

GetCollection retrieves a collection by ID with its prompt count. Returns nil, nil if not found.

func (*Store) GetPersonal added in v1.81.0

func (s *Store) GetPersonal(ctx context.Context, ownerEmail, name string) (*prompt.Prompt, error)

GetPersonal retrieves a personal prompt by its owner and name. Returns nil, nil if not found.

func (*Store) GetVersion added in v1.108.0

func (s *Store) GetVersion(ctx context.Context, promptID string, version int) (*prompt.Version, error)

GetVersion returns one version with its full content, or nil, nil when the prompt has no such version.

func (*Store) List

func (s *Store) List(ctx context.Context, filter prompt.ListFilter) ([]prompt.Prompt, error)

List returns prompts matching the filter.

func (*Store) ListCollections added in v1.109.0

func (s *Store) ListCollections(ctx context.Context) ([]prompt.Collection, error)

ListCollections returns every collection with its prompt count, ordered by name (case-insensitive, matching the uniqueness rule).

func (*Store) ListVersions added in v1.108.0

func (s *Store) ListVersions(ctx context.Context, promptID string) ([]prompt.Version, error)

ListVersions returns every version of the prompt, newest first.

func (*Store) RejectVersion added in v1.108.0

func (s *Store) RejectVersion(ctx context.Context, promptID string, version int) error

RejectVersion marks a pending draft version rejected, leaving the live prompt row untouched.

func (*Store) Search added in v1.81.0

Search ranks approved prompts by relevance to the query within the caller's visibility. A non-nil q.Embedding selects hybrid (semantic + lexical) ranking; a nil embedding selects the lexical-only fallback used when no embedding provider is configured. Visibility is applied in SQL before ranking, so a prompt the caller cannot read is never returned.

func (*Store) SetPromptCollection added in v1.109.0

func (s *Store) SetPromptCollection(ctx context.Context, promptID, collectionID string) error

SetPromptCollection assigns a prompt to a collection (empty collectionID clears the assignment). Placement is not reviewable substance: no version snapshot, no review gate, and the search embedding is untouched.

func (*Store) Update

func (s *Store) Update(ctx context.Context, p *prompt.Prompt) error

Update modifies an existing prompt identified by ID. It does not create a version snapshot (use UpdateWithVersion for versioned edits), but it does bind a first approval to the current version: when the update carries the draft-to-approved transition, the approval stamp is copied onto the current prompt_versions row in the same transaction, so "approved" always names a specific snapshot regardless of which path performed the approval. Like UpdateWithVersion, it re-validates the review gate under the row lock, so a write racing an approval cannot slip unreviewed content past it.

func (*Store) UpdateCollection added in v1.109.0

func (s *Store) UpdateCollection(ctx context.Context, id, name, description string) error

UpdateCollection renames or re-describes a collection.

func (*Store) UpdateWithVersion added in v1.108.0

func (s *Store) UpdateWithVersion(ctx context.Context, p *prompt.Prompt, author string) error

UpdateWithVersion persists p like Update and, when any versioned snapshot field changed against the stored row, records a new applied version authored by author and advances p.Version to it. System rows are written without versioning (config mirrors). The review gate is re-validated under the row lock (see requireUngated).

Jump to

Keyboard shortcuts

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