store

package
v0.3.7 Latest Latest
Warning

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

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

Documentation

Overview

Package store provides SQLite-backed persistence.

Index

Constants

View Source
const (
	OriginParsed = "parsed"
	OriginManual = "manual"

	DirectionOut  = "out"
	DirectionIn   = "in"
	DirectionBoth = "both"
)

Variables

This section is empty.

Functions

func EmbeddedMigrationVersions added in v0.3.2

func EmbeddedMigrationVersions() ([]string, error)

Types

type DeleteMode added in v0.3.1

type DeleteMode int
const (
	DeleteStrict DeleteMode = iota
	DeleteCascade
	DeleteReparent
)

func ParseDeleteMode added in v0.3.1

func ParseDeleteMode(s string) (DeleteMode, error)

func (DeleteMode) String added in v0.3.1

func (m DeleteMode) String() string

type DiffRecord

type DiffRecord struct {
	SnapshotID int64
	NodeID     string
	Op         string
	OldHash    string
	NewHash    string
	OldContent string
	NewContent string

	OldParentID   sql.NullString
	OldSourceFile sql.NullString
	OldNodeType   sql.NullString
	OldDepth      sql.NullInt64
	OldLabel      sql.NullString
	OldFormat     sql.NullString
	OldTokenCount sql.NullInt64
}

func (*DiffRecord) HasOldMetadata added in v0.3.1

func (d *DiffRecord) HasOldMetadata() bool

True iff the diff carries pre-state metadata.

func (*DiffRecord) SetOldMetadata added in v0.3.1

func (d *DiffRecord) SetOldMetadata(n *Node)

Populate the diff's old_* metadata fields from a node's pre-state.

type FileSummary added in v0.1.6

type FileSummary struct {
	Path        string
	NodeCount   int
	TokenCount  int
	CompileRoot string
}

type Node

type Node struct {
	ID           string
	ParentID     string
	SourceFile   string
	NodeType     string
	Depth        int
	Label        string
	Content      string
	Format       string
	TokenCount   int
	ContentHash  string
	Temperature  float64
	AccessCount  int
	LastAccessed sql.NullInt64
	CreatedAt    int64
	UpdatedAt    int64
	Pinned       bool
	SeedPinned   bool
	SeedTemp     *float64
}

func BuildTree

func BuildTree(nodes []*Node) (roots []*Node, children map[string][]*Node)

type PendingRelation added in v0.3.0

type PendingRelation struct {
	ID           int64
	SourceNodeID string
	TargetLabel  string
	TargetSource string
	TargetIDHint string
	Weight       float64
	Origin       string
	CreatedAt    int64
}

type RankedNode

type RankedNode struct {
	Node *Node
	Rank float64
}

type RelatedNode added in v0.3.0

type RelatedNode struct {
	Node   *Node
	Weight float64
	Hop    int
}

type RelatedOption added in v0.3.6

type RelatedOption func(*relatedOptions)

func WithDirection added in v0.3.6

func WithDirection(d string) RelatedOption

func WithLimit added in v0.3.6

func WithLimit(l int) RelatedOption

func WithMaxDepth added in v0.3.6

func WithMaxDepth(d int) RelatedOption

func WithWeightMin added in v0.3.6

func WithWeightMin(w float64) RelatedOption

type Relation added in v0.3.0

type Relation struct {
	ID           int64
	SourceNodeID string
	TargetNodeID string
	Weight       float64
	Origin       string
	CreatedAt    int64
}

type RestoreResult added in v0.3.1

type RestoreResult struct {
	Nodes   map[string]*Node
	Skipped []SkippedRestore
}

type RowScanner

type RowScanner interface {
	Scan(...any) error
}

type SkippedRestore added in v0.3.1

type SkippedRestore struct {
	NodeID string
	Reason string
}

type Snapshot

type Snapshot struct {
	ID          int64
	CursorHash  string
	ParentID    sql.NullInt64
	Message     string
	CompileRoot string
	CreatedAt   int64
}

type SnapshotOption added in v0.3.6

type SnapshotOption func(*snapshotOptions)

func WithCompileRoot added in v0.3.6

func WithCompileRoot(r string) SnapshotOption

func WithCursorHash added in v0.3.6

func WithCursorHash(h string) SnapshotOption

