Documentation
¶
Overview ¶
Package db manages the SQLite index database lifecycle.
Index ¶
- Constants
- func ClearAllDataTx(tx *sql.Tx) error
- func ClearGitDataTx(tx *sql.Tx) error
- func DeleteFileEdgesTx(tx *sql.Tx, path string) error
- func DeleteFileSignalsTx(tx *sql.Tx, path string) error
- func DeleteFileTx(tx *sql.Tx, path string) error
- func DeleteFileUnresolvedTx(tx *sql.Tx, path string) error
- func FileExistsTx(tx *sql.Tx, path string) (bool, error)
- func IndexPath(repoRoot string) string
- func InsertCoChangePairTx(tx *sql.Tx, r CoChangePairRecord) error
- func InsertEdgeTx(tx *sql.Tx, src, dst, edgeType, spec, method string, line int, ...) error
- func InsertFileTx(tx *sql.Tx, path, hash string, mtime int64, lang string, size int64) error
- func InsertGitSignalTx(tx *sql.Tx, r GitSignalRecord) error
- func InsertUnresolvedTx(tx *sql.Tx, src, spec, reason string, line int) error
- func SetMetaTx(tx *sql.Tx, key, value string) error
- func UpsertFileTx(tx *sql.Tx, path, hash string, mtime int64, lang string, size int64) error
- type CoChangePairRecord
- type CoChangePartner
- type DirLanguageCount
- type DirectedEdge
- type EntrypointFile
- type GitSignalRecord
- type Index
- func (idx *Index) Close() error
- func (idx *Index) CoChangePairCount(windowDays int) (int, error)
- func (idx *Index) EdgeCount() (int, error)
- func (idx *Index) EntrypointCount() (int, error)
- func (idx *Index) FileCount() (int, error)
- func (idx *Index) FileExists(path string) (bool, error)
- func (idx *Index) GetAllFileHashes() (map[string]string, error)
- func (idx *Index) GetChurnForFiles(paths []string, windowDays int) (map[string]float64, error)
- func (idx *Index) GetCoChangePartners(path string, windowDays int, limit int) ([]CoChangePartner, error)
- func (idx *Index) GetDirectImporters(path string) ([]string, error)
- func (idx *Index) GetDirectImports(path string) ([]string, error)
- func (idx *Index) GetDirectoryStructure() ([]DirLanguageCount, error)
- func (idx *Index) GetEdgesAmong(paths []string) ([]DirectedEdge, error)
- func (idx *Index) GetEntrypoints() ([]EntrypointFile, error)
- func (idx *Index) GetForwardEdgesBatch(paths []string) (map[string][]string, error)
- func (idx *Index) GetFoundations(limit int) ([]EntrypointFile, error)
- func (idx *Index) GetGoSiblingsInDir(dir, exclude string) ([]string, error)
- func (idx *Index) GetHighestChurnFile(windowDays int, exclude map[string]bool) (string, float64, error)
- func (idx *Index) GetImportedNamesForSubject(subject string) (map[string][]string, error)
- func (idx *Index) GetImporterSymbols(subject string) (map[string][]string, error)
- func (idx *Index) GetImportersOf(paths []string, exclude map[string]bool) ([]string, error)
- func (idx *Index) GetImportsOf(paths []string, exclude map[string]bool) ([]string, error)
- func (idx *Index) GetJavaSiblingsInDir(dir, exclude string) ([]string, error)
- func (idx *Index) GetMaxChurn(windowDays int) (float64, error)
- func (idx *Index) GetMaxIndegree() (int, error)
- func (idx *Index) GetMeta(key string) (string, error)
- func (idx *Index) GetOrchestrators(minIn, minOut, limit int, exclude map[string]bool) ([]EntrypointFile, error)
- func (idx *Index) GetPackageImporterCount(dir string) (int, error)
- func (idx *Index) GetRustSiblingsInDir(dir, exclude string) ([]string, error)
- func (idx *Index) GetSignals(paths []string) (map[string]SignalRow, error)
- func (idx *Index) GetSubjectResolutionRate(subject string) (int, int, error)
- func (idx *Index) GetTestFilesByName(dir string, basenames []string) ([]string, error)
- func (idx *Index) GetTestFilesInDir(dir, suffix string) ([]string, error)
- func (idx *Index) GetUnresolvedByFile(path string) ([]UnresolvedRecord, error)
- func (idx *Index) GetUnresolvedSummary() (UnresolvedSummary, error)
- func (idx *Index) GitSignalCount(windowDays int) (int, error)
- func (idx *Index) MigrateToLatest() (bool, error)
- func (idx *Index) PackageRootCount() (int, error)
- func (idx *Index) SchemaVersion() (int, error)
- func (idx *Index) SearchByPath(query string, limit int) ([]SearchResult, error)
- func (idx *Index) SearchBySymbol(symbol string, limit int) ([]SearchResult, error)
- func (idx *Index) SetMeta(key, value string) error
- func (idx *Index) UnresolvedCount() (int, error)
- func (idx *Index) UpsertPackageRoots(roots []PackageRootRecord) error
- func (idx *Index) UtilityCount() (int, error)
- type PackageRootRecord
- type SearchResult
- type SignalRow
- type UnresolvedRecord
- type UnresolvedSummary
Constants ¶
const IndexDir = ".contextception"
IndexDir is the directory name where the index is stored.
const IndexFile = "index.sqlite"
IndexFile is the filename of the SQLite database.
Variables ¶
This section is empty.
Functions ¶
func ClearAllDataTx ¶
ClearAllDataTx removes all data from files, edges, unresolved, signals, and git signal tables within a transaction.
func ClearGitDataTx ¶
ClearGitDataTx clears git_signals and co_change_pairs within a transaction.
func DeleteFileEdgesTx ¶
DeleteFileEdgesTx removes all edges originating from a file within a transaction.
func DeleteFileSignalsTx ¶
DeleteFileSignalsTx removes signals for a file within a transaction.
func DeleteFileTx ¶
DeleteFileTx removes a file and its associated edges/signals/unresolved (via CASCADE) within a transaction.
func DeleteFileUnresolvedTx ¶
DeleteFileUnresolvedTx removes all unresolved imports for a file within a transaction.
func FileExistsTx ¶
FileExistsTx checks if a file path exists in the index.
func InsertCoChangePairTx ¶
func InsertCoChangePairTx(tx *sql.Tx, r CoChangePairRecord) error
InsertCoChangePairTx inserts a co-change pair record within an existing transaction.
func InsertEdgeTx ¶
func InsertEdgeTx(tx *sql.Tx, src, dst, edgeType, spec, method string, line int, importedNames []string) error
InsertEdgeTx inserts a dependency edge within an existing transaction. Ignores duplicate edges silently. importedNames may be nil for bare imports.
func InsertFileTx ¶
InsertFileTx inserts a file record within an existing transaction.
func InsertGitSignalTx ¶
func InsertGitSignalTx(tx *sql.Tx, r GitSignalRecord) error
InsertGitSignalTx inserts a git signal record within an existing transaction.
func InsertUnresolvedTx ¶
InsertUnresolvedTx inserts an unresolved import within an existing transaction. Ignores duplicates silently.
Types ¶
type CoChangePairRecord ¶
type CoChangePairRecord struct {
FileA string
FileB string
Frequency int
WindowDays int
ComputedAt string
}
CoChangePairRecord represents a row in the co_change_pairs table.
type CoChangePartner ¶
CoChangePartner represents a file that co-changes with a given file.
type DirLanguageCount ¶
DirLanguageCount represents a directory's file count for a specific language.
type DirectedEdge ¶
DirectedEdge represents a directed dependency edge between two files.
type EntrypointFile ¶
EntrypointFile represents a file with structural graph signals.
type GitSignalRecord ¶
type GitSignalRecord struct {
FilePath string
SignalType string
Value float64
WindowDays int
ComputedAt string
}
GitSignalRecord represents a row in the git_signals table.
type Index ¶
Index wraps the SQLite database connection for the contextception index.
func OpenIndex ¶
OpenIndex opens or creates the SQLite index database at the given path. It configures pragmas for WAL mode, foreign keys, and busy timeout. On first creation, it ensures .contextception/ is in .gitignore.
func (*Index) CoChangePairCount ¶
CoChangePairCount returns the number of co-change pairs for the given window.
func (*Index) EntrypointCount ¶
EntrypointCount returns the number of files flagged as entrypoints.
func (*Index) FileExists ¶
FileExists checks if a file path exists in the index (non-transaction version).
func (*Index) GetAllFileHashes ¶
GetAllFileHashes returns a map of path→content_hash for all indexed files.
func (*Index) GetChurnForFiles ¶
GetChurnForFiles returns churn values for the given paths and window.
func (*Index) GetCoChangePartners ¶
func (idx *Index) GetCoChangePartners(path string, windowDays int, limit int) ([]CoChangePartner, error)
GetCoChangePartners returns files that co-change with the given path, sorted by frequency desc. Pass limit=0 to return all partners (no limit).
func (*Index) GetDirectImporters ¶
GetDirectImporters returns all files that import the given file.
func (*Index) GetDirectImports ¶
GetDirectImports returns all files imported by the given file.
func (*Index) GetDirectoryStructure ¶
func (idx *Index) GetDirectoryStructure() ([]DirLanguageCount, error)
GetDirectoryStructure returns file counts grouped by top-level directory and language.
func (*Index) GetEdgesAmong ¶
func (idx *Index) GetEdgesAmong(paths []string) ([]DirectedEdge, error)
GetEdgesAmong returns directed edges where both src and dst are in the given path set.
func (*Index) GetEntrypoints ¶
func (idx *Index) GetEntrypoints() ([]EntrypointFile, error)
GetEntrypoints returns files flagged as entrypoints (is_entrypoint=1 in signals).
func (*Index) GetForwardEdgesBatch ¶
GetForwardEdgesBatch returns forward edges (imports) for multiple files in a single query. Returns a map of source file → list of destination files.
func (*Index) GetFoundations ¶
func (idx *Index) GetFoundations(limit int) ([]EntrypointFile, error)
GetFoundations returns the top-N files by indegree, excluding entrypoints and utilities. These are the most depended-upon source files in the project.
func (*Index) GetGoSiblingsInDir ¶
GetGoSiblingsInDir returns non-test .go files in the given directory, excluding the specified file and subdirectories.
func (*Index) GetHighestChurnFile ¶
func (idx *Index) GetHighestChurnFile(windowDays int, exclude map[string]bool) (string, float64, error)
GetHighestChurnFile returns the file with the highest churn value for the given window, excluding files in the exclude set. Returns empty string if no churn data exists.
func (*Index) GetImportedNamesForSubject ¶
GetImportedNamesForSubject returns dst_file → symbol names for all edges from subject.
func (*Index) GetImporterSymbols ¶
GetImporterSymbols returns src_file → symbol names for all edges into subject.
func (*Index) GetImportersOf ¶
GetImportersOf returns reverse edges from multiple files, excluding a set.
func (*Index) GetImportsOf ¶
GetImportsOf returns forward edges from multiple files, excluding a set.
func (*Index) GetJavaSiblingsInDir ¶
GetJavaSiblingsInDir returns non-test .java files in the given directory, excluding the specified file and subdirectories.
func (*Index) GetMaxChurn ¶
GetMaxChurn returns the maximum churn value across all files for the given window.
func (*Index) GetMaxIndegree ¶
GetMaxIndegree returns the maximum indegree across all signals.
func (*Index) GetOrchestrators ¶
func (idx *Index) GetOrchestrators(minIn, minOut, limit int, exclude map[string]bool) ([]EntrypointFile, error)
GetOrchestrators returns files with high connectivity in both directions (indegree >= minIn AND outdegree >= minOut), ordered by total degree descending. Files in the exclude set are skipped.
func (*Index) GetPackageImporterCount ¶
GetPackageImporterCount returns the count of distinct files from OTHER directories that have edges pointing to any file in the given directory. Approximates "how many files outside this Go package depend on this package".
func (*Index) GetRustSiblingsInDir ¶
GetRustSiblingsInDir returns non-test .rs files in the given directory, excluding the specified file and subdirectories.
func (*Index) GetSignals ¶
GetSignals returns signals for the given file paths.
func (*Index) GetSubjectResolutionRate ¶
GetSubjectResolutionRate returns (resolvedCount, notFoundCount) for a subject file. resolvedCount = edges from subject (internal resolved imports). notFoundCount = unresolved from subject with reason 'not_found' (internal misses), plus unresolved crate::, super::, and self:: specifiers (always internal in Rust). External and stdlib unresolved are excluded (expected, not failures).
func (*Index) GetTestFilesByName ¶
GetTestFilesByName searches recursively under a directory prefix for files matching any of the given basenames. Used for Python tests/ directory discovery where test files (e.g., test_pipelines.py) live in a separate tests/ tree.
func (*Index) GetTestFilesInDir ¶
GetTestFilesInDir returns files in the given directory (not subdirectories) matching a suffix. Used for Go (_test.go) and Rust test discovery.
func (*Index) GetUnresolvedByFile ¶
func (idx *Index) GetUnresolvedByFile(path string) ([]UnresolvedRecord, error)
GetUnresolvedByFile returns all unresolved imports for a given file.
func (*Index) GetUnresolvedSummary ¶
func (idx *Index) GetUnresolvedSummary() (UnresolvedSummary, error)
GetUnresolvedSummary returns aggregate unresolved import counts grouped by reason.
func (*Index) GitSignalCount ¶
GitSignalCount returns the number of files with git signals for the given window.
func (*Index) MigrateToLatest ¶
MigrateToLatest applies all pending migrations to bring the schema up to date. Each migration runs in its own transaction. Returns true when any migration was applied, false when already up to date.
func (*Index) PackageRootCount ¶
PackageRootCount returns the number of detected package roots.
func (*Index) SchemaVersion ¶
SchemaVersion reads the current schema version from the meta table. Returns 0 if the meta table does not exist (fresh database).
func (*Index) SearchByPath ¶
func (idx *Index) SearchByPath(query string, limit int) ([]SearchResult, error)
SearchByPath returns files whose path contains the query substring (case-insensitive).
func (*Index) SearchBySymbol ¶
func (idx *Index) SearchBySymbol(symbol string, limit int) ([]SearchResult, error)
SearchBySymbol returns files that export the given symbol name (exact match). Searches the imported_names JSON column on edges — finds dst_file where any importer references the given symbol name.
func (*Index) UnresolvedCount ¶
UnresolvedCount returns the number of unresolved imports.
func (*Index) UpsertPackageRoots ¶
func (idx *Index) UpsertPackageRoots(roots []PackageRootRecord) error
UpsertPackageRoots replaces all package roots for a given language.
func (*Index) UtilityCount ¶
UtilityCount returns the number of files flagged as utilities.
type PackageRootRecord ¶
PackageRootRecord represents a package root for bulk upsert.
type SearchResult ¶
SearchResult represents a file found by a search query.
type UnresolvedRecord ¶
UnresolvedRecord represents a single unresolved import row.
type UnresolvedSummary ¶
UnresolvedSummary holds aggregate unresolved import statistics.