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

upgrade diesel, r2d2, state examples

This commit is contained in:
Nikolay Kim
2019-03-07 14:50:29 -08:00
parent 60a9df8abd
commit f39a53ea3a
10 changed files with 185 additions and 282 deletions

View File

@ -1,10 +1,7 @@
//! Actix web r2d2 example
use std::io;
use actix_web::{
blocking, extract::Path, middleware, web, App, Error, HttpResponse, HttpServer,
State,
};
use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer};
use futures::Future;
use r2d2::Pool;
use r2d2_sqlite::SqliteConnectionManager;
@ -12,11 +9,11 @@ use uuid;
/// Async request handler. Ddb pool is stored in application state.
fn index(
path: Path<String>,
db: State<Pool<SqliteConnectionManager>>,
path: web::Path<String>,
db: web::State<Pool<SqliteConnectionManager>>,
) -> impl Future<Item = HttpResponse, Error = Error> {
// execute sync code in threadpool
blocking::run(move || {
web::block(move || {
let conn = db.get().unwrap();
let uuid = format!("{}", uuid::Uuid::new_v4());