func WithMessage added in v0.3.6

func WithMessage(m string) SnapshotOption

func WithParent added in v0.3.6

func WithParent(id int64) SnapshotOption

WithParent sets an explicit parent (id == 0 records NULL).

type Stats

type Stats struct {
	NodeCount            int
	SnapshotCount        int
	AvgTemp              float64
	MedianTemp           float64
	HotCount             int
	ColdCount            int
	PinnedCount          int
	TokenCountTotal      int64
	FTSRowCount          int
	PendingRelationCount int
}

type Store

type Store struct {
	Path string

	OpMu sync.Mutex
	// contains filtered or unexported fields
}

func Open

func Open(path string) (*Store, error)

func (*Store) AdvanceCursorTx

func (s *Store) AdvanceCursorTx(ctx context.Context, tx *sql.Tx, snapshotID int64) error

func (*Store) AppliedMigrationVersions added in v0.3.2

func (s *Store) AppliedMigrationVersions(ctx context.Context) ([]string, error)

func (*Store) BackupTo added in v0.3.2

func (s *Store) BackupTo(ctx context.Context, dst string) error

func (*Store) BoostTemperature

func (s *Store) BoostTemperature(ctx context.Context, id string, boost float64) error

func (*Store) BoostTemperatureBatch

func (s *Store) BoostTemperatureBatch(ctx context.Context, ids []string, boost float64) error

func (*Store) CheckFTSIntegrity added in v0.3.2

func (s *Store) CheckFTSIntegrity(ctx context.Context) error

func (*Store) Close

func (s *Store) Close() error

func (*Store) CountDanglingDiffs added in v0.3.2

func (s *Store) CountDanglingDiffs(ctx context.Context) (int, error)

func (*Store) CountNodes added in v0.3.2

func (s *Store) CountNodes(ctx context.Context) (int, error)

func (*Store) CountOrphanParents added in v0.3.2

func (s *Store) CountOrphanParents(ctx context.Context) (int, error)

func (*Store) CountSnapshots added in v0.3.2

func (s *Store) CountSnapshots(ctx context.Context) (int, error)

func (*Store) CreateSnapshotTx

func (s *Store) CreateSnapshotTx(ctx context.Context, tx *sql.Tx, opts ...SnapshotOption) (int64, error)

func (*Store) DecayTemperatures

func (s *Store) DecayTemperatures(ctx context.Context, factor float64) (int64, error)

func (*Store) DeleteDanglingDiffs added in v0.3.2

func (s *Store) DeleteDanglingDiffs(ctx context.Context) error

func (*Store) DeleteNode

func (s *Store) DeleteNode(ctx context.Context, id string, mode DeleteMode) ([]string, error)

Remove a node according to the mode; returns the IDs affected.

func (*Store) DeleteNodeTx

func (s *Store) DeleteNodeTx(ctx context.Context, tx *sql.Tx, id string) error

func (*Store) DeleteNodesByFiles

func (s *Store) DeleteNodesByFiles(ctx context.Context, paths []string) error

func (*Store) DeleteParsedPendingForSource added in v0.3.0

func (s *Store) DeleteParsedPendingForSource(ctx context.Context, sourceID string) error

func (*Store) DeleteParsedPendingForSourceTx added in v0.3.0

func (s *Store) DeleteParsedPendingForSourceTx(ctx context.Context, tx *sql.Tx, sourceID string) error

func (*Store) DeletePendingByID added in v0.3.0

func (s *Store) DeletePendingByID(ctx context.Context, id int64) error

func (*Store) DeletePendingByIDTx added in v0.3.0

func (s *Store) DeletePendingByIDTx(ctx context.Context, tx *sql.Tx, id int64) error

func (*Store) DistinctCompileRoots added in v0.3.2

func (s *Store) DistinctCompileRoots(ctx context.Context) ([]string, error)

func (*Store) FindHeadingByLabel added in v0.3.0

func (s *Store) FindHeadingByLabel(ctx context.Context, label string) (string, error)

Look up a heading node ID by case-insensitive trimmed label match across all files.

func (*Store) FindHeadingByLabelInFile added in v0.3.0

func (s *Store) FindHeadingByLabelInFile(ctx context.Context, sourceFile, label string) (string, error)

Look up a heading node ID by label scoped to a source file.

