Pular para conteúdo

Persistência (SQLite)

Database layer for semtree.

schema

SQLite schema v1 for semtree.

Design goals: - FTS5 full-text search on symbol names and docstrings - Vec-ready: embedding column stored as BLOB (sqlite-vec compatible) - Incremental hashing: skip re-parse if SHA-1 unchanged - Lean writes: single transaction per file update

init_db

init_db(path)

Create or open the database at path, applying DDL if needed.

get_version

get_version(conn)

Return the schema version stored in the database.

store

All CRUD operations against the semtree SQLite database.

Typed returns throughout - no bare Any in public API.

get_file_sha1

get_file_sha1(conn, rel_path)

Return the stored SHA-1 for rel_path, or None if not indexed.

upsert_file

upsert_file(conn, rel_path, sha1, size_bytes, lang)

Insert or update a file record. Returns the file id.

delete_file

delete_file(conn, rel_path)

Remove a file and all its symbols (CASCADE handles symbols).

list_files

list_files(conn)

Return all indexed files.

replace_file_symbols

replace_file_symbols(conn, file_id, symbols)

Delete existing symbols for file_id and insert fresh batch.

Each dict in symbols must have: name, kind, line_start, line_end, signature, docstring. git_author and git_date are optional.

fts_search(conn, query, limit=20)

Full-text search across symbol names, signatures, and docstrings.

get_symbols_for_file

get_symbols_for_file(conn, rel_path)

Return all symbols for a given relative file path.

get_symbols_by_name

get_symbols_by_name(conn, name, kind=None)

Exact-match symbol name lookup, optionally filtered by kind.

upsert_memory

upsert_memory(conn, kind, key, value)

Insert or update a memory entry.

list_memory

list_memory(conn, kind=None)

List all memory entries, optionally filtered by kind.

delete_memory

delete_memory(conn, kind, key)

Delete a memory entry. Returns True if a row was deleted.