Skip to main content

QueryHandler

Struct QueryHandler 

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

Production query effect handler.

Implements QueryEffects by:

  • Using AuraQuery for Datalog execution via Biscuit
  • Delegating subscription management to ReactiveHandler
  • Tracking query dependencies for invalidation
  • Optionally using IndexedJournalEffects for efficient fact lookups

§Authorization Model

Capability checks use a permissive model: queries pass if no capabilities are explicitly required OR if all required capabilities are granted. For production use with Biscuit integration, inject capabilities via grant_capability() based on the authenticated token.

§Indexed Journal Integration

When an indexed journal is provided via with_indexed_journal(), the handler:

  • Uses bloom filter pre-filtering to skip queries for non-existent predicates
  • Can load facts directly from the index for O(log n) lookups

§Query Isolation

Supports four isolation levels:

  • ReadUncommitted: Immediate query against current CRDT state
  • ReadCommitted: Wait for specific consensus IDs before querying
  • Snapshot: Query against historical state by prestate hash
  • ReadLatest: Wait for all pending consensus in a scope

Implementations§

Source§

impl QueryHandler

Source

pub fn new(reactive: Arc<ReactiveHandler>) -> Self

Create a new query handler with a reactive handler for subscriptions.

Source

pub fn new_with_policy( reactive: Arc<ReactiveHandler>, policy: CapabilityPolicy, ) -> Self

Create a new query handler with an explicit capability policy.

Source

pub fn with_indexed_journal( reactive: Arc<ReactiveHandler>, indexed_journal: Arc<dyn IndexedJournalEffects + Send + Sync>, ) -> Self

Create a query handler with indexed journal support.

When an indexed journal is provided, the handler can:

  • Load facts from the index for efficient O(log n) predicate lookups
  • Use bloom filter to quickly check if facts exist before expensive queries
Source

pub fn with_indexed_journal_with_policy( reactive: Arc<ReactiveHandler>, indexed_journal: Arc<dyn IndexedJournalEffects + Send + Sync>, policy: CapabilityPolicy, ) -> Self

Create a query handler with indexed journal support and explicit policy.

Source

pub fn with_consensus_timeout(self, timeout: Duration) -> Self

Set the consensus wait timeout.

Source

pub async fn add_fact(&self, predicate: &str, args: Vec<String>)

Add a fact to the query store.

Facts added here are available for all subsequent queries. In production, facts come from the journal via a fact stream.

Source

pub async fn add_facts(&self, entries: Vec<(String, Vec<String>)>)

Add multiple facts at once.

Source

pub async fn clear_facts(&self)

Clear all facts.

Source

pub async fn grant_capability(&self, cap: QueryCapability)

Grant a capability for subsequent queries.

In production, capabilities are typically derived from Biscuit tokens after authentication. This method allows manual capability injection for testing or scenarios where capabilities are determined externally.

Source

pub async fn set_capability_policy(&self, policy: CapabilityPolicy)

Set capability enforcement policy.

Use AllowAll in tests or offline scenarios that do not enforce Biscuit checks.

Source

pub async fn load_facts_for_predicate( &self, predicate: &str, ) -> Result<usize, QueryError>

Load facts from the indexed journal for a specific predicate.

This uses O(log n) B-tree lookup to fetch all facts matching the predicate. Facts are loaded into the local store for query execution.

Returns the number of facts loaded.

Source

pub fn might_contain_fact(&self, predicate: &str, value: &FactValue) -> bool

Check if facts with the given predicate and value might exist.

Uses the bloom filter for O(1) membership testing. Returns true if facts might exist, false if definitely not present.

This is useful for early query rejection - if returns false, the query can be skipped entirely.

Source

pub async fn register_query_binding<Q: Query>( &self, signal: &Signal<Q::Result>, query: Q, ) -> Result<(), QueryError>

Register a query binding for reactive refresh.

This stores the query and signal mapping and emits the initial query result.

Source

pub async fn mark_consensus_completed(&self, id: ConsensusId)

