diff --git a/examples/rocket_example/src/sqlx/mod.rs b/examples/rocket_example/src/sqlx/mod.rs index 39f11241..fe089ba4 100644 --- a/examples/rocket_example/src/sqlx/mod.rs +++ b/examples/rocket_example/src/sqlx/mod.rs @@ -61,26 +61,16 @@ async fn list(mut con: Connection) -> Result>> { } #[get("/")] -async fn read(mut db: Connection, id: i64) -> Option> { - // let post: Option = Post::find_by_id(id) - // .one(db) - // .await - // .expect("could not find baker"); - // println!("post: {:#?}", post); +async fn read(mut con: Connection, id: i64) -> Option> { + let post: Option = Post::find_by_id(id) + .one(&con) + .await + .expect("could not find post"); - // sqlx::query!("SELECT id, title, text FROM posts WHERE id = ?", id) - // .fetch_one(&mut *db) - // .map_ok(|r| { - // Json(Post { - // id: Some(r.id), - // title: r.title, - // text: r.text, - // }) - // }) - // .await - // .ok() - - None + match post { + None => None, + Some(post) => Some(Json(post)), + } } // #[delete("/")]