store

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package store owns the SQLite database that holds an opentuple index.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoIndex = errors.New("repository not indexed")

ErrNoIndex reports that no index database exists for a repository.

Functions

func IndexDirFor

func IndexDirFor(repoPath string) (string, error)

IndexDirFor returns the index directory Open would use for repoPath, without creating it.

func ReadRepoPath

func ReadRepoPath(dir string) (string, error)

ReadRepoPath opens the index database inside dir read-only and returns the stored repo_path, without creating or migrating anything.

Types

type CallGraphRow

type CallGraphRow struct {
	CallerID   int64
	CalleeName string
	Qualifier  string
	Deferred   bool
}

CallGraphRow is a single edge in the call graph.

type FuncIORow

type FuncIORow struct {
	ID     int64
	Name   string
	DoesIO bool
}

FuncIORow is a function with its ID, name, and current does_io status.

type FunctionFingerprintRow

type FunctionFingerprintRow struct {
	FilePath        string
	Scope           string
	FingerprintJSON string
}

FunctionFingerprintRow is a joined row from functions + function_fingerprints.

type FunctionLocation

type FunctionLocation struct {
	ID        int64
	Name      string
	FilePath  string
	StartLine int
}

FunctionLocation is where one indexed function lives.

type MinerFunctionRow

type MinerFunctionRow struct {
	ID              int64
	FilePath        string
	Name            string
	StartLine       int
	Language        string
	Scope           string
	FingerprintJSON string
}

MinerFunctionRow is a function with its ID and fingerprint for pattern mining.

type Pattern

type Pattern struct {
	Scope           string
	ClaimType       string
	ClaimJSON       string
	Confidence      float64
	SupportCount    int
	PopulationCount int
}

Pattern is a single mined pattern row read back for convention selection.

type PatternEntry

type PatternEntry struct {
	Scope               string
	ClaimType           string
	ClaimJSON           string
	Confidence          float64
	SupportCount        int
	PopulationCount     int
	EvidenceJSON        string
	CounterExamplesJSON *string
	Tier                string
}

PatternEntry is a single pattern row ready for insertion.

type ScopeRule

type ScopeRule struct {
	Scope           string
	ClaimType       string
	ClaimJSON       string
	Confidence      float64
	SupportCount    int
	PopulationCount int
	EvidenceIDs     []int64
}

ScopeRule is a pattern the check command may enforce, with its evidence function IDs decoded.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store owns the SQLite handle for a single indexed repository.

func Open

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

Open resolves repoPath, ensures the per-repo index directory exists under ~/.opentuple/repos/<basename>-<hash>/, and opens (creating if necessary) the index.db SQLite file inside it.

func OpenExisting

func OpenExisting(repoPath string) (*Store, error)

OpenExisting opens the index for repoPath only when one already exists on disk. Unlike Open it never creates directories or database files; it returns an error wrapping ErrNoIndex when the repository has not been indexed.

func (*Store) AllFiles

func (s *Store) AllFiles(ctx context.Context) ([]types.FileRecord, error)

AllFiles returns every indexed file's facts, ordered by path.

func (*Store) AllPatterns

func (s *Store) AllPatterns(ctx context.Context) ([]Pattern, error)

AllPatterns returns every mined pattern row, ordered deterministically by scope, claim type, then claim JSON so downstream selection is stable.

func (*Store) AnyDoesIO

func (s *Store) AnyDoesIO(ctx context.Context, names []string) (bool, error)

AnyDoesIO reports whether any indexed function with one of the given names performs I/O, directly or through its own callees, as recorded by the index's I/O propagation.

func (*Store) CallGraph

func (s *Store) CallGraph(ctx context.Context) ([]CallGraphRow, error)

CallGraph returns all edges from the function_calls table.

func (*Store) ClearPatterns

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

ClearPatterns removes all rows from the patterns table.

func (*Store) ClearSubsystems

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

ClearSubsystems removes all rows from the subsystems table.

func (*Store) ClearVocabulary

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

ClearVocabulary removes all rows from the vocabulary table.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database handle.

func (*Store) CountFunctions

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

CountFunctions returns the total number of indexed functions.

func (*Store) CountPatterns

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

CountPatterns returns the total number of mined patterns.

func (*Store) CountSubsystems

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

CountSubsystems returns the total number of rows in the subsystems table.

func (*Store) CountVocabulary

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

CountVocabulary returns the total number of rows in the vocabulary table.

func (*Store) DBPath

func (s *Store) DBPath() string

DBPath returns the filesystem path to the SQLite database file.

func (*Store) DominantLanguage

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

DominantLanguage returns the most common language for functions under the given directory, falling back to the globally dominant language.

func (*Store) FileIndexed

func (s *Store) FileIndexed(ctx context.Context, path string) (bool, error)

