store

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package store persists SpecScore Studio facts in a single-file SQLite database (pure-Go driver, house precedent) and answers the filter queries behind `specscore studio facts`.

Feature: cli/studio/index (REQ: rebuild-only, REQ: fact-shape, REQ: facts-query)

The store is a disposable cache: Rebuild replaces the whole file via an atomic temp-file swap, so a failed rebuild leaves the previous store intact and facts from previous runs never survive unless re-derived.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Query

func Query(path string, f Filter) ([]fact.Fact, error)

Query returns the facts at path matching the filter, in deterministic (subject, predicate, object) order. A missing, unreadable, or empty store returns an exit-2 error naming the store path and suggesting `specscore studio index`.

func Rebuild

func Rebuild(path string, facts []fact.Fact) error

Rebuild replaces the fact store at path with one containing exactly the given facts. The new store is written to a temp file in the same directory and swapped in atomically on success; on any failure the previous store is left intact and the temp file is removed.

Types

type Filter

type Filter struct {
	Subject   string
	Predicate string
	Object    string
	Class     string
	Adapter   string
	// StaleBefore, when non-zero, selects only facts whose verified_at is
	// strictly older than this cutoff (the `studio facts --stale <duration>`
	// filter; REQ: stale-filter). The zero time disables the cutoff.
	StaleBefore time.Time
}

Filter selects facts by exact field match; empty fields match everything. Subject and Object also accept a trailing `*` for prefix matching.

type MergeResult

type MergeResult struct {
	// Written counts the incoming facts inserted as fresh observations (a new
	// object, or a key not previously in the store).
	Written int
	// Refreshed counts the existing facts whose verified_at was advanced
	// because an incoming fact re-verified the same observation.
	Refreshed int
}

MergeResult reports what a Merge did: how many facts it wrote (inserted as new observations) and how many existing facts it refreshed (verified_at advanced, observed_at preserved).

func Merge

func Merge(path string, facts []fact.Fact) (MergeResult, error)

Merge folds the given facts into the existing store at path without rebuilding it: every fact already in the store survives (index facts, prior probe facts), and each incoming fact either refreshes a key-matching existing fact's verified_at (preserving its original observed_at) or is inserted as a fresh observation (REQ: probe-merge, REQ: verified-at-field). The rewrite is atomic — the merged store is written to a temp file in the same directory and swapped in on success, mirroring Rebuild, so a failed merge leaves the prior store intact.

Jump to

Keyboard shortcuts

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