Skip to main content

QueryEffects

Trait QueryEffects 

Source
pub trait QueryEffects: Send + Sync {
    // Required methods
    fn query<'life0, 'life1, 'async_trait, Q>(
        &'life0 self,
        query: &'life1 Q,
    ) -> Pin<Box<dyn Future<Output = Result<<Q as Query>::Result, QueryError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Q: 'async_trait + Query,
             Self: 'async_trait;
    fn query_raw<'life0, 'life1, 'async_trait>(
        &'life0 self,
        program: &'life1 DatalogProgram,
    ) -> Pin<Box<dyn Future<Output = Result<DatalogBindings, QueryError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn subscribe<Q>(&self, query: &Q) -> QuerySubscription<<Q as Query>::Result>
       where Q: Query;
    fn check_capabilities<'life0, 'life1, 'async_trait>(
        &'life0 self,
        capabilities: &'life1 [QueryCapability],
    ) -> Pin<Box<dyn Future<Output = Result<(), QueryError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn invalidate<'life0, 'life1, 'async_trait>(
        &'life0 self,
        predicate: &'life1 FactPredicate,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn query_with_isolation<'life0, 'life1, 'async_trait, Q>(
        &'life0 self,
        query: &'life1 Q,
        isolation: QueryIsolation,
    ) -> Pin<Box<dyn Future<Output = Result<<Q as Query>::Result, QueryError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Q: 'async_trait + Query,
             Self: 'async_trait;
    fn query_with_stats<'life0, 'life1, 'async_trait, Q>(
        &'life0 self,
        query: &'life1 Q,
    ) -> Pin<Box<dyn Future<Output = Result<(<Q as Query>::Result, QueryStats), QueryError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Q: 'async_trait + Query,
             Self: 'async_trait;
    fn query_with_consistency<'life0, 'life1, 'async_trait, Q>(
        &'life0 self,
        query: &'life1 Q,
    ) -> Pin<Box<dyn Future<Output = Result<(<Q as Query>::Result, ConsistencyMap), QueryError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Q: 'async_trait + Query,
             Self: 'async_trait;
    fn query_full<'life0, 'life1, 'async_trait, Q>(
        &'life0 self,
        query: &'life1 Q,
        isolation: QueryIsolation,
    ) -> Pin<Box<dyn Future<Output = Result<(<Q as Query>::Result, QueryStats), QueryError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Q: 'async_trait + Query,
             Self: 'async_trait;
    fn register_query_binding<'life0, 'life1, 'async_trait, Q>(
        &'life0 self,
        signal: &'life1 Signal<<Q as Query>::Result>,
        query: Q,
    ) -> Pin<Box<dyn Future<Output = Result<(), QueryError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Q: 'async_trait + Query,
             Self: 'async_trait;
}
Expand description

Effects for executing typed Datalog queries.

This trait provides the read interface to the journal through Datalog queries. All queries:

  1. Compile to Datalog programs via Query::to_datalog()
  2. Are authorized via Biscuit capabilities
  3. Execute against journal facts
  4. Parse results to typed values

§Example

use aura_core::effects::QueryEffects;
use aura_app::queries::ChannelsQuery;

// One-shot query
let channels = handler.query(&ChannelsQuery::default()).await?;

// Live subscription (re-evaluates when facts change)
let mut stream = handler.subscribe(&ChannelsQuery::default());
while let Some(channels) = stream.recv().await {
    println!("Channels updated: {} total", channels.len());
}

Required Methods§

Source

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

Execute a one-shot query.

This compiles the query to Datalog, checks authorization, executes against the journal, and parses the results.

§Errors
  • QueryError::AuthorizationFailed if capability check fails
  • QueryError::ExecutionError if Datalog execution fails
  • QueryError::ParseError if result parsing fails
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 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Execute a raw Datalog program and return bindings.

Lower-level API for executing arbitrary Datalog without typed parsing. Useful for debugging or dynamic queries.

Source

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

Subscribe to a query for live updates.

Returns a stream that re-evaluates the query whenever facts matching the query’s dependencies() change.

The stream yields new results after each relevant fact change.

Source

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

Check if a query’s capabilities are satisfied.

Can be used to pre-check authorization before execution.

Source

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

Invalidate cached results for queries matching the given predicate.

Called when facts change to trigger re-evaluation of subscriptions.

Source

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

Execute a query with a specific isolation level.

Allows specifying consistency requirements for the query. See QueryIsolation for available levels.

§Example
// Wait for specific consensus before querying
let result = handler.query_with_isolation(
    &ChannelsQuery::default(),
    QueryIsolation::ReadCommitted { wait_for: vec![consensus_id] },
).await?;
Source

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

Execute a query and return results with execution statistics.

Useful for debugging, profiling, and optimization. Returns both the query results and metadata about the execution.

§Example
let (channels, stats) = handler.query_with_stats(&ChannelsQuery::default()).await?;
println!("Query took {:?}, scanned {} facts", stats.execution_time, stats.facts_scanned);
Source

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

Execute a query and return results with consistency metadata.

Returns both the query results and a ConsistencyMap containing the consistency status (agreement, propagation, acknowledgment) for each matched fact.

§Example
let (messages, consistency) = handler.query_with_consistency(&MessagesQuery::default()).await?;
for msg in &messages {
    if consistency.is_finalized(&msg.id) {
        println!("{}: finalized", msg.content);
    } else {
        println!("{}: pending", msg.content);
    }
}
Source

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

Execute a query with both isolation level and statistics.

Combines query_with_isolation and query_with_stats.

Source

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

Register a query binding for reactive refresh.

Implementations should store the query/signal mapping and emit the initial query result.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> QueryEffects for Arc<T>
where T: QueryEffects + ?Sized,

Blanket implementation for Arc where T: QueryEffects

Source§

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

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 'life0: 'async_trait, 'life1: 'async_trait, Arc<T>: 'async_trait,

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§