Files
vmall/apps/api/src/state.rs
T
Chengdong ZhangandCursor 5e866d08f4 refactor(api): split Axum handlers into handler/service/repo modules
Keep the REST contract; move domain logic out of route files so checkout, fulfillment, and identity can be reused across customer, shop, and admin surfaces.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-18 14:59:36 +08:00

21 lines
698 B
Rust

use sqlx::PgPool;
#[derive(Clone)]
pub struct AppState {
pub db: PgPool,
pub redis: redis::aio::ConnectionManager,
pub config: crate::config::Config,
}
pub async fn build_state(config: &crate::config::Config) -> anyhow::Result<AppState> {
let db = PgPool::connect(&config.database_url).await?;
assemble(config.clone(), db).await
}
/// Build state from an already-open pool (migrate + serve share one pool).
pub async fn assemble(config: crate::config::Config, db: PgPool) -> anyhow::Result<AppState> {
let client = redis::Client::open(config.redis_url.clone())?;
let redis = redis::aio::ConnectionManager::new(client).await?;
Ok(AppState { db, redis, config })
}