Documentation
¶
Overview ¶
Package postgres provides PostgreSQL storage for prompts.
Index ¶
- type Store
- func (s *Store) ApproveVersion(ctx context.Context, promptID string, version int, approver string) (*prompt.Prompt, error)
- func (s *Store) Attach(ctx context.Context, a prompt.Attachment) error
- func (s *Store) Count(ctx context.Context, filter prompt.ListFilter) (int, error)
- func (s *Store) Create(ctx context.Context, p *prompt.Prompt) error
- func (s *Store) CreateCollection(ctx context.Context, c *prompt.Collection) error
- func (s *Store) CreateDraftVersion(ctx context.Context, promptID string, proposed *prompt.Prompt, author string) (int, error)
- func (s *Store) Delete(ctx context.Context, name string) error
- func (s *Store) DeleteByID(ctx context.Context, id string) error
- func (s *Store) DeleteCollection(ctx context.Context, id string) error
- func (s *Store) Detach(ctx context.Context, promptID, resourceID string) error
- func (s *Store) Get(ctx context.Context, name string) (*prompt.Prompt, error)
- func (s *Store) GetByID(ctx context.Context, id string) (*prompt.Prompt, error)
- func (s *Store) GetCollection(ctx context.Context, id string) (*prompt.Collection, error)
- func (s *Store) GetPersonal(ctx context.Context, ownerEmail, name string) (*prompt.Prompt, error)
- func (s *Store) GetVersion(ctx context.Context, promptID string, version int) (*prompt.Version, error)
- func (s *Store) List(ctx context.Context, filter prompt.ListFilter) ([]prompt.Prompt, error)
- func (s *Store) ListByPrompt(ctx context.Context, promptID string) ([]prompt.Attachment, error)
- func (s *Store) ListByResource(ctx context.Context, resourceID string) ([]string, error)
- func (s *Store) ListCollections(ctx context.Context) ([]prompt.Collection, error)
- func (s *Store) ListVersions(ctx context.Context, promptID string) ([]prompt.Version, error)
- func (s *Store) RejectVersion(ctx context.Context, promptID string, version int) error
- func (s *Store) Reorder(ctx context.Context, promptID string, resourceIDs []string) error
- func (s *Store) Search(ctx context.Context, q prompt.SearchQuery) ([]prompt.ScoredPrompt, error)
- func (s *Store) SetPromptCollection(ctx context.Context, promptID, collectionID string) error
- func (s *Store) Update(ctx context.Context, p *prompt.Prompt) error
- func (s *Store) UpdateCollection(ctx context.Context, id, name, description string) error
- func (s *Store) UpdateWithVersion(ctx context.Context, p *prompt.Prompt, author string) error
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 (*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) Attach ¶ added in v1.111.0
Attach appends a resource to a prompt's attachment list. The position is computed inside the INSERT so two concurrent attaches cannot both read the same "next" value. Re-attaching an existing resource is a no-op that keeps the original position: a double-submit must never silently reorder an author's materials.
func (*Store) Create ¶
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
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) DeleteByID ¶
DeleteByID removes a prompt by ID.
func (*Store) DeleteCollection ¶ added in v1.109.0
DeleteCollection removes a collection. The collection_id FK is ON DELETE SET NULL, so member prompts are released to the uncollected group.
func (*Store) Detach ¶ added in v1.111.0
Detach removes one link, returning prompt.ErrAttachmentNotFound when the prompt does not attach that resource.
func (*Store) Get ¶
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) GetCollection ¶ added in v1.109.0
GetCollection retrieves a collection by ID with its prompt count. Returns nil, nil if not found.
func (*Store) GetPersonal ¶ added in v1.81.0
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) ListByPrompt ¶ added in v1.111.0
ListByPrompt returns one prompt's attachments in authored order.
func (*Store) ListByResource ¶ added in v1.111.0
ListByResource returns the ids of prompts that attach a resource.
func (*Store) ListCollections ¶ added in v1.109.0
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
ListVersions returns every version of the prompt, newest first.
func (*Store) RejectVersion ¶ added in v1.108.0
RejectVersion marks a pending draft version rejected, leaving the live prompt row untouched.
func (*Store) Reorder ¶ added in v1.111.0
Reorder rewrites one prompt's attachment order to exactly resourceIDs. It runs in a transaction that deletes the prompt's rows and reinserts them, so a caller never observes a half-ordered list, and it rejects an id that is not already attached rather than silently creating a link that skipped the scope check.
func (*Store) Search ¶ added in v1.81.0
func (s *Store) Search(ctx context.Context, q prompt.SearchQuery) ([]prompt.ScoredPrompt, error)
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
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 ¶
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
UpdateCollection renames or re-describes a collection.
func (*Store) UpdateWithVersion ¶ added in v1.108.0
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).