diff options
Diffstat (limited to 'src/state.rs')
-rw-r--r-- | src/state.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/state.rs b/src/state.rs index 22234f3..2646489 100644 --- a/src/state.rs +++ b/src/state.rs @@ -12,12 +12,23 @@ use crate::Error; #[derive(Debug, Clone)] pub struct AppState { pub pool: Pool<Postgres>, - pub jwt_secret: String, } impl AppState { - pub fn new(pool: Pool<Postgres>, jwt_secret: String) -> Self { - Self { pool, jwt_secret } + #[tracing::instrument] + pub async fn new(uri: String) -> Result<Self, Error> { + tracing::debug!("Attempting to connect to database..."); + + let pool = sqlx::postgres::PgPoolOptions::new() + .max_connections(10) + .connect(&uri) + .await?; + + tracing::info!("Connected to database"); + + sqlx::migrate!().run(&pool).await?; + + Ok(Self { pool }) } } |