pub struct QueryBuilder<'a> { /* private fields */ }Expand description
Fluent query builder for graph operations.
Allows chaining multiple filters to find specific nodes in the graph.
§Examples
use codegraph::{CodeGraph, NodeType};
let mut graph = CodeGraph::in_memory()?;
// ... populate graph ...
// Find all public functions in a specific file
let results = graph.query()
.node_type(NodeType::Function)
.in_file("src/main.rs")
.property("visibility", "public")
.execute()?;Implementations§
Source§impl<'a> QueryBuilder<'a>
impl<'a> QueryBuilder<'a>
Sourcepub fn node_type(self, node_type: NodeType) -> Self
pub fn node_type(self, node_type: NodeType) -> Self
Filter nodes by type.
§Examples
let functions = graph.query()
.node_type(NodeType::Function)
.execute()?;Sourcepub fn in_file(self, file_path: &str) -> Self
pub fn in_file(self, file_path: &str) -> Self
Filter nodes that are contained in a specific file.
Looks up the file by path and finds all nodes connected via Contains edges.
Sourcepub fn file_pattern(self, pattern: &str) -> Self
pub fn file_pattern(self, pattern: &str) -> Self
Filter files by glob pattern.
Supports wildcards: * matches any characters, ** matches directories.
§Examples
src/*.rs- All Rust files in src/**/*.py- All Python files recursivelytests/**/*.rs- All Rust files under tests/
Sourcepub fn property<V: Into<PropertyValue>>(self, key: &str, value: V) -> Self
pub fn property<V: Into<PropertyValue>>(self, key: &str, value: V) -> Self
Filter nodes by exact property match.
Supports string, int, float, and bool property values.
Sourcepub fn property_exists(self, key: &str) -> Self
pub fn property_exists(self, key: &str) -> Self
Filter nodes that have a specific property (regardless of value).
Sourcepub fn name_contains(self, substring: &str) -> Self
pub fn name_contains(self, substring: &str) -> Self
Filter nodes by name containing a substring (case-insensitive).
Sourcepub fn name_matches(self, pattern: &str) -> Self
pub fn name_matches(self, pattern: &str) -> Self
Filter nodes by name matching a regex pattern.
Sourcepub fn custom<F>(self, predicate: F) -> Self
pub fn custom<F>(self, predicate: F) -> Self
Filter nodes using a custom predicate function.
§Examples
// Find functions longer than 50 lines
let results = graph.query()
.node_type(NodeType::Function)
.custom(|node| {
if let (Some(start), Some(end)) = (
node.properties.get_int("line_start"),
node.properties.get_int("line_end")
) {
(end - start) > 50
} else {
false
}
})
.execute()?;Auto Trait Implementations§
impl<'a> Freeze for QueryBuilder<'a>
impl<'a> !RefUnwindSafe for QueryBuilder<'a>
impl<'a> !Send for QueryBuilder<'a>
impl<'a> !Sync for QueryBuilder<'a>
impl<'a> Unpin for QueryBuilder<'a>
impl<'a> !UnwindSafe for QueryBuilder<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more