Documentation
¶
Overview ¶
Package store owns the SQLite database that holds an opentuple index.
Index ¶
- Variables
- func IndexDirFor(repoPath string) (string, error)
- func ReadRepoPath(dir string) (string, error)
- type CallGraphRow
- type FuncIORow
- type FunctionFingerprintRow
- type FunctionLocation
- type MinerFunctionRow
- type Pattern
- type PatternEntry
- type ScopeRule
- type Store
- func (s *Store) AllFiles(ctx context.Context) ([]types.FileRecord, error)
- func (s *Store) AllPatterns(ctx context.Context) ([]Pattern, error)
- func (s *Store) AnyDoesIO(ctx context.Context, names []string) (bool, error)
- func (s *Store) CallGraph(ctx context.Context) ([]CallGraphRow, error)
- func (s *Store) ClearPatterns(ctx context.Context) error
- func (s *Store) ClearSubsystems(ctx context.Context) error
- func (s *Store) ClearVocabulary(ctx context.Context) error
- func (s *Store) Close() error
- func (s *Store) CountFunctions(ctx context.Context) (int, error)
- func (s *Store) CountPatterns(ctx context.Context) (int, error)
- func (s *Store) CountSubsystems(ctx context.Context) (int, error)
- func (s *Store) CountVocabulary(ctx context.Context) (int, error)
- func (s *Store) DBPath() string
- func (s *Store) DominantLanguage(ctx context.Context, dirPrefix string) (string, error)
- func (s *Store) FileIndexed(ctx context.Context, path string) (bool, error)
- func (s *Store) FunctionCallees(ctx context.Context, id int64) ([]CallGraphRow, error)
- func (s *Store) FunctionCode(ctx context.Context, id int64) (string, error)
- func (s *Store) FunctionFingerprints(ctx context.Context) ([]FunctionFingerprintRow, error)
- func (s *Store) FunctionLocations(ctx context.Context, ids []int64) ([]FunctionLocation, error)
- func (s *Store) FunctionsWithIO(ctx context.Context) ([]FuncIORow, error)
- func (s *Store) MinerFunctions(ctx context.Context) ([]MinerFunctionRow, error)
- func (s *Store) PopulateFunctionVocabulary(ctx context.Context) error
- func (s *Store) RepoPath(ctx context.Context) (string, error)
- func (s *Store) ResetIndexData(ctx context.Context) error
- func (s *Store) RulesForCheck(ctx context.Context, scope string) ([]ScopeRule, error)
- func (s *Store) SchemaVersion(ctx context.Context) (int, error)
- func (s *Store) SetDoesIO(ctx context.Context, functionIDs []int64, value bool) error
- func (s *Store) ShapeMatches(ctx context.Context, hash, lang, excludeFile, excludeName string) ([]FunctionLocation, error)
- func (s *Store) SubsystemFunctionCounts(ctx context.Context) (map[string]int, error)
- func (s *Store) UpdateVocabularyUsage(ctx context.Context) error
- func (s *Store) WriteFiles(ctx context.Context, records []types.FileRecord) error
- func (s *Store) WriteFunctions(ctx context.Context, records []types.FunctionRecord) error
- func (s *Store) WritePatterns(ctx context.Context, entries []PatternEntry) error
- func (s *Store) WriteSubsystems(ctx context.Context, entries []SubsystemEntry) error
- func (s *Store) WriteVocabulary(ctx context.Context, entries []types.VocabEntry) error
- type SubsystemEntry
Constants ¶
This section is empty.
Variables ¶
var ErrNoIndex = errors.New("repository not indexed")
ErrNoIndex reports that no index database exists for a repository.
Functions ¶
func IndexDirFor ¶
IndexDirFor returns the index directory Open would use for repoPath, without creating it.
func ReadRepoPath ¶
ReadRepoPath opens the index database inside dir read-only and returns the stored repo_path, without creating or migrating anything.
Types ¶
type CallGraphRow ¶
CallGraphRow is a single edge in the call graph.
type FunctionFingerprintRow ¶
FunctionFingerprintRow is a joined row from functions + function_fingerprints.
type FunctionLocation ¶
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 ¶
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 ¶
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) AllPatterns ¶
AllPatterns returns every mined pattern row, ordered deterministically by scope, claim type, then claim JSON so downstream selection is stable.
func (*Store) AnyDoesIO ¶
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 ¶
ClearPatterns removes all rows from the patterns table.
func (*Store) ClearSubsystems ¶
ClearSubsystems removes all rows from the subsystems table.
func (*Store) ClearVocabulary ¶
ClearVocabulary removes all rows from the vocabulary table.
func (*Store) CountFunctions ¶
CountFunctions returns the total number of indexed functions.
func (*Store) CountPatterns ¶
CountPatterns returns the total number of mined patterns.
func (*Store) CountSubsystems ¶
CountSubsystems returns the total number of rows in the subsystems table.
func (*Store) CountVocabulary ¶
CountVocabulary returns the total number of rows in the vocabulary table.
func (*Store) DominantLanguage ¶
DominantLanguage returns the most common language for functions under the given directory, falling back to the globally dominant language.
func (*Store) FileIndexed ¶
FileIndexed reports whether path was indexed as a source file.
func (*Store) FunctionCallees ¶
FunctionCallees returns the call-graph edges leaving one function.
func (*Store) FunctionCode ¶
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 ¶
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 ¶
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 ¶
PopulateFunctionVocabulary inserts function vocabulary derived from the functions and function_calls tables in a single SQL statement.
func (*Store) ResetIndexData ¶
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 ¶
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 ¶
SchemaVersion returns the highest applied schema version.
func (*Store) SetDoesIO ¶
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 ¶
SubsystemFunctionCounts returns path_prefix → function_count for every subsystem row.
func (*Store) UpdateVocabularyUsage ¶
UpdateVocabularyUsage sets usage_count for non-function entries based on function_calls references.
func (*Store) WriteFiles ¶
WriteFiles inserts a batch of file records in a single transaction.
func (*Store) WriteFunctions ¶
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 ¶
WriteVocabulary inserts a batch of vocabulary entries in a single transaction.
type SubsystemEntry ¶
SubsystemEntry is a single subsystem row ready for insertion.