use crate::error::Error; use axum::extract::Path; use axum::extract::State; use axum::Json; use serde::Deserialize; use serde::Serialize; use surrealdb::engine::remote::ws::Client; use surrealdb::Surreal; const PERSON: &str = "person"; type Db = State>; #[derive(Serialize, Deserialize)] pub struct Person { name: String, } pub async fn create( db: Db, id: Path, Json(person): Json, ) -> Result>, Error> { let person = db.create((PERSON, &*id)).content(person).await?; Ok(Json(person)) } pub async fn read(db: Db, id: Path) -> Result>, Error> { let person = db.select((PERSON, &*id)).await?; Ok(Json(person)) } pub async fn update( db: Db, id: Path, Json(person): Json, ) -> Result>, Error> { let person = db.update((PERSON, &*id)).content(person).await?; Ok(Json(person)) } pub async fn delete(db: Db, id: Path) -> Result>, Error> { let person = db.delete((PERSON, &*id)).await?; Ok(Json(person)) } pub async fn list(db: Db) -> Result>, Error> { let people = db.select(PERSON).await?; Ok(Json(people)) }