Documentation
¶
Index ¶
- Constants
- Variables
- func CreateSchema(db *sql.DB) error
- func QueriesFromTx(tx *sql.Tx) *codedbsqlc.Queries
- type MaintenanceResult
- type Store
- func (s *Store) AttachDirtyIndex(dirtyBlevePath string) error
- func (s *Store) AttachDirtyIndexByID(id, dirtyBlevePath string) error
- func (s *Store) AttachDirtyOverlay() error
- func (s *Store) Begin() (*sql.Tx, error)
- func (s *Store) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
- func (s *Store) CheckIntegrity() error
- func (s *Store) Close() error
- func (s *Store) DBPath() string
- func (s *Store) DetachDirtyIndexByID(id string)
- func (s *Store) DetachDirtyOverlay()
- func (s *Store) DirtyCodeIndex() bleve.Index
- func (s *Store) DirtyOverlayCount() int
- func (s *Store) Exec(query string, args ...interface{}) (sql.Result, error)
- func (s *Store) Maintain(ctx context.Context) MaintenanceResult
- func (s *Store) Queries() *codedbsqlc.Queries
- func (s *Store) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (s *Store) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (s *Store) QueryRow(query string, args ...interface{}) *sql.Row
- func (s *Store) ReposDir() string
Constants ¶
const MetadataDBFile = "metadata.db"
MetadataDBFile is the filename of the SQLite database inside a CodeDB directory.
Variables ¶
var ErrCorrupt = fmt.Errorf("codedb index is corrupt")
ErrCorrupt indicates the index is corrupted and needs re-indexing.
Functions ¶
func CreateSchema ¶
CreateSchema initializes the SQLite tables and indexes.
func QueriesFromTx ¶ added in v0.6.0
QueriesFromTx returns sqlc-generated typed queries bound to a transaction.
Types ¶
type MaintenanceResult ¶ added in v0.6.0
type MaintenanceResult struct {
OrphanBlobsPruned int64
OldDiffsPruned int64
StaleSymbolsCount int64
Vacuumed bool
IntegrityOK bool
SizeBefore int64
SizeAfter int64
Duration time.Duration
}
MaintenanceResult captures what happened during codedb maintenance.
func (MaintenanceResult) TotalPruned ¶ added in v0.6.0
func (r MaintenanceResult) TotalPruned() int64
TotalPruned returns the total number of rows removed.
type Store ¶
type Store struct {
CodeIndex bleve.Index
DiffIndex bleve.Index
CommentIndex bleve.Index
Root string
CombinedCodeIndex bleve.Index // alias of CodeIndex + all dirty indexes, or just CodeIndex
// contains filtered or unexported fields
}
Store wraps a SQLite database and Bleve full-text search indexes. All SQL access goes through the convenience methods below.
The store supports a two-tier architecture:
- Shared indexes (on-disk): committed content, shared across worktrees
- Dirty overlay (on-disk or in-memory): uncommitted worktree files, per-worktree
When a dirty overlay is attached, CombinedCodeIndex transparently merges results from both tiers via Bleve IndexAlias.
func Open ¶
Open opens (or creates) a Store at the given root directory. It creates the directory structure, initializes SQLite and Bleve indexes. If SQLite corruption is detected, the database is removed and ErrCorrupt is returned so the caller can trigger a full re-index.
func (*Store) AttachDirtyIndex ¶ added in v0.5.0
AttachDirtyIndex opens an existing on-disk dirty overlay index (built by the daemon) and aliases it with the shared CodeIndex for transparent search. Uses a default key; for multi-worktree support use AttachDirtyIndexByID.
func (*Store) AttachDirtyIndexByID ¶ added in v0.6.1
AttachDirtyIndexByID opens an on-disk dirty overlay and adds it to the overlay map under the given ID. If the ID is already attached, the old overlay is detached first. Rebuilds the combined alias to include all active overlays.
func (*Store) AttachDirtyOverlay ¶ added in v0.5.0
AttachDirtyOverlay creates an in-memory Bleve index for dirty worktree files and combines it with the shared CodeIndex via IndexAlias. Search code using CombinedCodeIndex will transparently search both. Primarily used in tests; production uses AttachDirtyIndex for on-disk overlays.
func (*Store) CheckIntegrity ¶
CheckIntegrity validates that the SQLite database and all Bleve indexes are healthy. Returns nil if everything is fine, ErrCorrupt otherwise.
func (*Store) DetachDirtyIndexByID ¶ added in v0.6.1
DetachDirtyIndexByID closes and removes a specific dirty overlay by ID. Rebuilds the combined alias with remaining overlays.
func (*Store) DetachDirtyOverlay ¶ added in v0.5.0
func (s *Store) DetachDirtyOverlay()
DetachDirtyOverlay closes all attached dirty overlays and resets CombinedCodeIndex.
func (*Store) DirtyCodeIndex ¶ added in v0.6.1
DirtyCodeIndex returns the first dirty overlay index found, or nil. Used by callers that need direct access to a dirty index (e.g., for indexing docs).
func (*Store) DirtyOverlayCount ¶ added in v0.6.1
DirtyOverlayCount returns the number of currently attached dirty overlays.
func (*Store) Maintain ¶ added in v0.6.0
func (s *Store) Maintain(ctx context.Context) MaintenanceResult
Maintain runs cleanup: prunes orphaned blobs, old diffs, and vacuums. Safe to call while the store is in use — all operations use transactions.
func (*Store) Queries ¶ added in v0.6.0
func (s *Store) Queries() *codedbsqlc.Queries
Queries returns the sqlc-generated typed queries bound to the store's DB.
func (*Store) QueryContext ¶
func (s *Store) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext executes a SQL query with context and returns the rows.