Documentation
¶
Overview ¶
Package db implements SQLite-backed persistence for the file/symbol cache shared between the Go and Python implementations of AST-Digger. It corresponds to ast_digger/db.py in the Python implementation.
Index ¶
- type FileMeta
- type SymbolDatabase
- func (db *SymbolDatabase) Close() error
- func (db *SymbolDatabase) DeleteFileCache(filePath string) error
- func (db *SymbolDatabase) GetAllFiles() (map[string]FileMeta, error)
- func (db *SymbolDatabase) GetSymbolsInDirectory(dirPath string) ([]parser.SymbolData, error)
- func (db *SymbolDatabase) UpdateFileCache(filePath string, mtime float64, hash string, language string, ...) error
- func (db *SymbolDatabase) UpdateFileMtime(filePath string, mtime float64) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileMeta ¶
type FileMeta struct {
// Mtime is the last-observed modification time of the file (seconds
// since epoch, matching Python's os.path.getmtime()).
Mtime float64
// Hash is the content hash (SHA-256) of the file at Mtime.
Hash string
// Language identifies the parser/language used ("python", "typescript",
// "go", ...).
Language string
}
FileMeta holds the cached metadata AST-Digger tracks per source file, as stored in the `files` table. It mirrors the (mtime, hash, language) tuple returned by Python's SymbolDatabase.get_all_files().
type SymbolDatabase ¶
type SymbolDatabase struct {
// contains filtered or unexported fields
}
SymbolDatabase manages the SQLite cache database (`.workspace_cache/symbols.db`) shared with the Python implementation. It corresponds to Python's ast_digger.db.SymbolDatabase.
func NewSymbolDatabase ¶
func NewSymbolDatabase(dbPath string) (*SymbolDatabase, error)
NewSymbolDatabase opens (creating if necessary) the SQLite database at dbPath and ensures its schema matches the shared cache schema. dbPath may be ":memory:" for an in-memory database.
If dbPath refers to an existing file whose schema is missing required tables/columns (i.e. it was created by an incompatible/older version of either implementation), the file is deleted and rebuilt from scratch. This mirrors Python's SymbolDatabase._init_db() "detect and self-heal" behavior; callers are not expected to see an error in that case.
func (*SymbolDatabase) Close ¶
func (db *SymbolDatabase) Close() error
Close closes the underlying database connection.
func (*SymbolDatabase) DeleteFileCache ¶
func (db *SymbolDatabase) DeleteFileCache(filePath string) error
DeleteFileCache removes filePath's metadata (and, via ON DELETE CASCADE, its symbols) from the cache.
func (*SymbolDatabase) GetAllFiles ¶
func (db *SymbolDatabase) GetAllFiles() (map[string]FileMeta, error)
GetAllFiles returns the metadata of every file currently tracked in the cache, keyed by file path.
func (*SymbolDatabase) GetSymbolsInDirectory ¶
func (db *SymbolDatabase) GetSymbolsInDirectory(dirPath string) ([]parser.SymbolData, error)
GetSymbolsInDirectory returns all cached symbols whose file path is dirPath itself or lies under dirPath. An empty dirPath or "." returns every cached symbol.
func (*SymbolDatabase) UpdateFileCache ¶
func (db *SymbolDatabase) UpdateFileCache(filePath string, mtime float64, hash string, language string, symbols []parser.SymbolData) error
UpdateFileCache replaces the cached metadata and symbols for filePath with mtime/hash/language/symbols, inside a single transaction.
NOTE on the CASCADE-delete-through-INSERT-OR-REPLACE trick: like Python's SymbolDatabase.update_file_cache(), this method does NOT explicitly "DELETE FROM symbols WHERE file_path = ?" before inserting the new symbols. Instead it relies on a SQLite implementation detail: "INSERT OR REPLACE INTO files ..." resolves a PRIMARY KEY conflict by deleting the conflicting row and then inserting the new one, and because this connection has "PRAGMA foreign_keys = ON" set, that internal DELETE triggers the "ON DELETE CASCADE" on symbols.file_path, wiping out all of the previous symbol rows for filePath before the fresh INSERTs below run. This is intentional behavior-parity with the Python implementation (see ast_digger/db.py: SymbolDatabase.update_file_cache) and must not be "simplified" by adding an explicit DELETE, since callers/tests may depend on the exact statement ordering matching the Python original.
func (*SymbolDatabase) UpdateFileMtime ¶
func (db *SymbolDatabase) UpdateFileMtime(filePath string, mtime float64) error
UpdateFileMtime updates the cached mtime of filePath without touching its hash, language, or symbols. It corresponds to Python's SymbolDatabase.update_file_mtime(), used by the Outliner (task 6) to refresh mtime after a cache hit that skips re-parsing.