Documentation
¶
Overview ¶
Package priomptdb is the durable, ACID prompt store for Priompt. Backends are per-file dialects (sqlite.go, postgres.go — see dialect.go to add one), chosen from the DSN at Open. The schema and every query are portable, written once in ?-placeholder style; a dialect supplies the driver and the placeholder rewrite.
Index ¶
- Constants
- Variables
- func CommitHash(uri, versionHash, parent, parent2, author, message string) string
- func Hash(template string, slots []string) string
- type Commit
- type Prompt
- type Ref
- type Sealer
- type Store
- func (s *Store) Branch(ctx context.Context, uri, name, from string) (string, error)
- func (s *Store) Branches(ctx context.Context, uri string) ([]Ref, error)
- func (s *Store) Close() error
- func (s *Store) Commit(ctx context.Context, uri, branch, template string, slots []string, ...) (string, error)
- func (s *Store) Commits(ctx context.Context, uri string) ([]Commit, error)
- func (s *Store) CountCommits(ctx context.Context) (int, error)
- func (s *Store) Dump(ctx context.Context) ([]Prompt, error)
- func (s *Store) DumpCommits(ctx context.Context) ([]Commit, error)
- func (s *Store) DumpRefs(ctx context.Context) ([]Ref, error)
- func (s *Store) Get(ctx context.Context, uri string) (Prompt, error)
- func (s *Store) GetCommit(ctx context.Context, hash string) (Commit, error)
- func (s *Store) List(ctx context.Context, prefix string) ([]Prompt, error)
- func (s *Store) Log(ctx context.Context, uri, branch string) ([]Commit, error)
- func (s *Store) Merge(ctx context.Context, uri, into, from, author, message string) (string, error)
- func (s *Store) Put(ctx context.Context, p Prompt) error
- func (s *Store) PutCommit(ctx context.Context, c Commit) error
- func (s *Store) PutRef(ctx context.Context, r Ref) error
- func (s *Store) Resolve(ctx context.Context, uri, ref string) (Commit, error)
- func (s *Store) SchemaVersion() int
- func (s *Store) SetBranch(ctx context.Context, uri, branch, commitHash string) (Commit, error)
Constants ¶
const DefaultBranch = "main"
DefaultBranch is the trunk a prompt's history accrues on unless told otherwise.
Variables ¶
var ErrAlreadyExists = errors.New("branch already exists")
ErrAlreadyExists means the named branch is already present on this prompt.
var ErrBranchNotFound = errors.New("branch not found")
var ErrConflict = errors.New("branch moved: concurrent update")
ErrConflict means the branch moved between reading its tip and advancing it — someone else committed first. It is retryable: re-read the tip and reapply.
var ErrNotFound = errors.New("prompt not found")
Functions ¶
func CommitHash ¶
CommitHash is the commit identity: which prompt, plus content, plus lineage, plus authorship. Two commits with the same content but different parents are distinct nodes, which is what lets history branch and reverts not collide with the original.
The uri is part of the identity, and must be. Git gets this for free because a commit names a tree and a tree encodes path -> blob: identical file content shares a *blob* (safe, and deliberate dedup) while the commit still differs by path. This store snapshots content inline with no tree layer, so leaving the uri out collapsed the two: any two prompts with the same template, author and message produced the same hash, the second INSERT hit ON CONFLICT DO NOTHING and was dropped, and the surviving row kept the *first* prompt's uri. The second prompt's branch then pointed at a commit that disowned it, which corrupted its history (across org boundaries) and made rollback impossible.
Types ¶
type Commit ¶
type Commit struct {
Hash string
URI string
Template string
Slots []string
VersionHash string
Parent string // "" for the root commit
Parent2 string // set only on merge commits
Author string
Message string
CreatedAt time.Time
}
Commit is one node in a prompt's history DAG.
type Sealer ¶
type Sealer struct {
// contains filtered or unexported fields
}
A Sealer encrypts and decrypts values with the configured key. It is exported because the database is not the only place prompt content comes to rest: the server's shared Redis cache holds the same templates, and an "encrypted at rest" guarantee that stops at one of two persistent stores is not a guarantee. One implementation of the crypto, used by both.
func NewSealer ¶
NewSealer builds a Sealer from PRIOMPT_ENCRYPTION_KEY. A nil-aead Sealer (no key configured) is valid and passes values through unchanged, so callers need no branch of their own.
func (*Sealer) OpenBytes ¶
OpenBytes reverses SealBytes. A value without the marker is returned as-is.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func Open ¶
Open connects to SQLite (a file path) or PostgreSQL (a postgres:// DSN) and applies any pending schema migrations.
func (*Store) Branch ¶
Branch creates a new branch pointing at the current tip of from. The new branch shares from's history until they diverge. Returns that tip's commit hash — the caller already needs it and Branch has already resolved it internally, so there's no reason to make them look it up again.
func (*Store) Branches ¶ added in v0.7.2
Branches returns a prompt's branch pointers, sorted by name.
func (*Store) Commit ¶
func (s *Store) Commit(ctx context.Context, uri, branch, template string, slots []string, author, message string) (string, error)
Commit appends a new version onto branch and advances the branch pointer to it. The branch is created (rooted at this commit) if it does not yet exist. Author and message are the collaboration metadata: who changed what, and why. Returns the new commit hash; committing identical content+meta onto the same tip is idempotent (same hash, pointer unchanged).
func (*Store) Commits ¶ added in v0.7.2
Commits returns every commit of a prompt, newest first — on any branch, a merged-away side branch, or none at all (a commit left behind by a rollback). Log only follows one branch's first parents, so it can't reach those.
func (*Store) CountCommits ¶
CountCommits reports how many commits the store holds. Restore uses it to refuse to write over a database that already has history.
func (*Store) DumpCommits ¶
DumpCommits returns every commit in the store, oldest first so that a restore can insert them in an order where each commit's parents already exist.
func (*Store) List ¶
List returns the served-HEAD prompts whose URI starts with prefix, sorted by URI — the repo/tree browse. An empty prefix lists the whole store. Only uri and version_hash are populated (a listing, not a fetch).
func (*Store) Log ¶
Log walks the first-parent chain from a branch tip back to the root — the mainline history, newest first. (Like `git log --first-parent`; second parents are reachable via GetCommit when you need the full DAG.) Done as one recursive query rather than one round-trip per commit: a branch's history only grows, and an N-round-trip walk gets slower every time something is published to it.
func (*Store) Merge ¶
Merge records a merge commit on into, with into's tip as first parent and from's tip as second parent, and advances into. Returns the merge commit hash.
ponytail: resolution is "take theirs" — the merge content is from's tip verbatim. That records the graph correctly and lets a semantic diff against the first parent show exactly what the merge pulled in. Add 3-way content auto-merge when divergent edits to the *same* prompt actually need reconciling.
func (*Store) PutCommit ¶
PutCommit inserts a commit verbatim, preserving its hash, parents, author, message and timestamp. Restoring must not recompute the hash: the hash is the commit's identity, every child names it as a parent, and recomputing would break the chain. Re-inserting an existing commit is a no-op.
func (*Store) PutRef ¶
PutRef points a branch at a commit, creating or moving it. Unlike SetBranch this does not re-materialize the served HEAD or check that the commit belongs to the prompt — a restore replays recorded state rather than performing a rollback, and the prompts table is restored from its own records.
func (*Store) Resolve ¶
Resolve maps a ref to its commit. A ref is a branch name (resolved to its tip) or a commit hash. Returns ErrNotFound if it is neither, or names a commit that belongs to a different prompt.
func (*Store) SchemaVersion ¶
SchemaVersion is the number of migrations applied to this database.