Skip to content

Commit 37ec95f

Browse files
authored
perf(db): migrate Repository read queries to NativeDatabase rusqlite (6.14) (#671)
* perf(db): migrate Repository read queries to NativeDatabase rusqlite (6.14) Implement all 40 Repository read methods as Rust napi-rs methods on NativeDatabase so every query runs via rusqlite when the native engine is available. openRepo() now returns NativeRepository (delegating to NativeDatabase.openReadonly) with automatic fallback to SqliteRepository. Rust side: read_types.rs defines 14 napi return-type structs, read_queries.rs implements 40 query methods including BFS for getClassHierarchy and dynamic SQL for triage/fan-in queries. TypeScript side: NativeRepository maps napi camelCase rows back to the snake_case field names the Repository interface expects. * fix: make line fields optional in three Native row types (#671) The nodes table allows NULL for line, but these three Rust structs declared line as non-optional i32. Any node with a NULL line (e.g. file-kind nodes) would trigger a rusqlite type-mismatch error. Change to Option<i32> in Rust and number | null in TypeScript, with ?? 0 fallback in the converter functions to match existing Repository interface contracts. * fix: re-throw DbError and guard ndb handle in openRepo (#671) Re-throw DbError (e.g. DB not found) instead of silently falling back to better-sqlite3, which would produce a misleading debug message. Also wrap the ndb setup block in try/catch to close the handle if an exception occurs after openReadonly, preventing resource leaks. * fix: distinguish table-not-found from I/O errors in table checks (#671) has_cfg_tables, has_embeddings, and has_dataflow_table previously caught all rusqlite errors and returned false. Now only SqliteFailure (and QueryReturnedNoRows for embeddings) map to false — genuine I/O or connection errors propagate as napi errors.
1 parent 497f984 commit 37ec95f

8 files changed

Lines changed: 2002 additions & 3 deletions

File tree

crates/codegraph-core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub mod import_resolution;
1111
pub mod incremental;
1212
pub mod insert_nodes;
1313
pub mod native_db;
14+
pub mod read_queries;
15+
pub mod read_types;
1416
pub mod parallel;
1517
pub mod parser_registry;
1618
pub mod roles_db;

crates/codegraph-core/src/native_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ impl NativeDatabase {
668668

669669
impl NativeDatabase {
670670
/// Get a reference to the open connection, or error if closed.
671-
fn conn(&self) -> napi::Result<&Connection> {
671+
pub(crate) fn conn(&self) -> napi::Result<&Connection> {
672672
self.conn
673673
.as_ref()
674674
.ok_or_else(|| napi::Error::from_reason("NativeDatabase is closed"))

0 commit comments

Comments
 (0)