1
0
mirror of https://github.com/actix/examples synced 2025-06-28 09:50:36 +02:00

Update db/basic, db/sqlx_todo and db/r2d2 to v4 (#506)

This commit is contained in:
Luca Palmieri
2022-01-29 16:25:46 +00:00
committed by GitHub
parent 6e3ae0fd19
commit 8b5de155bd
11 changed files with 225 additions and 165 deletions

View File

@ -2,14 +2,14 @@
name = "r2d2-example"
version = "1.0.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
edition = "2018"
edition = "2021"
[dependencies]
actix-web = "3"
actix-web = "4.0.0-beta.21"
env_logger = "0.8"
uuid = { version = "0.8", features = ["v4"] }
env_logger = "0.9.0"
uuid = { version = "1.0.0-alpha.1", features = ["v4"] }
r2d2 = "0.8"
r2d2_sqlite = "0.14"
rusqlite = "0.21"
r2d2_sqlite = "0.18.0"
rusqlite = "0.25.4"

View File

@ -1,7 +1,10 @@
//! Actix web r2d2 example
use std::io;
use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer};
use actix_web::{
error::InternalError, http::StatusCode, middleware, web, App, Error, HttpResponse,
HttpServer,
};
use r2d2::Pool;
use r2d2_sqlite::SqliteConnectionManager;
@ -26,8 +29,9 @@ async fn index(
})
})
.await
.unwrap()
.map(|user| HttpResponse::Ok().json(user))
.map_err(|_| HttpResponse::InternalServerError())?;
.map_err(|e| InternalError::new(e, StatusCode::INTERNAL_SERVER_ERROR))?;
Ok(res)
}
@ -43,7 +47,7 @@ async fn main() -> io::Result<()> {
// start http server
HttpServer::new(move || {
App::new()
.data(pool.clone()) // <- store db pool in app state
.app_data(web::Data::new(pool.clone())) // <- store db pool in app state
.wrap(middleware::Logger::default())
.route("/{name}", web::get().to(index))
})