-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstate.rs
More file actions
30 lines (27 loc) · 787 Bytes
/
state.rs
File metadata and controls
30 lines (27 loc) · 787 Bytes
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
use crate::config::AppConfig;
use reqwest::Client;
use sqlx::SqlitePool;
use std::sync::Arc;
#[derive(Clone)]
pub struct AppState {
pub config: Arc<AppConfig>,
pub client: Client,
pub db_pool: Option<Arc<SqlitePool>>,
}
impl AppState {
pub async fn new(config: AppConfig) -> Self {
// Get the pool, convert Result to Option, then wrap in Arc
let db_pool = match crate::database::init_db().await {
Ok(pool) => Some(Arc::new(pool)),
Err(e) => {
eprintln!("⚠️ Failed to initialize database: {}", e);
None
}
};
Self {
config: Arc::new(config),
client: Client::new(),
db_pool, // Now it's Option<Arc<SqlitePool>>
}
}
}