stately_arrow/state.rs
1//! Application state for stately-arrow API handlers.
2
3use datafusion::prelude::SessionContext;
4
5use crate::{QueryContext, QuerySession};
6
7/// State required by the API handlers.
8///
9/// Wraps a [`QueryContext`] and can be extracted from your application state
10/// using axum's `FromRef` pattern.
11///
12/// # Example
13///
14/// ```rust,ignore
15/// use axum::extract::FromRef;
16/// use stately_arrow::{QueryContext, QuerySession, QueryState};
17///
18/// #[derive(Clone)]
19/// pub struct AppState {
20/// pub query_context: QueryContext<MySession>,
21/// pub other_field: String,
22/// }
23///
24/// impl FromRef<AppState> for QueryState<MySession> {
25/// fn from_ref(state: &AppState) -> Self {
26/// Self::new(state.query_context.clone())
27/// }
28/// }
29/// ```
30#[derive(Clone)]
31pub struct QueryState<S = SessionContext>
32where
33 S: QuerySession,
34{
35 /// The query context containing session and registry.
36 pub query_context: QueryContext<S>,
37}
38
39impl<S> QueryState<S>
40where
41 S: QuerySession,
42{
43 /// Create a new `QueryState` from a `QueryContext`.
44 pub fn new(query_context: QueryContext<S>) -> Self { Self { query_context } }
45}