Skip to main content

QueryBuilder

Struct QueryBuilder 

Source
pub struct QueryBuilder { /* private fields */ }
Expand description

Fluent builder that compiles a chain of operator method calls into a QueryPlan.

§Composition rules

  1. The first step appended must be context-free. Self::scan, Self::scan_with, Self::scan_all, Self::union, Self::intersect, and Self::difference all satisfy that contract; calling Self::filter or Self::traverse on an empty builder produces a BuildError::FirstStepNotContextFree at Self::build time.
  2. Self::union, Self::intersect, and Self::difference take an arbitrary QueryPlan as 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.
  3. Self::traverse normalises its EdgeKind argument so that the plan hash is independent of metadata the executor ignores (see normalize_edge_kind).
  4. Self::build always wraps the accumulated steps in a PlanNode::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 resulting Chain.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

Source

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.

Source

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

Source

pub fn scan_with(self, filters: ScanFilters) -> Self

Appends a PlanNode::NodeScan with the given filter combination.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_empty(&self) -> bool

Returns true if the builder has no steps yet.

Source

pub fn build(self) -> Result<QueryPlan, BuildError>

Materialises the accumulated steps into a QueryPlan.

§Validation
  1. The builder must contain at least one step (BuildError::EmptyBuilder).
  2. The first step must be context-free (BuildError::FirstStepNotContextFree).
  3. No PlanNode::EdgeTraversal step may have max_depth = 0 (BuildError::ZeroDepth). This is checked recursively through PlanNode::SetOp and PlanNode::Chain payloads, so a malformed sub-plan supplied to Self::union is also caught.
  4. Any PlanNode::SetOp node added by Self::union / Self::intersect / Self::difference must 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

Source§

fn clone(&self) -> QueryBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QueryBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for QueryBuilder

Source§

fn default() -> QueryBuilder

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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