Release 0.1.6 - 2026-09-05
After a few weeks in the heart of Bavaria, I am restored, and back at it. This release provides routes with access to the store.
Read the full change log here.
Using the Store from a Route
Let's generate a new route to display a list of customers:
$ auric generate route customers
created src/routes/customers.rs
updated src/routes/mod.rs
created src/templates/customers.hbs
==> make
Compiling my-app v0.1.0 (/Users/davidr/workspaces/drr)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.50s
Let's look at the default route that was generated, before we make any changes:
// src/routes/customers.rs
use anyhow::Result;
use auric_runtime::async_trait::async_trait;
use auric_runtime::routing::{Route, RouteModel};
use auric_runtime::{AuricRoute, Context};
use serde_json::{Value, json};
#[derive(AuricRoute, Default)]
#[route("/customers")]
pub struct CustomersRoute {}
#[async_trait]
impl Route for CustomersRoute {
fn init(&mut self, _context: &dyn Context) -> Result<()> {
Ok(())
}
async fn model(&self, _params: &[Value]) -> Result<RouteModel> {
Ok(RouteModel::Json(json!({})))
}
}
#[cfg(test)]
mod tests {
use super::CustomersRoute;
#[test]
fn can_construct() {
let _ = CustomersRoute::default();
}
}
Now let's modify the init() fn to keep our own reference to the store:
pub struct CustomersRoute {
store: Arc<Store>,
}
#[async_trait]
impl Route for CustomersRoute {
fn init(&mut self, context: &dyn Context) -> Result<()> {
self.store = context.store();
Ok(())
}
...
}
Now we can use the store when preparing the route's model:
use crate::models::customer::Customer;
#[async_trait]
impl Route for CustomersRoute {
...
async fn model(&self, _params: &[Value]) -> Result<RouteModel> {
let customers: Vec<Customer> = self.store.find_all("customer", None).await?;
...
}
}