sqlx 1:n dependencies

This commit is contained in:
Peter Schiwy
2024-06-03 01:53:23 +02:00
parent bab592edf1
commit 6e6918e8ee
11 changed files with 114 additions and 59 deletions

View File

@@ -1,5 +1,6 @@
pub mod hersteller;
pub mod modell;
pub mod modell_temp;
pub mod typ;
use async_graphql::MergedObject;
@@ -8,5 +9,6 @@ use async_graphql::MergedObject;
pub struct Query(
typ::TypQuery,
modell::ModellQuery,
modell_temp::ModellTempQuery,
hersteller::HerstellerQuery,
);

View File

@@ -0,0 +1,22 @@
use async_graphql::{Context, FieldResult, Object};
use sqlx::postgres::PgPool;
use crate::models::modell_temp::ModellTemp;
#[derive(Default)]
pub struct ModellTempQuery {}
#[Object(extends)]
impl ModellTempQuery {
// async fn modelle<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<Vec<ModellTemp>> {
// let pool = ctx.data::<PgPool>()?;
// let rows = ModellTemp::read_all(pool).await?;
// Ok(rows)
// }
async fn modell_temp<'a>(&self, ctx: &'a Context<'_>, id: i32) -> FieldResult<ModellTemp> {
let pool = ctx.data::<PgPool>()?;
let row = ModellTemp::read_one(pool, &id).await?;
Ok(row)
}
}