func (*Store) GetAllNodes

func (s *Store) GetAllNodes(ctx context.Context) ([]*Node, error)

func (*Store) GetAllPendingRelations added in v0.3.0

func (s *Store) GetAllPendingRelations(ctx context.Context) ([]*PendingRelation, error)

func (*Store) GetAllRelations added in v0.3.4

func (s *Store) GetAllRelations(ctx context.Context) ([]*Relation, error)

func (*Store) GetAncestors

func (s *Store) GetAncestors(ctx context.Context, id string) ([]*Node, error)

func (*Store) GetChildren

func (s *Store) GetChildren(ctx context.Context, parentID string) ([]*Node, error)

func (*Store) GetColdNodes

func (s *Store) GetColdNodes(ctx context.Context, threshold float64, limit int) ([]*Node, error)

func (*Store) GetDescendants

func (s *Store) GetDescendants(ctx context.Context, id string, maxDepth int) ([]*Node, error)

func (*Store) GetDiffsBetween added in v0.3.1

func (s *Store) GetDiffsBetween(ctx context.Context, fromSnapshotID, toSnapshotID int64) ([]*DiffRecord, error)

func (*Store) GetDiffsBySnapshot

func (s *Store) GetDiffsBySnapshot(ctx context.Context, snapshotID int64) ([]*DiffRecord, error)

func (*Store) GetDiffsForNode

func (s *Store) GetDiffsForNode(ctx context.Context, nodeID string) ([]*DiffRecord, error)

func (*Store) GetDiffsSince

func (s *Store) GetDiffsSince(ctx context.Context, sinceSnapshotID int64) ([]*DiffRecord, error)

func (*Store) GetHeadCursorHash

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

func (*Store) GetHeadSnapshotID added in v0.3.1

func (s *Store) GetHeadSnapshotID(ctx context.Context) (int64, error)

Return the snapshot id at HEAD, or 0 if no snapshot has been recorded yet.

func (*Store) GetLatestCompileRoot

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

Return the compile root of the most recent snapshot created via a directory compile.

func (*Store) GetNode

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

func (*Store) GetNodeCountsByType added in v0.3.0

func (s *Store) GetNodeCountsByType(ctx context.Context) (map[string]int, error)

Return node counts grouped by node_type (e.g. heading, list, kv, table).

func (*Store) GetNodeTx added in v0.3.1

func (s *Store) GetNodeTx(ctx context.Context, tx *sql.Tx, id string) (*Node, error)

func (*Store) GetNodesByCompileRoot added in v0.1.7

func (s *Store) GetNodesByCompileRoot(ctx context.Context, root string) ([]*Node, error)

func (*Store) GetNodesByFile

func (s *Store) GetNodesByFile(ctx context.Context, path string) ([]*Node, error)

func (*Store) GetNodesByFiles

func (s *Store) GetNodesByFiles(ctx context.Context, paths []string) ([]*Node, error)

func (*Store) GetNodesByIDs added in v0.3.0

func (s *Store) GetNodesByIDs(ctx context.Context, ids []string) ([]*Node, error)

func (*Store) GetPendingBySource added in v0.3.0

func (s *Store) GetPendingBySource(ctx context.Context, sourceID string) ([]*PendingRelation, error)

func (*Store) GetRelatedNodes added in v0.3.0

func (s *Store) GetRelatedNodes(ctx context.Context, anchorID string, opts ...RelatedOption) ([]*RelatedNode, error)

Return nodes reachable from anchor via relations edges, up to maxDepth hops, filtered by weightMin.

func (*Store) GetRelationCountsByOrigin added in v0.3.0

func (s *Store) GetRelationCountsByOrigin(ctx context.Context) (map[string]int, error)

Return relation counts grouped by origin (parsed, manual).

func (*Store) GetRootNodes

func (s *Store) GetRootNodes(ctx context.Context) ([]*Node, error)

func (*Store) GetSiblings

func (s *Store) GetSiblings(ctx context.Context, id string) ([]*Node, error)

func (*Store) GetSnapshot

func (s *Store) GetSnapshot(ctx context.Context, id int) (*Snapshot, error)

func (*Store) GetStats

func (s *Store) GetStats(ctx context.Context, hotThreshold, coldThreshold float64) (*Stats, error)

func (*Store) HeadCursorRef added in v0.3.2

