pub struct QueryBuilder { /* private fields */ }Expand description
Fluent builder that compiles a chain of operator method calls into a
QueryPlan.
§Composition rules
- The first step appended must be context-free.
Self::scan,Self::scan_with,Self::scan_all,Self::union,Self::intersect, andSelf::differenceall satisfy that contract; callingSelf::filterorSelf::traverseon an empty builder produces aBuildError::FirstStepNotContextFreeatSelf::buildtime. Self::union,Self::intersect, andSelf::differencetake an arbitraryQueryPlanas the right-hand operand. The builder’s current accumulated state is folded into the left-hand operand. If the builder is empty, the right-hand operand becomes the first step.Self::traversenormalises itsEdgeKindargument so that the plan hash is independent of metadata the executor ignores (seenormalize_edge_kind).Self::buildalways wraps the accumulated steps in aPlanNode::Chain, even when only a single step is present. This keeps the plan shape uniform for the fuser and the executor; callers that want the bare step can match against the resultingChain.steps.
§Cloning
QueryBuilder is Clone so that an in-progress chain can be branched
— useful when constructing two related queries from a shared prefix:
use sqry_core::graph::unified::node::kind::NodeKind;
use sqry_db::planner::{Predicate, QueryBuilder};
let prefix = QueryBuilder::new().scan(NodeKind::Function);
let with_callers = prefix.clone().filter(Predicate::HasCaller).build();
let with_callees = prefix.filter(Predicate::HasCallee).build();
assert!(with_callers.is_ok() && with_callees.is_ok());Implementations§
Source§impl QueryBuilder
impl QueryBuilder
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Constructs an empty builder.
At least one of Self::scan, Self::scan_with, Self::scan_all,
Self::union, Self::intersect, or Self::difference must be
called before Self::build for the resulting plan to validate.
Sourcepub fn scan(self, kind: NodeKind) -> Self
pub fn scan(self, kind: NodeKind) -> Self
Appends a PlanNode::NodeScan filtered to the given NodeKind.
Equivalent to .scan_with(ScanFilters::new().with_kind(kind)).
Sourcepub fn scan_with(self, filters: ScanFilters) -> Self
pub fn scan_with(self, filters: ScanFilters) -> Self
Appends a PlanNode::NodeScan with the given filter combination.
Sourcepub fn scan_all(self) -> Self
pub fn scan_all(self) -> Self
Appends an unfiltered PlanNode::NodeScan that matches every node in
the graph.
Use sparingly — this is an expensive operation on large snapshots.
Sourcepub fn filter(self, predicate: Predicate) -> Self
pub fn filter(self, predicate: Predicate) -> Self
Appends a PlanNode::Filter step with the given predicate.
Every variant of Predicate is acceptable here, including the
boolean combinators (Predicate::And, Predicate::Or,
Predicate::Not) and value-bearing relation predicates with
PredicateValue::Subquery payloads.
Sourcepub fn filter_name(self, pattern: StringPattern) -> Self
pub fn filter_name(self, pattern: StringPattern) -> Self
Convenience wrapper that builds a Predicate::MatchesName filter
from a StringPattern and appends it as a PlanNode::Filter.
Sourcepub fn filter_in_file(self, path: impl Into<PathPattern>) -> Self
pub fn filter_in_file(self, path: impl Into<PathPattern>) -> Self
Convenience wrapper that builds a Predicate::InFile filter from a
PathPattern (or anything convertible to one) and appends it.
Sourcepub fn traverse(
self,
direction: Direction,
edge_kind: EdgeKind,
max_depth: u32,
) -> Self
pub fn traverse( self, direction: Direction, edge_kind: EdgeKind, max_depth: u32, ) -> Self
Appends a PlanNode::EdgeTraversal step.
The supplied EdgeKind is run through normalize_edge_kind so
that two builders that pick the same edge kind but supply different
per-edge metadata produce the same plan hash. See
normalize_edge_kind for the rationale.
Note that max_depth == 0 is accepted here but rejected at
Self::build time with BuildError::ZeroDepth. The builder defers
validation so that callers can compose traversals freely without
fallible intermediate steps.
Sourcepub fn traverse_any(self, direction: Direction, max_depth: u32) -> Self
pub fn traverse_any(self, direction: Direction, max_depth: u32) -> Self
Appends a PlanNode::EdgeTraversal step that matches any edge kind.
Useful for “follow any outgoing edge to depth N” queries (impact analysis, broad reachability).
Sourcepub fn union(self, other: QueryPlan) -> Self
pub fn union(self, other: QueryPlan) -> Self
Combines the builder’s current state with another plan via union.
If the builder already holds steps, they are wrapped in a
PlanNode::Chain and used as the left-hand operand. If the builder
is empty, the right-hand operand becomes the sole context-free step.
Sourcepub fn intersect(self, other: QueryPlan) -> Self
pub fn intersect(self, other: QueryPlan) -> Self
Combines the builder’s current state with another plan via intersection.
See Self::union for the composition semantics when the builder is
non-empty vs empty.
Sourcepub fn difference(self, other: QueryPlan) -> Self
pub fn difference(self, other: QueryPlan) -> Self
Combines the builder’s current state with another plan via difference.
result = self \ other. See Self::union for composition semantics.
Sourcepub fn step_count(&self) -> usize
pub fn step_count(&self) -> usize
Returns the number of steps currently accumulated in the builder.
Does not include nested operators inside PlanNode::SetOp or
PlanNode::Chain payloads — only top-level steps that
Self::build would emit.
Sourcepub fn build(self) -> Result<QueryPlan, BuildError>
pub fn build(self) -> Result<QueryPlan, BuildError>
Materialises the accumulated steps into a QueryPlan.
§Validation
- The builder must contain at least one step
(
BuildError::EmptyBuilder). - The first step must be context-free
(
BuildError::FirstStepNotContextFree). - No
PlanNode::EdgeTraversalstep may havemax_depth = 0(BuildError::ZeroDepth). This is checked recursively throughPlanNode::SetOpandPlanNode::Chainpayloads, so a malformed sub-plan supplied toSelf::unionis also caught. - Any
PlanNode::SetOpnode added bySelf::union/Self::intersect/Self::differencemust have both operands rooted at a context-free node (BuildError::InvalidSetOpOperand).
§Output shape
The returned QueryPlan’s root is always a PlanNode::Chain.
Single-step builders therefore produce a Chain { steps: vec![one] }
rather than the bare one. This keeps the plan shape uniform for
downstream fusion and execution. Callers that prefer the bare step
can match against plan.root and unwrap when Chain.steps.len() == 1.
Trait Implementations§
Source§impl Clone for QueryBuilder
impl Clone for QueryBuilder
Source§fn clone(&self) -> QueryBuilder
fn clone(&self) -> QueryBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for QueryBuilder
impl Debug for QueryBuilder
Source§impl Default for QueryBuilder
impl Default for QueryBuilder
Source§fn default() -> QueryBuilder
fn default() -> QueryBuilder
Auto Trait Implementations§
impl Freeze for QueryBuilder
impl RefUnwindSafe for QueryBuilder
impl Send for QueryBuilder
impl Sync for QueryBuilder
impl Unpin for QueryBuilder
impl UnsafeUnpin for QueryBuilder
impl UnwindSafe for QueryBuilder
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more