fn index(
    path: web::Path<String>,
    db: web::Data<Pool<SqliteConnectionManager>>,
) -> impl Future<Item = HttpResponse, Error = Error> {
    // execute sync code in threadpool
    web::block(move || {
        let conn = db.get().unwrap();

        let uuid = format!("{}", uuid::Uuid::new_v4());
        conn.execute(
            "INSERT INTO users (id, name) VALUES ($1, $2)",
            &[&uuid, &path.into_inner()],
        )
        .unwrap();

        conn.query_row("SELECT name FROM users WHERE id=$1", &[&uuid], |row| {
            row.get::<_, String>(0)
        })
    })
    .then(|res| match res {
        Ok(user) => Ok(HttpResponse::Ok().json(user)),
        Err(_) => Ok(HttpResponse::InternalServerError().into()),
    })
}
/// Async request handler. Ddb pool is stored in application state.
Async request handler. Ddb pool is stored in application state.
Async request handler . Ddb pool is stored in application state .
fn index(
    path: web::Path<String>,
    db: web::Data<Pool<SqliteConnectionManager>>,
) -> impl Future<Item = HttpResponse, Error = Error> {
    // execute sync code in threadpool
    web::block(move || {
        let conn = db.get().unwrap();
        let uuid = format!("{}", uuid::Uuid::new_v4());
        conn.execute(
            "INSERT INTO users (id, name) VALUES ($1, $2)",
            &[&uuid, &path.into_inner()],
        )
        .unwrap();
        conn.query_row("SELECT name FROM users WHERE id=$1", &[&uuid], |row| {
            row.get::<_, String>(0)
        })
    })
    .then(|res| match res {
        Ok(user) => Ok(HttpResponse::Ok().json(user)),
        Err(_) => Ok(HttpResponse::InternalServerError().into()),
    })
}
fn index ( path : web :: Path < String > , db : web :: Data < Pool < SqliteConnectionManager > > , ) -> impl Future < Item = HttpResponse , Error = Error > { // execute sync code in threadpool web :: block ( move | | { let conn = db . get ( ) . unwrap ( ) ; let uuid = format ! ( " " uuid Uuid new_v4 ( ) ) ; conn . execute ( " " , & [ & uuid , & path . into_inner ( ) ] , ) . unwrap ( ) ; conn . query_row ( " " , & [ & uuid ] , | row | { row . get :: < _ , String > ( 0 ) } ) } ) . then ( | res | match res { Ok ( user ) => Ok ( HttpResponse :: Ok ( ) . json ( user ) ) , Err ( _ ) => Ok ( HttpResponse :: InternalServerError ( ) . into ( ) ) , } ) }
Async request handler.
Async request handler .
path
web::Path<String>
db
web::Data<Pool<SqliteConnectionManager>>