First Commit
This commit is contained in:
35
src/queries/hersteller.rs
Normal file
35
src/queries/hersteller.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use async_graphql::{Context, FieldResult, Object};
|
||||
use sqlx::postgres::PgPool;
|
||||
|
||||
use crate::models::hersteller::Hersteller;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct HerstellerQuery {
|
||||
pub id: i32,
|
||||
}
|
||||
|
||||
#[Object(extends)]
|
||||
impl HerstellerQuery {
|
||||
// #[graphql(external)]
|
||||
// async fn id(&self) -> &i32 {
|
||||
// &self.id
|
||||
// }
|
||||
|
||||
// async fn modell<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<Vec<Modell>> {
|
||||
// let pool = ctx.data::<PgPool>().unwrap();
|
||||
// let rows = Modell::read_by_typ(pool, &self.id).await?;
|
||||
// Ok(rows)
|
||||
// }
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user