QueryBuilder

Struct QueryBuilder 

Source
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>

Source

pub fn new(graph: &'a CodeGraph) -> Self

Create a new query builder for the given graph.

Source

pub fn node_type(self, node_type: NodeType) -> Self

Filter nodes by type.

§Examples
let functions = graph.query()
    .node_type(NodeType::Function)
    .execute()?;
Source

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.

Source

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 recursively
  • tests/**/*.rs - All Rust files under tests/
Source

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.

Source

pub fn property_exists(self, key: &str) -> Self

Filter nodes that have a specific property (regardless of value).

Source

pub fn name_contains(self, substring: &str) -> Self

Filter nodes by name containing a substring (case-insensitive).

Source

pub fn name_matches(self, pattern: &str) -> Self

Filter nodes by name matching a regex pattern.

Source

pub fn custom<F>(self, predicate: F) -> Self
where F: Fn(&Node) -> bool + 'static,

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()?;
Source

pub fn limit(self, n: usize) -> Self

Limit the number of results returned.

Source

pub fn execute(&self) -> Result<Vec<NodeId>>

Execute the query and return matching node IDs.

Source

pub fn count(&self) -> Result<usize>

Count the number of matching nodes without allocating a result vector.

Source

pub fn exists(&self) -> Result<bool>

Check if any nodes match the query (short-circuits on first match).

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> 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, 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, 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.