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:
parent
52ba8ea777
commit
2bc48c18c8
@ -49,14 +49,15 @@ 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 conn = pool.get().expect("couldn't get db connection from pool");
|
let user = web::block(move || {
|
||||||
|
let conn = pool.get().expect("couldn't get db connection from pool");
|
||||||
let user = web::block(move || actions::insert_new_user(&conn, &user))
|
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))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user