Files
axum-async-graphql/src/queries/typ.rs

23 lines
591 B
Rust
Raw Normal View History

2024-05-31 00:32:51 +02:00
use async_graphql::{Context, FieldResult, Object};
use sqlx::postgres::PgPool;
use crate::{models::typ::Typ, scalar::Id};
2024-05-31 00:32:51 +02:00
#[derive(Default)]
2024-06-07 14:40:44 +02:00
pub struct TypQuery {}
2024-05-31 00:32:51 +02:00
#[Object(extends)]
impl TypQuery {
async fn typen<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<Vec<Typ>> {
let pool = ctx.data::<PgPool>()?;
let rows = Typ::read_all(pool).await?;
Ok(rows)
}
async fn typ<'a>(&self, ctx: &'a Context<'_>, id: Id) -> FieldResult<Typ> {
2024-05-31 00:32:51 +02:00
let pool = ctx.data::<PgPool>()?;
let row = Typ::read_one(pool, &id).await?;
Ok(row)
}
}