First Commit

This commit is contained in:
Peter Schiwy
2024-05-31 00:32:51 +02:00
commit bab592edf1
23 changed files with 3268 additions and 0 deletions

35
src/queries/hersteller.rs Normal file
View 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)
}
}