store

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package store manages the DevSpecs SQLite database: opening, migrations, and queries.

Index

Constants

View Source
const SchemaVersion = 7

SchemaVersion is the current schema version. Bump when schema.sql changes.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArtifactRow

type ArtifactRow struct {
	ID             string
	RepoID         string
	ShortID        string
	Kind           string
	Subtype        string
	Title          string
	Status         string
	CurrentRevID   string
	CreatedAt      string
	UpdatedAt      string
	LastObservedAt string
}

ArtifactRow represents a row from the artifacts table.

type CriterionRow

type CriterionRow struct {
	ID           string
	ArtifactID   string
	RevisionID   string
	Ordinal      int
	Text         string
	Done         bool
	SourceFile   string
	SourceLine   int
	CriteriaKind string
}

CriterionRow represents a row from the artifact_criteria table.

type DB

type DB struct {
	*sql.DB
}

DB wraps *sql.DB with DevSpecs-specific operations.

func Open

func Open(dbPath string) (*DB, error)

Open opens or creates the SQLite database at the given path. It ensures the parent directory exists and applies migrations.

func (*DB) AssignArtifactShortID

func (db *DB) AssignArtifactShortID(artifactID, baseShort string) error

AssignArtifactShortID sets short_id to baseShort, or baseShort with a numeric suffix, until UNIQUE succeeds.

func (*DB) DeleteAutoTags

func (db *DB) DeleteAutoTags(artifactID string) error

DeleteAutoTags removes all frontmatter and inferred tags for an artifact (preserving manual).

func (*DB) DeleteTag

func (db *DB) DeleteTag(artifactID, tag string) error

DeleteTag removes a specific tag from an artifact.

func (*DB) EnsureRepo

func (db *DB) EnsureRepo(rootPath, now string) (string, error)

EnsureRepo creates or returns the repo ID for the given root path.

func (*DB) FindArtifacts

func (db *DB) FindArtifacts(query string, fp FilterParams) ([]ArtifactRow, error)

FindArtifacts does a text search across title, source path, and body. It tries FTS5 first, falling back to LIKE if FTS returns no results or errors.

func (*DB) FindSourceByIdentity

func (db *DB) FindSourceByIdentity(identity string) (string, error)

FindSourceByIdentity checks if a source_identity already exists and returns the artifact ID.

func (*DB) GetArtifact

func (db *DB) GetArtifact(idOrPrefix string) (*ArtifactRow, error)

GetArtifact retrieves a single artifact by full ID, short_id, or prefix.

func (*DB) GetCriteriaForArtifact

func (db *DB) GetCriteriaForArtifact(artifactID string) ([]CriterionRow, error)

GetCriteriaForArtifact returns extracted criteria for a specific artifact.

func (*DB) GetLinksForArtifact

func (db *DB) GetLinksForArtifact(artifactID string) ([]LinkRow, error)

GetLinksForArtifact returns all links for an artifact.

func (*DB) GetRepoByRoot

func (db *DB) GetRepoByRoot(rootPath string) *RepoMeta

GetRepoByRoot returns the repo row for a given root path, or nil if not found.

func (*DB) GetRevision

func (db *DB) GetRevision(id string) (*RevisionRow, error)

GetRevision retrieves a revision by ID.

func (*DB) GetSourcesForArtifact

func (db *DB) GetSourcesForArtifact(artifactID string) ([]SourceRow, error)

GetSourcesForArtifact returns all sources for an artifact.

func (*DB) GetTagsForArtifact

func (db *DB) GetTagsForArtifact(artifactID string) ([]TagRow, error)

GetTagsForArtifact returns all tags for an artifact.

func (*DB) GetTodosForArtifact

func (db *DB) GetTodosForArtifact(artifactID string) ([]TodoRow, error)

GetTodosForArtifact returns todos for a specific artifact.

func (*DB) IndexArtifactFTS

func (db *DB) IndexArtifactFTS(artifactID, title, body, sourcePath string) error

IndexArtifactFTS inserts or updates the FTS5 index for an artifact.

func (*DB) InsertArtifactDirect

func (db *DB) InsertArtifactDirect(id, repoID, kind, subtype, title, status, revID, authoredAt, now string) error

InsertArtifactDirect allows inserting an artifact directly (for capture).

