1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Request-scoped context helpers for Workers routes.
//!
//! WHY: Workers passes `RouteContext<Data>` to non-DO handlers; the data
//! often includes D1 bindings. Wrapping the extraction pattern here avoids
//! repeating it in every route handler.
//!
//! WHAT: thin wrappers that extract typed bindings from the route context.
use ;
/// Run a closure with a D1 database extracted from the route data.
///
/// The route data must be a `D1Database` (set up by the Worker's `fn
/// router()` or by the `#[event(fetch)]` init path that stores the
/// env-extracted DB into the context).
///
/// # Panics
///
/// Panics if the route data is not a `D1Database`. This is a setup error —
/// the route data type is determined at compile time by the Worker's router.
/// Run an async closure with a D1 database from the route context.
///
/// Async variant for handlers that need `.await`.
pub async