func (s *Store) HeadCursorRef(ctx context.Context) (snapshotID int64, exists bool, err error)

func (*Store) IncrementAccess

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

func (*Store) InsertDiffTx

func (s *Store) InsertDiffTx(ctx context.Context, tx *sql.Tx, d *DiffRecord) error

func (*Store) InsertPendingRelation added in v0.3.0

func (s *Store) InsertPendingRelation(ctx context.Context, p *PendingRelation) error

func (*Store) InsertPendingRelationTx added in v0.3.0

func (s *Store) InsertPendingRelationTx(ctx context.Context, tx *sql.Tx, p *PendingRelation) error

func (*Store) ListFileSummaries added in v0.1.6

func (s *Store) ListFileSummaries(ctx context.Context) ([]FileSummary, error)

func (*Store) ListSnapshots

func (s *Store) ListSnapshots(ctx context.Context, limit int) ([]*Snapshot, error)

func (*Store) MaxSnapshotID added in v0.3.2

func (s *Store) MaxSnapshotID(ctx context.Context) (id int64, hasAny bool, err error)

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context) error

Apply any embedded migration that hasn't run on the DB yet.

func (*Store) PromoteOrphansToRoots added in v0.3.2

func (s *Store) PromoteOrphansToRoots(ctx context.Context) error

func (*Store) PruneSnapshotsAfterTx added in v0.3.1

func (s *Store) PruneSnapshotsAfterTx(ctx context.Context, tx *sql.Tx, targetID, excludeID int64) (int, error)

Hard-delete snapshots (and their diffs) with id > targetID, except excludeID.

func (*Store) RebuildFTS added in v0.3.2

func (s *Store) RebuildFTS(ctx context.Context) error

func (*Store) RepointHeadCursor added in v0.3.2

func (s *Store) RepointHeadCursor(ctx context.Context) error

func (*Store) ResetPinnedByFiles added in v0.3.6

func (s *Store) ResetPinnedByFiles(ctx context.Context, paths []string) error

func (*Store) ResetPinnedByFilesTx added in v0.3.6

func (s *Store) ResetPinnedByFilesTx(ctx context.Context, tx *sql.Tx, paths []string) error

func (*Store) ResetTemperaturesByFiles added in v0.1.8

func (s *Store) ResetTemperaturesByFiles(ctx context.Context, paths []string, temp float64) error

func (*Store) ResetTemperaturesByFilesTx added in v0.3.6

func (s *Store) ResetTemperaturesByFilesTx(ctx context.Context, tx *sql.Tx, paths []string, temp float64) error

func (*Store) RestoreToSnapshot added in v0.3.1

func (s *Store) RestoreToSnapshot(ctx context.Context, targetID int64) (*RestoreResult, error)

Compute the node set at targetID by reverse-walking diffs from HEAD. Pure read.

func (*Store) Search

func (s *Store) Search(ctx context.Context, query string, limit int) ([]*Node, error)

func (*Store) SearchRanked

func (s *Store) SearchRanked(ctx context.Context, query string, limit int) ([]*RankedNode, error)

func (*Store) SetPinned added in v0.3.0

func (s *Store) SetPinned(ctx context.Context, id string, pinned bool, temp *float64) error

func (*Store) SnapshotExists added in v0.3.2

func (s *Store) SnapshotExists(ctx context.Context, id int64) (bool, error)

func (*Store) Tx

func (s *Store) Tx(ctx context.Context, fn func(tx *sql.Tx) error) error

Run fn inside a transaction; commit on nil error, roll back otherwise.

func (*Store) UpdateTemperature

func (s *Store) UpdateTemperature(ctx context.Context, id string, temp float64) error

func (*Store) UpsertNode

func (s *Store) UpsertNode(ctx context.Context, n *Node) error

func (*Store) UpsertNodeTx

func (s *Store) UpsertNodeTx(ctx context.Context, tx *sql.Tx, n *Node) error

func (*Store) UpsertRelation added in v0.3.0

func (s *Store) UpsertRelation(ctx context.Context, r *Relation) error

func (*Store) UpsertRelationTx added in v0.3.0

func (s *Store) UpsertRelationTx(ctx context.Context, tx *sql.Tx, r *Relation) error

Jump to

Keyboard shortcuts

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