25 lines
596 B
Rust
25 lines
596 B
Rust
|
|
use async_graphql::{Context, FieldResult, Object};
|
||
|
|
use sqlx::postgres::PgPool;
|
||
|
|
|
||
|
|
use crate::models::typ::Typ;
|
||
|
|
|
||
|
|
#[derive(Default)]
|
||
|
|
pub struct TypQuery {
|
||
|
|
pub id: i32,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[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: i32) -> FieldResult<Typ> {
|
||
|
|
let pool = ctx.data::<PgPool>()?;
|
||
|
|
let row = Typ::read_one(pool, &id).await?;
|
||
|
|
Ok(row)
|
||
|
|
}
|
||
|
|
}
|