Struct persist_es::GenericQuery [−][src]
pub struct GenericQuery<R, V, A> where
R: ViewRepository<V, A>,
V: View<A>,
A: Aggregate, { /* fields omitted */ }
Expand description
A simple query and view repository. This is used both to act as a Query
for processing events
and to return materialized views.
Implementations
Creates a new GenericQuery
using the provided ViewRepository
.
let repo: MyRepo = ...
let query = GenericQuery::<MyRepo, MyView, MyAggregate>::new(repo);
let store = ...
let cqrs = CqrsFramework::new(store, vec![Box::new(query)]);
pub fn use_error_handler(
&mut self,
error_handler: Box<dyn Fn(PersistenceError) + Send + Sync + 'static>
)
pub fn use_error_handler(
&mut self,
error_handler: Box<dyn Fn(PersistenceError) + Send + Sync + 'static>
)
Allows the user to apply a custom error handler to the query. Queries are infallible and should never cause errors, but programming errors or other technical problems might. Adding an error handler allows the user to choose whether to panic the application, log the error or otherwise register the issue.
This is not required for usage but without an error handler any error encountered by the query repository will simply be ignored, so it is strongly recommended.
An error handler that panics on any error.
query.use_error_handler(Box::new(|e|panic!("{}",e)));
Loads and deserializes a view based on the provided view id. Use this method to load a materialized view when requested by a user.
This is an asynchronous method so don’t forget to await
.
let view = query.load("customer-B24DA0".to_string()).await;
Trait Implementations
impl<R, V, A> Query<A> for GenericQuery<R, V, A> where
R: ViewRepository<V, A>,
V: View<A>,
A: Aggregate,
impl<R, V, A> Query<A> for GenericQuery<R, V, A> where
R: ViewRepository<V, A>,
V: View<A>,
A: Aggregate,
Events will be dispatched here immediately after being committed for the downstream queries to be updated. Read more