func (db *DB) InsertLink(id, artifactID, linkType, target, now string) error

InsertLink adds a link for an artifact.

func (*DB) InsertRevisionDirect

func (db *DB) InsertRevisionDirect(id, artifactID, contentHash, body, extractedJSON, now string) error

InsertRevisionDirect inserts a revision directly. extractedJSON may be empty for NULL.

func (*DB) InsertSourceDirect

func (db *DB) InsertSourceDirect(id, artifactID, repoID, sourceType, path, sourceIdentity, formatProfile, layoutGroup, now string) error

InsertSourceDirect inserts a source directly.

func (*DB) InsertTag

func (db *DB) InsertTag(artifactID, tag, source, now string) error

InsertTag adds a tag for an artifact. It is a no-op on conflict.

func (*DB) ListAllCriteria

func (db *DB) ListAllCriteria(fp FilterParams, openOnly, doneOnly bool, criteriaKind string) ([]CriterionRow, error)

ListAllCriteria returns criteria across all artifacts, optionally filtered. criteriaKind filters by criteria_kind when non-empty (acceptance, success, okr).

func (*DB) ListAllTodos

func (db *DB) ListAllTodos(fp FilterParams, openOnly, doneOnly bool) ([]TodoRow, error)

ListAllTodos returns todos across all artifacts, optionally filtered.

func (*DB) ListArtifacts

func (db *DB) ListArtifacts(fp FilterParams) ([]ArtifactRow, error)

ListArtifacts returns artifacts filtered by the given parameters.

func (*DB) ResumeArtifacts

func (db *DB) ResumeArtifacts(repoRoot string, fp FilterParams) ([]ResumeRow, error)

ResumeArtifacts returns all artifacts for a repo, with todo counts, sorted by updated_at DESC.

func (*DB) UpdateArtifactShortID

func (db *DB) UpdateArtifactShortID(artifactID, shortID string) error

UpdateArtifactShortID sets the short_id for an artifact.

func (*DB) UpdateArtifactStatus

func (db *DB) UpdateArtifactStatus(artifactID, status, now string) error

UpdateArtifactStatus updates the status of an artifact.

func (*DB) UpdateScanMeta

func (db *DB) UpdateScanMeta(repoID, commit, scannedBy, now string)

UpdateScanMeta records the git commit, timestamp, and user of the last scan.

type FilterParams

type FilterParams struct {
	RepoRoot   string
	Kind       string
	Subtype    string
	Status     string
	SourceType string
	Tag        string
	Branch     string
	User       string
}

FilterParams groups all query filters.

type LinkRow

type LinkRow struct {
	ID         string
	ArtifactID string
	LinkType   string
	Target     string
	CreatedAt  string
}

LinkRow represents a row from the links table.

type RepoMeta

type RepoMeta struct {
	ID             string
	RootPath       string
	LastScanCommit string
	LastScanAt     string
	ScannedBy      string
}

RepoMeta holds freshness metadata for a repository.

type ResumeRow

type ResumeRow struct {
	ID             string
	ShortID        string
	Kind           string
	Subtype        string
	Title          string
	Status         string
	AuthoredAt     string
	UpdatedAt      string
	LastObservedAt string
	SourcePath     string
	TotalTodos     int
	OpenTodos      int
	TagsJoined     string // comma-separated from SQL GROUP_CONCAT
}

ResumeRow holds the data needed for ds resume display.

type RevisionRow

type RevisionRow struct {
	ID            string
	ArtifactID    string
	ContentHash   string
	Body          string
	ExtractedJSON string
	ObservedAt    string
}

RevisionRow represents a row from the artifact_revisions table.

type SourceRow

type SourceRow struct {
	ID             string
	ArtifactID     string
	SourceType     string
	Path           string
	SourceIdentity string
	FormatProfile  string
	LayoutGroup    string
}

SourceRow represents a row from the sources table.

type TagRow

type TagRow struct {
	ArtifactID string
	Tag        string
	Source     string
	CreatedAt  string
}

TagRow represents a row from the artifact_tags table.

type TodoRow

type TodoRow struct {
	ID         string
	ArtifactID string
	RevisionID string
	Ordinal    int
	Text       string
	Done       bool
	SourceFile string
	SourceLine int
}

TodoRow represents a row from the artifact_todos table.

Jump to

Keyboard shortcuts

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