Mark a consensus instance as completed.

Call this when a consensus operation completes to wake up any queries waiting with ReadCommitted isolation.

Source

pub async fn register_pending_consensus( &self, scope: ResourceScope, id: ConsensusId, )

Register a pending consensus instance for a resource scope.

Call this when a new consensus operation is started to track it for ReadLatest isolation.

Source

pub async fn create_snapshot(&self, prestate_hash: Hash32)

Create a snapshot of current facts at a specific prestate hash.

Call this when a consensus operation starts to enable Snapshot isolation queries against this state.

Source

pub async fn remove_snapshot(&self, prestate_hash: Hash32)

Remove a snapshot (e.g., after garbage collection window).

Source

pub async fn has_snapshot(&self, prestate_hash: &Hash32) -> bool

Check if a snapshot exists for a prestate hash.

Trait Implementations§

Source§

impl Clone for QueryHandler

Source§

fn clone(&self) -> Self

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 Default for QueryHandler

Source§

fn default() -> Self

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

impl QueryEffects for QueryHandler

Source§

fn query<'life0, 'life1, 'async_trait, Q>( &'life0 self, query: &'life1 Q, ) -> Pin<Box<dyn Future<Output = Result<Q::Result, QueryError>> + Send + 'async_trait>>
where Q: 'async_trait + Query, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute a one-shot query. Read more
Source§

fn query_raw<'life0, 'life1, 'async_trait>( &'life0 self, program: &'life1 DatalogProgram, ) -> Pin<Box<dyn Future<Output = Result<DatalogBindings, QueryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute a raw Datalog program and return bindings. Read more
Source§

fn subscribe<Q: Query>(&self, query: &Q) -> QuerySubscription<Q::Result>

Subscribe to a query for live updates. Read more
Source§

fn check_capabilities<'life0, 'life1, 'async_trait>( &'life0 self, capabilities: &'life1 [QueryCapability], ) -> Pin<Box<dyn Future<Output = Result<(), QueryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Check if a query’s capabilities are satisfied. Read more
Source§

fn invalidate<'life0, 'life1, 'async_trait>( &'life0 self, predicate: &'life1 FactPredicate, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invalidate cached results for queries matching the given predicate. Read more
Source§

fn query_with_isolation<'life0, 'life1, 'async_trait, Q>( &'life0 self, query: &'life1 Q, isolation: QueryIsolation, ) -> Pin<Box<dyn Future<Output = Result<Q::Result, QueryError>> + Send + 'async_trait>>
where Q: 'async_trait + Query, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute a query with a specific isolation level. Read more
Source§

fn query_with_stats<'life0, 'life1, 'async_trait, Q>( &'life0 self, query: &'life1 Q, ) -> Pin<Box<dyn Future<Output = Result<(Q::Result, QueryStats), QueryError>> + Send + 'async_trait>>
where Q: 'async_trait + Query, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute a query and return results with execution statistics. Read more
Source§

fn query_with_consistency<'life0, 'life1, 'async_trait, Q>( &'life0 self, query: &'life1 Q, ) -> Pin<Box<dyn Future<Output = Result<(Q::Result, ConsistencyMap), QueryError>> + Send + 'async_trait>>
where Q: 'async_trait + Query, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute a query and return results with consistency metadata. Read more
Source§

fn query_full<'life0, 'life1, 'async_trait, Q>( &'life0 self, query: &'life1 Q, isolation: QueryIsolation, ) -> Pin<Box<dyn Future<Output = Result<(Q::Result, QueryStats), QueryError>> + Send + 'async_trait>>
where Q: 'async_trait + Query, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute a query with both isolation level and statistics. Read more
Source§

fn register_query_binding<'life0, 'life1, 'async_trait, Q>( &'life0 self, signal: &'life1 Signal<Q::Result>, query: Q, ) -> Pin<Box<dyn Future<Output = Result<(), QueryError>> + Send + 'async_trait>>
where Q: 'async_trait + Query, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Register a query binding for reactive refresh. 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> 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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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