Queries
Queries are about requesting and retrieving data without affecting the system's state. They don't interact with the domain. Queries are read-only operations and are used to fetch data for the application's read model. The update of the read model is handled by the commands.
- Data-Focused: Queries are solely concerned with data retrieval.
- Side-Effect-Free: They do not alter the state of the system.
- Read-Oriented: Queries interact with the read model of the application.
Creating Queries
application/src/query.rs
#[derive(Deserialize)]
pub struct GetTodoListQuery {}
Implementing Queries
Queries are usually implemented to interact with the read model, fetching data as per the application's requirements.
application/src/query.rs
#[async_trait]
impl<R> Execute<R> for GetTodoListQuery
where
R: TodoListRepository + Send + Sync,
{
type Output = TodoListProjection;
async fn execute(&self, runtime: &R) -> AnyResult<TodoListProjection> {
runtime.fetch().await
}
}