(pool: &Pool, query: Queries)
| 23 | } |
| 24 | |
| 25 | pub async fn execute(pool: &Pool, query: Queries) -> Result<Vec<WeatherAgg>, Error> { |
| 26 | let pool = pool.clone(); |
| 27 | |
| 28 | let conn = web::block(move || pool.get()) |
| 29 | .await? |
| 30 | .map_err(error::ErrorInternalServerError)?; |
| 31 | |
| 32 | web::block(move || { |
| 33 | // simulate an expensive query, see comments at top of main.rs |
| 34 | sleep(Duration::from_secs(1)); |
| 35 | |
| 36 | match query { |
| 37 | Queries::GetTopTenHottestYears => get_hottest_years(conn), |
| 38 | Queries::GetTopTenColdestYears => get_coldest_years(conn), |
| 39 | Queries::GetTopTenHottestMonths => get_hottest_months(conn), |
| 40 | Queries::GetTopTenColdestMonths => get_coldest_months(conn), |
| 41 | } |
| 42 | }) |
| 43 | .await? |
| 44 | .map_err(error::ErrorInternalServerError) |
| 45 | } |
| 46 | |
| 47 | fn get_hottest_years(conn: Connection) -> WeatherAggResult { |
| 48 | let stmt = conn.prepare( |
nothing calls this directly
no test coverage detected