Skip to main content

Query

Struct Query 

Source
pub struct Query<'a> { /* private fields */ }
Expand description

Declarative agent-facing query over a ReadonlyRepo.

Usage:

let hits = Query::new(repo)
    .label("Person")
    .where_prop("name", PropPredicate::Eq(Ipld::String("Alice".into())))
    .with_outgoing("knows")
    .limit(10)
    .execute()?;

Implementations§

Source§

impl<'a> Query<'a>

Source

pub const DEFAULT_ADJACENCY_CAP: usize = 10_000

Default per-hit cap on how many edges (in each direction) are surfaced from the adjacency index. Protects agent-facing callers from fan-in/out denial-of-service (a “celebrity” node with 1M incoming edges would otherwise allocate a 1M-entry Vec per hit). Override via Self::adjacency_cap.

The default is intentionally generous (10_000) so normal knowledge graphs are never clipped; the cap is a safety valve, not a performance knob. Callers that legitimately need the full fan-in should raise it explicitly and consume the result stream.

Source

pub const fn new(repo: &'a ReadonlyRepo) -> Self

Start a new query against repo.

Source

pub fn label(self, label: impl Into<String>) -> Self

Restrict matches to nodes of a specific label (ntype).

Source

pub fn where_prop(self, name: impl Into<String>, pred: PropPredicate) -> Self

Add a property predicate. If a label is also set, the indexed (label, prop_name) -> value Prolly lookup is used (O(log n)); otherwise the query falls back to a full label scan.

Source

pub fn where_eq(self, name: impl Into<String>, value: impl Into<Ipld>) -> Self

Convenience: where_prop(name, PropPredicate::Eq(value.into())). The most common agent query shape, one call shorter.

Source

pub fn with_outgoing(self, edge_label: impl Into<String>) -> Self

Include outgoing edges of these labels in every hit.

Source

pub fn with_incoming(self, edge_label: impl Into<String>) -> Self

Include incoming edges of these labels in every hit. Symmetric mirror of Self::with_outgoing: answers “who points at me through this edge-type?” using the incoming Prolly tree in O(log n) plus one bucket read per hit.

Populates QueryHit::incoming_edges. When combined with with_outgoing in the same query, a hit is kept if it matches the base predicates regardless of direction, and each direction’s edges are surfaced in its own field.

Source

pub fn with_any_direction(self, edge_label: impl Into<String>) -> Self

Convenience: ask for this edge-type in BOTH directions. Saves the caller from writing with_outgoing(x).with_incoming(x) every time.

Self-loops (edges where src == dst) appear in edges only, not duplicated into incoming_edges. The execute path detects the self-loop case and deduplicates on EdgeId.

Source

pub const fn adjacency_cap(self, cap: usize) -> Self

Override the per-hit adjacency cap. See Self::DEFAULT_ADJACENCY_CAP for the rationale.

Source

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

Cap the result set.

Source

pub fn first(self) -> Result<Option<QueryHit>, Error>

Convenience: execute and return the first hit, or Ok(None) if the result set is empty. Sets limit(1) internally.

§Errors

Same as Self::execute.

Source

pub fn one(self) -> Result<QueryHit, Error>

Convenience: execute and return the exactly-one hit, erroring if the result set is empty or has more than one match. Useful when the agent treats a resolve as a precondition.

Internally sets limit(2) so a genuine second hit is detected cheaply.

§Errors
Source

pub fn execute(self) -> Result<Vec<QueryHit>, Error>

Execute the query against the repo’s current commit.

Dispatches to the fastest matching path:

  • label + prop_eq with an IndexSet present: one Prolly point lookup
  • label-only with an IndexSet: label sub-tree cursor, bounded by limit
  • otherwise: streaming scan of commit.nodes with in-memory filter, also bounded by limit
§Errors

Trait Implementations§

Source§

impl<'a> Clone for Query<'a>

Source§

fn clone(&self) -> Query<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Query<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Query<'a>

§

impl<'a> !RefUnwindSafe for Query<'a>

§

impl<'a> Send for Query<'a>

§

impl<'a> Sync for Query<'a>

§

impl<'a> Unpin for Query<'a>

§

impl<'a> UnsafeUnpin for Query<'a>

§

impl<'a> !UnwindSafe for Query<'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> 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> 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