store

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package store wraps the per-repo SQLite index database.

The DB lives at ~/.cogni/<repo-hash>/index.db. v0.1 schema is embedded as schema.sql and applied on Open. Writers must serialize themselves; readers are concurrent-safe via SQLite's WAL mode.

Index

Constants

View Source
const SchemaVersion = "1"

SchemaVersion is the current store schema. Bumped on incompatible changes.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileRow

type FileRow struct {
	ID          int64
	Path        string
	SHA256      string
	MtimeNs     int64
	SizeBytes   int64
	LineCount   int
	Language    string
	LastIndexed int64
}

FileRow describes a row in the files table.

type RefRow

type RefRow struct {
	ID          int64
	FileID      int64
	FilePath    string
	SymbolName  string
	Line        int
	Col         int
	ContextKind string
}

RefRow is a persisted reference joined with its file path.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store owns a sql.DB handle to the index database.

func Open

func Open(path string) (*Store, error)

Open opens (or creates) the SQLite index at path and applies the schema. The caller must Close() when done.

func (*Store) AllFilePaths

func (s *Store) AllFilePaths() ([]string, error)

AllFilePaths returns every indexed file's repo-relative path. Used by repo_overview to build the package tree in Go.

func (*Store) Close

func (s *Store) Close() error

Close releases the underlying DB handle.

func (*Store) DB

func (s *Store) DB() *sql.DB

DB exposes the raw handle for advanced callers (tests, future tools).

func (*Store) DeleteFile

func (s *Store) DeleteFile(path string) error

DeleteFile removes the row for path; symbols cascade.

func (*Store) FileSHA

func (s *Store) FileSHA(path string) (string, error)

FileSHA returns the sha256 stored for path, or sql.ErrNoRows if absent.

func (*Store) RefsByName

func (s *Store) RefsByName(name string, kinds []string, limit int) ([]RefRow, error)

RefsByName returns reference sites for the bare symbol name. When kinds is non-empty, results are restricted to those context kinds.

func (*Store) ReplaceRefs

func (s *Store) ReplaceRefs(fileID int64, refs []parse.Reference) error

ReplaceRefs deletes all refs for fileID and inserts the given references in a single transaction. Use from the indexer after each (re)parse.

func (*Store) ReplaceSymbols

func (s *Store) ReplaceSymbols(fileID int64, syms []parse.Symbol) error

ReplaceSymbols deletes the existing symbols for fileID and inserts the given symbols in a single transaction. The FTS5 mirror updates via triggers. Use this from the indexer after each (re)parse.

func (*Store) SchemaVersionFromDB

func (s *Store) SchemaVersionFromDB() (string, error)

SchemaVersionFromDB returns the schema version recorded in the meta table.

func (*Store) SymbolsByFile

func (s *Store) SymbolsByFile(path string) ([]SymbolRow, error)

SymbolsByFile returns all symbols for the given repo-relative file path, ordered by start_line. Used by file_outline.

func (*Store) SymbolsByName

func (s *Store) SymbolsByName(q string, limit int) ([]SymbolRow, error)

SymbolsByName returns symbols whose bare name exactly matches q.

func (*Store) SymbolsByQualified

func (s *Store) SymbolsByQualified(q string, limit int) ([]SymbolRow, error)

SymbolsByQualified returns symbols whose fully-qualified name matches q exactly. Used by symbol_source for unambiguous lookup.

func (*Store) SymbolsFTS

func (s *Store) SymbolsFTS(q, kind string, limit int) ([]SymbolRow, error)

SymbolsFTS runs a trigram FTS5 query over name/qualified/docstring and returns the matching symbol rows, ordered by relevance. When kind is non-empty and not "any", results are restricted to that symbol kind.

func (*Store) TopExportedSymbolsByPrefix

func (s *Store) TopExportedSymbolsByPrefix(prefix string, limit int) ([]SymbolRow, error)

TopExportedSymbolsByPrefix returns up to limit non-underscore symbols whose file path begins with prefix. Used by repo_overview to surface the most visible names per package.

func (*Store) UpsertFile

func (s *Store) UpsertFile(f FileRow) (int64, error)

UpsertFile inserts a file row or updates the existing row at the same path. Returns the file id.

type SymbolRow

type SymbolRow struct {
	ID        int64
	FileID    int64
	FilePath  string
	Name      string
	Qualified string
	Kind      string
	StartLine int
	EndLine   int
	Signature string
	Docstring string
}

SymbolRow is the persisted form of parse.Symbol joined with its file path.

Jump to

Keyboard shortcuts

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