MCPcopy Create free account
hub / github.com/actix/examples / execute

Function execute

databases/sqlite/src/db.rs:25–45  ·  view source on GitHub ↗
(pool: &Pool, query: Queries)

Source from the content-addressed store, hash-verified

23}
24
25pub 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
47fn get_hottest_years(conn: Connection) -> WeatherAggResult {
48 let stmt = conn.prepare(

Callers

nothing calls this directly

Calls 6

sleepFunction · 0.85
get_hottest_yearsFunction · 0.85
get_coldest_yearsFunction · 0.85
get_hottest_monthsFunction · 0.85
get_coldest_monthsFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected