use crate::errors::AppError; use sqlx::postgres::PgPool; static mut CONNECTION: Option = None; pub async fn setup() -> Result<(), AppError> { let database_url = std::env::var("DATABASE_URL").expect("Define `DATABASE_URL` environment variable."); unsafe { CONNECTION = Some(PgPool::connect(&database_url).await?); } Ok(()) } pub unsafe fn get_client() -> &'static PgPool { match &CONNECTION { Some(client) => &client, None => panic!("Connection not established!"), } }