#[query]Expand description
Marks a function as a query (read-only, cacheable, subscribable).
Queries can only read from the database and are automatically cached. They can be subscribed to for real-time updates.
§Attributes
cache = "5m"- Cache TTL (duration like “30s”, “5m”, “1h”)public- No authentication requiredrequire_auth- Require authenticationtimeout = 30- Timeout in seconds
§Example
ⓘ
#[forge::query]
pub async fn get_user(ctx: &QueryContext, user_id: Uuid) -> Result<User> {
ctx.db().query::<User>().filter(|u| u.id == user_id).fetch_one().await
}
#[forge::query(cache = "5m", require_auth)]
pub async fn get_profile(ctx: &QueryContext) -> Result<Profile> {
let user_id = ctx.require_user_id()?;
// ...
}