Skip to main content

GraphDb

Struct GraphDb 

Source
pub struct GraphDb {
    pub conn: Connection,
    pub repo_id: String,
    pub db_path: PathBuf,
}
Expand description

Handle to the DuckDB database that stores the code knowledge graph.

Each repository gets its own .db file under ~/.cgx/repos/<repo_id>.db. All methods operate on the embedded DuckDB connection and are synchronous.

Fields§

§conn: Connection§repo_id: String

SHA-256–derived stable identifier for the repository path.

§db_path: PathBuf

Implementations§

Source§

impl GraphDb

Source

pub fn open(repo_path: &Path) -> Result<Self>

Open (or create) the graph database for the repository at repo_path.

Creates all required tables and runs forward migrations on existing databases.

Source

pub fn upsert_nodes(&self, nodes: &[Node]) -> Result<usize>

Insert or replace nodes in the nodes table, returning the count written.

Source

pub fn upsert_edges(&self, edges: &[Edge]) -> Result<usize>

Insert or replace edges in the edges table, returning the count written.

Source

pub fn upsert_tags(&self, tags: &[TagRow]) -> Result<usize>

Insert or replace comment annotation tags, returning the count written.

Source

pub fn get_tags( &self, tag_type_filter: Option<&str>, comment_type_filter: Option<&str>, ) -> Result<Vec<TagRow>>

Query comment annotation tags with optional filters on tag type and comment kind.

Source

pub fn clear_all_tags(&self) -> Result<()>

Drop and recreate the tags table, removing all stored annotations.

Source

pub fn delete_tags_for_paths(&self, paths: &[String]) -> Result<()>

Delete all tags whose file_path is in paths (used during incremental re-index).

Source

pub fn get_node(&self, id: &str) -> Result<Option<Node>>

Fetch a single node by its stable id, returning None if not found.

Source

pub fn get_neighbors(&self, id: &str, depth: u8) -> Result<Vec<Node>>

BFS outward from id following edges in both directions, up to depth hops (max 3).

Source

pub fn get_all_nodes(&self) -> Result<Vec<Node>>

Return every node in the graph.

Source

pub fn get_all_edges(&self) -> Result<Vec<Edge>>

Return every edge in the graph.

Source

pub fn node_count(&self) -> Result<u64>

Total number of nodes in the graph.

Source

pub fn edge_count(&self) -> Result<u64>

Total number of edges in the graph.

Source

pub fn clear(&self) -> Result<()>

Truncate nodes, edges, and communities tables (does not remove file hashes).

Source

pub fn get_language_breakdown(&self) -> Result<HashMap<String, f64>>

Fraction of nodes per language, normalised to sum to 1.0.

Source

pub fn get_node_counts_by_kind(&self) -> Result<HashMap<String, u64>>

Count of nodes per [NodeKind] string, e.g. {"Function": 412, "File": 38}.

Source

pub fn upsert_node_scores( &self, node_id: &str, churn: f64, coupling: f64, ) -> Result<()>

Write normalised churn and coupling scores back to a single node.

Source

pub fn update_in_out_degrees(&self) -> Result<()>

Recompute and persist in_degree / out_degree for every node.

Source

pub fn get_hotspots(&self, limit: usize) -> Result<Vec<(String, f64, f64, i64)>>

Return the top limit file hotspots ranked by churn × coupling + in_degree.

Each tuple is (path, churn, coupling, in_degree).

Source

pub fn get_ownership(&self) -> Result<Vec<(String, i64)>>

Return (author_name, file_count) pairs sorted by file count descending.

Source

pub fn compute_coupling(&self) -> Result<()>

Recompute coupling for every File node as in_degree / max_in_degree.

Source

pub fn update_node_communities( &self, communities: &HashMap<String, i64>, ) -> Result<usize>

Write Louvain community assignments from detect_communities back to the DB.

Source

pub fn get_stats(&self) -> Result<RepoStats>

Return a RepoStats summary for the currently indexed repository.

Source

pub fn get_entry_points(&self, limit: usize) -> Result<Vec<Node>>

Return up to limit nodes with in_degree == 0 — likely entry points or roots.

Source

