From 2bc48c18c88f73b11851aa70e7d7e4481417a0c1 Mon Sep 17 00:00:00 2001 From: Raphael C Date: Fri, 7 Oct 2022 19:12:51 +0200 Subject: [PATCH] fix(ex-database): place pool get in web::block (#290) --- examples/databases/src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/databases/src/main.rs b/examples/databases/src/main.rs index cbb1952..efffd29 100644 --- a/examples/databases/src/main.rs +++ b/examples/databases/src/main.rs @@ -49,14 +49,15 @@ async fn main() -> io::Result<()> { async fn index(pool: web::Data, name: web::Path<(String)>) -> impl Responder { let name = name.into_inner(); - let conn = pool.get().expect("couldn't get db connection from pool"); - - let user = web::block(move || actions::insert_new_user(&conn, &user)) + let user = web::block(move || { + let conn = pool.get().expect("couldn't get db connection from pool"); + actions::insert_new_user(&conn, &user) .await .map_err(|e| { eprintln!("{}", e); HttpResponse::InternalServerError().finish() - })?; + } + })?; Ok(HttpResponse::Ok().json(user)) }