FileIndexed reports whether path was indexed as a source file.

func (*Store) FunctionCallees

func (s *Store) FunctionCallees(ctx context.Context, id int64) ([]CallGraphRow, error)

FunctionCallees returns the call-graph edges leaving one function.

func (*Store) FunctionCode

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

FunctionCode returns the stored source of one indexed function.

func (*Store) FunctionFingerprints

func (s *Store) FunctionFingerprints(ctx context.Context) ([]FunctionFingerprintRow, error)

FunctionFingerprints returns all (file_path, fingerprint_json) pairs for functions that have a fingerprint row.

func (*Store) FunctionLocations

func (s *Store) FunctionLocations(ctx context.Context, ids []int64) ([]FunctionLocation, error)

FunctionLocations returns the locations of the given function IDs ordered by file path then start line. IDs no longer in the index are skipped.

func (*Store) FunctionsWithIO

func (s *Store) FunctionsWithIO(ctx context.Context) ([]FuncIORow, error)

FunctionsWithIO returns all functions with their ID, name, and does_io flag extracted from the fingerprint JSON.

func (*Store) MinerFunctions

func (s *Store) MinerFunctions(ctx context.Context) ([]MinerFunctionRow, error)

MinerFunctions returns all functions with their IDs and fingerprints, ordered by ID so evidence selection downstream is deterministic.

func (*Store) PopulateFunctionVocabulary

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

PopulateFunctionVocabulary inserts function vocabulary derived from the functions and function_calls tables in a single SQL statement.

func (*Store) RepoPath

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

RepoPath returns the stored repo_path from the index_state table.

func (*Store) ResetIndexData

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

ResetIndexData deletes all derived index rows so a re-index starts clean. Preserves index_state (repo_path, schema metadata).

Foreign keys are disabled on the reset connection for the duration of the deletes: with them enabled, SQLite cannot use the truncate optimization and must visit every row (function_calls alone holds millions on large repos). Every table on either side of a foreign key is cleared inside the same transaction, so no dangling reference can survive the reset.

func (*Store) RulesForCheck

func (s *Store) RulesForCheck(ctx context.Context, scope string) ([]ScopeRule, error)

RulesForCheck returns the patterns the check command may enforce on a file in scope: the scope's own call-graph, family, import, documentation, receiver, test, error-handling, and defer claims, plus the repository-wide wrapper and file_header claims. Ordered by claim type then claim JSON so a check reports violations in the same order every run.

func (*Store) SchemaVersion

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

SchemaVersion returns the highest applied schema version.

func (*Store) SetDoesIO

func (s *Store) SetDoesIO(ctx context.Context, functionIDs []int64, value bool) error

SetDoesIO batch-updates the does_io field in fingerprint JSON for the given function IDs using SQLite's json_set. Processes in batches of 1000 within a single transaction.

func (*Store) ShapeMatches

func (s *Store) ShapeMatches(ctx context.Context, hash, lang, excludeFile, excludeName string) ([]FunctionLocation, error)

ShapeMatches returns the indexed functions in the same language whose named-node structure hash equals hash, excluding the one at excludeFile with excludeName (the function being checked, when it already exists), ordered by file path then start line.

func (*Store) SubsystemFunctionCounts

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

SubsystemFunctionCounts returns path_prefix → function_count for every subsystem row.

func (*Store) UpdateVocabularyUsage

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

UpdateVocabularyUsage sets usage_count for non-function entries based on function_calls references.

func (*Store) WriteFiles

func (s *Store) WriteFiles(ctx context.Context, records []types.FileRecord) error

WriteFiles inserts a batch of file records in a single transaction.

func (*Store) WriteFunctions

func (s *Store) WriteFunctions(ctx context.Context, records []types.FunctionRecord) error

WriteFunctions inserts a batch of function records, their call sites, and their fingerprints in a single transaction. Returns an error if any insert fails (the whole transaction rolls back).

func (*Store) WritePatterns

func (s *Store) WritePatterns(ctx context.Context, entries []PatternEntry) error

WritePatterns inserts pattern entries in a single transaction.

func (*Store) WriteSubsystems

func (s *Store) WriteSubsystems(ctx context.Context, entries []SubsystemEntry) error

WriteSubsystems inserts subsystem entries in a single transaction.

func (*Store) WriteVocabulary

func (s *Store) WriteVocabulary(ctx context.Context, entries []types.VocabEntry) error

WriteVocabulary inserts a batch of vocabulary entries in a single transaction.

type SubsystemEntry

type SubsystemEntry struct {
	PathPrefix      string
	FunctionCount   int
	ConventionsJSON string
}

SubsystemEntry is a single subsystem row ready for insertion.

Jump to

Keyboard shortcuts

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