Documentation
¶
Index ¶
- type Database
- func (db *Database) Close() error
- func (db *Database) DeleteDependenciesByFile(fileID int64) error
- func (db *Database) DeleteEntitiesByFile(fileID int64) error
- func (db *Database) FindUsages(entityID int64) ([]*EntityRelation, error)
- func (db *Database) GetAllDependencies() ([]*Dependency, error)
- func (db *Database) GetAllEntities() ([]*Entity, error)
- func (db *Database) GetAllRelations() ([]*EntityRelation, error)
- func (db *Database) GetCallGraph(entityID int64, depth int) (map[string]interface{}, error)
- func (db *Database) GetDB() *gorm.DB
- func (db *Database) GetDependencies(fileID int64) ([]*Dependency, error)
- func (db *Database) GetDependenciesByFileIDs(fileIDs []int64) ([]*Dependency, error)
- func (db *Database) GetDependencyCount() (int64, error)
- func (db *Database) GetDependencyGraph(filePath string) (map[string]interface{}, error)
- func (db *Database) GetEntitiesByFile(fileID int64) ([]*Entity, error)
- func (db *Database) GetEntitiesByFileIDs(fileIDs []int64) ([]*Entity, error)
- func (db *Database) GetEntitiesByIDs(ids []int64) ([]*Entity, error)
- func (db *Database) GetEntityByID(id int64) (*Entity, error)
- func (db *Database) GetEntityByName(name string) ([]*Entity, error)
- func (db *Database) GetEntityCount() (int64, error)
- func (db *Database) GetEntityRelations(entityID int64, relationType string) ([]*EntityRelation, error)
- func (db *Database) GetFileByID(id int64) (*File, error)
- func (db *Database) GetFileByPath(path string) (*File, error)
- func (db *Database) GetFileCount() (int64, error)
- func (db *Database) GetFileEntityCounts() (map[int64]int, error)
- func (db *Database) GetFiles() ([]*File, error)
- func (db *Database) GetImportersOfFile(filePath string) ([]*Dependency, error)
- func (db *Database) GetLinesOfCodeCount() (int64, error)
- func (db *Database) GetRelationCount() (int64, error)
- func (db *Database) GetRelationsByEntityIDs(entityIDs []int64) ([]*EntityRelation, error)
- func (db *Database) GetTokensCount() (int64, error)
- func (db *Database) InsertDependency(sourceFileID int64, targetPath, depType string, lineNumber int) (int64, error)
- func (db *Database) InsertEntity(fileID int64, name, entityType, kind, signature string, startLine, endLine int, ...) (int64, error)
- func (db *Database) InsertEntityRelation(sourceID, targetID int64, relationType string, lineNumber int, context string) (int64, error)
- func (db *Database) InsertFile(path, language, hash string, linesOfCode, tokens int) (int64, error)
- func (db *Database) SearchEntities(query string, limit int) ([]*Entity, error)
- func (db *Database) WithTx(tx *gorm.DB) *Database
- type Dependency
- type Entity
- type EntityRelation
- type File
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func Open ¶
Open creates or opens a SQLite database at the specified path using GORM. verbose enables SQL query logging.
func (*Database) DeleteDependenciesByFile ¶
DeleteDependenciesByFile removes all dependency records for the given file.
func (*Database) DeleteEntitiesByFile ¶
DeleteEntitiesByFile removes all entities for the given file. The CASCADE constraint on EntityRelation automatically removes relation rows.
func (*Database) FindUsages ¶
func (db *Database) FindUsages(entityID int64) ([]*EntityRelation, error)
FindUsages returns entity relations where the given entity is the target (i.e. other entities that reference it).
func (*Database) GetAllDependencies ¶
func (db *Database) GetAllDependencies() ([]*Dependency, error)
func (*Database) GetAllEntities ¶
func (*Database) GetAllRelations ¶
func (db *Database) GetAllRelations() ([]*EntityRelation, error)
func (*Database) GetCallGraph ¶
func (*Database) GetDependencies ¶
func (db *Database) GetDependencies(fileID int64) ([]*Dependency, error)
func (*Database) GetDependenciesByFileIDs ¶
func (db *Database) GetDependenciesByFileIDs(fileIDs []int64) ([]*Dependency, error)
GetDependenciesByFileIDs returns all dependencies for the given file IDs.
func (*Database) GetDependencyCount ¶
func (*Database) GetDependencyGraph ¶
func (*Database) GetEntitiesByFile ¶
func (*Database) GetEntitiesByFileIDs ¶
GetEntitiesByFileIDs returns all entities belonging to the given file IDs.
func (*Database) GetEntitiesByIDs ¶
GetEntitiesByIDs returns entities matching the given IDs in a single query.
func (*Database) GetEntityByName ¶
func (*Database) GetEntityCount ¶
func (*Database) GetEntityRelations ¶
func (db *Database) GetEntityRelations(entityID int64, relationType string) ([]*EntityRelation, error)
func (*Database) GetFileCount ¶
func (*Database) GetFileEntityCounts ¶
GetFileEntityCounts returns a map of fileID → entity count using a single GROUP BY query instead of N+1 individual queries.
func (*Database) GetImportersOfFile ¶
func (db *Database) GetImportersOfFile(filePath string) ([]*Dependency, error)
GetImportersOfFile returns dependencies where any file imports a path matching the given file's basename (best-effort reverse lookup). Uses path-separator-aware matching to avoid false positives like "fakedb.go" matching when looking for "db.go".
func (*Database) GetLinesOfCodeCount ¶
func (*Database) GetRelationCount ¶
func (*Database) GetRelationsByEntityIDs ¶
func (db *Database) GetRelationsByEntityIDs(entityIDs []int64) ([]*EntityRelation, error)
GetRelationsByEntityIDs returns all relations where the source entity ID is in the given set. Efficient for batch-loading relations for a file's entities.
func (*Database) GetTokensCount ¶
func (*Database) InsertDependency ¶
func (db *Database) InsertDependency(sourceFileID int64, targetPath, depType string, lineNumber int) (int64, error)
InsertDependency inserts a dependency record. Callers must ensure old dependencies for the file have been deleted first.
func (*Database) InsertEntity ¶
func (db *Database) InsertEntity(fileID int64, name, entityType, kind, signature string, startLine, endLine int, docs, parent, visibility, scope, language string) (int64, error)
InsertEntity inserts a new entity record. Callers must ensure old entities for the file have been deleted first (the indexer does this via DeleteEntitiesByFile before re-inserting).
func (*Database) InsertEntityRelation ¶
func (db *Database) InsertEntityRelation(sourceID, targetID int64, relationType string, lineNumber int, context string) (int64, error)
InsertEntityRelation inserts a relation row. Old relations are removed via CASCADE when entities are deleted during re-indexing.
func (*Database) InsertFile ¶
InsertFile upserts a file record using SQLite ON CONFLICT (single query).
func (*Database) SearchEntities ¶
SearchEntities performs a case-insensitive substring search on entity names using SQL LIKE, returning at most `limit` results.
type Dependency ¶
type Dependency struct {
ID int64 `gorm:"primaryKey"`
SourceFileID int64 `gorm:"index;not null"`
TargetPath string `gorm:"not null"` // Import path as written in code
ImportType string // import, require, from, include
LineNumber int
Resolved string // Resolved module/file path if determined
IsLocal bool // True if local module/relative import
SourceFile *File `gorm:"foreignKey:SourceFileID"`
}
Dependency represents a file dependency (import/require)
func (Dependency) TableName ¶
func (Dependency) TableName() string
type Entity ¶
type Entity struct {
ID int64 `gorm:"primaryKey"`
FileID int64 `gorm:"index;not null"`
Name string `gorm:"index;not null"`
Type string `gorm:"index;not null"` // function, class, interface, type, method, etc.
Kind string // specific kind: async_function, arrow_function, method, etc.
Signature string
StartLine int
EndLine int
ColumnStart int
ColumnEnd int
Documentation string
// Multi-language support fields
Parent string // Parent entity name for nested entities (e.g., "ClassName" for methods)
Visibility string `gorm:"index"` // public, private, protected, internal
Scope string // file, class, module, global, local
Language string `gorm:"index"` // go, python, javascript, typescript, java
Attributes string // JSON: {decorators: [], typeParams: [], modifiers: [], etc.}
// Relationships
File *File `gorm:"foreignKey:FileID"`
SourceRelations []EntityRelation `gorm:"foreignKey:SourceEntityID;constraint:OnDelete:CASCADE"`
TargetRelations []EntityRelation `gorm:"foreignKey:TargetEntityID;constraint:OnDelete:CASCADE"`
}
Entity represents a code entity (function, class, type, etc.)
type EntityRelation ¶
type EntityRelation struct {
ID int64 `gorm:"primaryKey"`
SourceEntityID int64 `gorm:"index;not null"`
TargetEntityID int64 `gorm:"index;not null"`
RelationType string `gorm:"index;not null"`
LineNumber int
Context string
SourceEntity *Entity `gorm:"foreignKey:SourceEntityID"`
TargetEntity *Entity `gorm:"foreignKey:TargetEntityID"`
}
EntityRelation represents relationships between entities
func (EntityRelation) TableName ¶
func (EntityRelation) TableName() string
type File ¶
type File struct {
ID int64 `gorm:"primaryKey"`
Path string `gorm:"uniqueIndex;not null"`
Language string `gorm:"not null"`
Hash string
LinesOfCode int
Tokens int
Entities []Entity `gorm:"foreignKey:FileID;constraint:OnDelete:CASCADE"`
Dependencies []Dependency `gorm:"foreignKey:SourceFileID;constraint:OnDelete:CASCADE"`
}
File represents a source file in the codebase