1
0
mirror of https://github.com/actix/actix-website synced 2024-12-18 01:43:59 +01:00

fix(ex-database): place pool get in web::block (#290)

This commit is contained in:
Raphael C 2022-10-07 19:12:51 +02:00 committed by GitHub
parent 52ba8ea777
commit 2bc48c18c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,13 +49,14 @@ async fn main() -> io::Result<()> {
async fn index(pool: web::Data<DbPool>, name: web::Path<(String)>) -> impl Responder { async fn index(pool: web::Data<DbPool>, name: web::Path<(String)>) -> impl Responder {
let name = name.into_inner(); let name = name.into_inner();
let user = web::block(move || {
let conn = pool.get().expect("couldn't get db connection from pool"); let conn = pool.get().expect("couldn't get db connection from pool");
actions::insert_new_user(&conn, &user)
let user = web::block(move || actions::insert_new_user(&conn, &user))
.await .await
.map_err(|e| { .map_err(|e| {
eprintln!("{}", e); eprintln!("{}", e);
HttpResponse::InternalServerError().finish() HttpResponse::InternalServerError().finish()
}
})?; })?;
Ok(HttpResponse::Ok().json(user)) Ok(HttpResponse::Ok().json(user))