db

package
v0.0.4-beta.13 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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

func Open(dbPath string, verbose bool) (*Database, error)

Open creates or opens a SQLite database at the specified path using GORM. verbose enables SQL query logging.

func (*Database) Close

func (db *Database) Close() error

func (*Database) DeleteDependenciesByFile

func (db *Database) DeleteDependenciesByFile(fileID int64) error

DeleteDependenciesByFile removes all dependency records for the given file.

func (*Database) DeleteEntitiesByFile

func (db *Database) DeleteEntitiesByFile(fileID int64) error

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 (db *Database) GetAllEntities() ([]*Entity, error)

func (*Database) GetAllRelations

func (db *Database) GetAllRelations() ([]*EntityRelation, error)

func (*Database) GetCallGraph

func (db *Database) GetCallGraph(entityID int64, depth int) (map[string]interface{}, error)

func (*Database) GetDB

func (db *Database) GetDB() *gorm.DB

GetDB returns the underlying GORM database instance.

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 (db *Database) GetDependencyCount() (int64, error)

func (*Database) GetDependencyGraph

func (db *Database) GetDependencyGraph(filePath string) (map[string]interface{}, error)

func (*Database) GetEntitiesByFile

func (db *Database) GetEntitiesByFile(fileID int64) ([]*Entity, error)

func (*Database) GetEntitiesByFileIDs

func (db *Database) GetEntitiesByFileIDs(fileIDs []int64) ([]*Entity, error)

GetEntitiesByFileIDs returns all entities belonging to the given file IDs.

func (*Database) GetEntitiesByIDs

func (db *Database) GetEntitiesByIDs(ids []int64) ([]*Entity, error)

GetEntitiesByIDs returns entities matching the given IDs in a single query.

func (*Database) GetEntityByID

func (db *Database) GetEntityByID(id int64) (*Entity, error)

func (*Database) GetEntityByName

func (db *Database) GetEntityByName(name string) ([]*Entity, error)

func (*Database) GetEntityCount

func (db *Database) GetEntityCount() (int64, error)

func (*Database) GetEntityRelations

func (db *Database) GetEntityRelations(entityID int64, relationType string) ([]*EntityRelation, error)

func (*Database) GetFileByID

func (db *Database) GetFileByID(id int64) (*File, error)

func (*Database) GetFileByPath

func (db *Database) GetFileByPath(path string) (*File, error)

func (*Database) GetFileCount

func (db *Database) GetFileCount() (int64, error)

func (*Database) GetFileEntityCounts

func (db *Database) GetFileEntityCounts() (map[int64]int, error)

GetFileEntityCounts returns a map of fileID → entity count using a single GROUP BY query instead of N+1 individual queries.

func (*Database) GetFiles

func (db *Database) GetFiles() ([]*File, error)

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 (db *Database) GetLinesOfCodeCount() (int64, error)

func (*Database) GetRelationCount

func (db *Database) GetRelationCount() (int64, error)

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 (db *Database) GetTokensCount() (int64, error)

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

func (db *Database) InsertFile(path, language, hash string, linesOfCode, tokens int) (int64, error)

InsertFile upserts a file record using SQLite ON CONFLICT (single query).

func (*Database) SearchEntities

func (db *Database) SearchEntities(query string, limit int) ([]*Entity, error)

SearchEntities performs a case-insensitive substring search on entity names using SQL LIKE, returning at most `limit` results.

func (*Database) WithTx

func (db *Database) WithTx(tx *gorm.DB) *Database

WithTx returns a shallow copy of Database that uses the given transaction instead of the underlying connection.

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.)

func (Entity) TableName

func (Entity) TableName() string

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

func (File) TableName

func (File) TableName() string

TableName specifies custom table names for GORM

Jump to

Keyboard shortcuts

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