Module query

Module query 

Source
Expand description

Query engine for graph traversal and filtering.

This module provides a fluent API for building and executing graph queries. It supports common graph traversal patterns, filtering, aggregation, and path finding operations.

§Query Building

The QueryBuilder provides a fluent interface for constructing complex graph traversals. Queries are built by chaining operations and executed lazily when results are requested.

§Path Finding

The PathFinder implements graph algorithms for finding paths between nodes, including shortest path calculations using breadth-first search.

§Example

use graph_d::{Graph, query::QueryBuilder};
use serde_json::json;
use std::collections::HashMap;

let mut graph = Graph::new()?;

// Create nodes
let alice_id = graph.create_node([
    ("name".to_string(), json!("Alice")),
    ("age".to_string(), json!(30))
].into())?;

let bob_id = graph.create_node([
    ("name".to_string(), json!("Bob")),
    ("age".to_string(), json!(25))
].into())?;

// Create relationship
graph.create_relationship(alice_id, bob_id, "KNOWS".to_string(), HashMap::new())?;

// Query: Find all people Alice knows who are under 30
let young_friends = QueryBuilder::from_node(&graph, alice_id)
    .outgoing("KNOWS")?
    .filter_by_property("age", &json!(25))?
    .nodes()?;

assert_eq!(young_friends.len(), 1);
assert_eq!(young_friends[0].id, bob_id);

Re-exports§

pub use aggregation::AggregateFunction;
pub use aggregation::AggregateResult;
pub use aggregation::Aggregator;
pub use aggregation::Statistics;
pub use aggregation::StatisticsResult;
pub use sorting::AdvancedSorter;
pub use sorting::Pagination;
pub use sorting::SortCriteria;
pub use sorting::SortDirection;
pub use sorting::SortedPage;
pub use sorting::Sorter;

Modules§

aggregation
Aggregation operations for graph queries.
sorting
Sorting operations for graph query results.

Structs§

PathFinder
Path finding algorithms for graph connectivity analysis.
QueryBuilder
A fluent query builder for graph traversals.