pub fn get_god_nodes(&self, limit: usize) -> Result<Vec<Node>>

Return up to limit nodes with the highest in_degree — the most-depended-on symbols.

Source

pub fn get_communities(&self) -> Result<Vec<CommunityRow>>

Return all communities as CommunityRow tuples, sorted by size descending.

Source

pub fn clear_communities(&self) -> Result<()>

Reset all community assignments to 0 and clear the communities table.

Source

pub fn get_dependents(&self, id: &str, depth: u8) -> Result<Vec<Node>>

BFS following only incoming edges — returns all nodes that depend on id. Used for blast-radius analysis: if id changes, these nodes are affected.

Source

pub fn get_nodes_by_community(&self, community: i64) -> Result<Vec<Node>>

Return all nodes that belong to the given community ID.

Source

pub fn mark_dead_candidates(&self, items: &[(String, String)]) -> Result<()>

Set is_dead_candidate = true and dead_reason for each (node_id, reason) pair.

Source

pub fn get_dead_code_stats(&self) -> Result<(i64, i64)>

Return (total_dead_candidates, high_confidence_count) from the DB.

Source

pub fn get_edges_by_community(&self, community: i64) -> Result<Vec<Edge>>

Return all edges where both endpoints belong to the given community.

Source

pub fn get_file_hashes(&self) -> Result<HashMap<String, String>>

Load the SHA-256 content hashes of all previously indexed files (used for incremental indexing).

Source

pub fn set_file_hash(&self, path: &str, hash: &str) -> Result<()>

Record or update the SHA-256 hash for a single file path.

Source

pub fn remove_file_hashes(&self, paths: &[String]) -> Result<()>

Remove stored file hashes for deleted or moved files.

Source

pub fn delete_nodes_by_paths(&self, paths: &[String]) -> Result<usize>

Delete all nodes (and their connected edges) whose path is in paths.

Used during incremental re-indexing to remove stale data for changed files.

Source

pub fn update_node_doc_comment(&self, id: &str, doc: &str) -> Result<()>

Store a doc comment string on a node (used by the docs-coverage analysis pass).

Source

pub fn update_node_complexity(&self, id: &str, complexity: f64) -> Result<()>

Write a cyclomatic-complexity score back to a single node.

Source

pub fn get_nodes_by_complexity( &self, limit: usize, min_score: f64, ) -> Result<Vec<Node>>

Return up to limit Function nodes with complexity >= min_score, sorted descending.

Source

pub fn get_docs_coverage(&self) -> Result<DocsCoverage>

Returns (overall_pct, Vec<(community_id, documented, total)>, Vec)

Source

pub fn upsert_clones(&self, clones: &[CloneRow]) -> Result<usize>

Insert or replace clone-pair records, returning the count written.

Source

pub fn get_clones( &self, min_similarity: f64, kind_filter: Option<&str>, ) -> Result<Vec<CloneRow>>

Query clone pairs above min_similarity, optionally filtered by kind ("exact" or "near").

Source

pub fn clear_clones(&self) -> Result<()>

Delete all clone-pair records from the database.

Source

pub fn mark_test_files(&self, paths: &[String]) -> Result<()>

Flag every node whose path is in paths as a test file (is_test_file = true).

Source

pub fn update_test_coverage(&self) -> Result<()>

After inserting TESTS edges, compute test_count and is_tested for non-test nodes.

Source

pub fn get_test_coverage_summary( &self, top_n: usize, ) -> Result<(f64, i64, i64, Vec<Node>)>

Returns (overall_pct, tested_count, untested_count, gaps ranked by risk)

Source

pub fn upsert_snapshot(&self, entry: &SnapshotEntry) -> Result<()>

Insert or replace a timeline snapshot entry.

Source

pub fn get_snapshots(&self, limit: usize) -> Result<Vec<SnapshotEntry>>

Return up to limit timeline snapshots, most recent first.

Source

pub fn get_snapshot_by_sha(&self, sha: &str) -> Result<Option<SnapshotEntry>>

Look up a snapshot by full SHA or short prefix, returning None if not cached.

Source

pub fn snapshot_count(&self) -> i64

Total number of cached timeline snapshots.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more