use std::fmt::Debug; use axum::extract::FromRef; use sqlx::PgPool; use crate::Error; #[derive(Debug, Clone, FromRef)] pub struct AppState { pub pool: PgPool, } impl AppState { pub async fn new(uri: String) -> Result { tracing::debug!("Attempting to connect to database..."); let pool = sqlx::postgres::PgPoolOptions::new() .max_connections(10) .connect(&uri) .await?; tracing::info!("Connected to database: {uri}"); sqlx::migrate!().run(&pool).await?; Ok(Self { pool }) } }