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

23 lines
651 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::hersteller::Hersteller;
#[derive(Default)]
2024-06-07 14:40:44 +02:00
pub struct HerstellerQuery {}
2024-05-31 00:32:51 +02:00
#[Object(extends)]
impl HerstellerQuery {
async fn hersteller<'a>(&self, ctx: &'a Context<'_>, id: i32) -> FieldResult<Hersteller> {
let pool = ctx.data::<PgPool>()?;
let row = Hersteller::read_one(pool, &id).await?;
Ok(row)
}
2024-06-07 14:40:44 +02:00
async fn alle_hersteller<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<Vec<Hersteller>> {
let pool = ctx.data::<PgPool>()?;
let rows = Hersteller::read_all(pool).await?;
Ok(rows)
}
2024-05-31 00:32:51 +02:00
}