blob: b08c38cd74bef43af268a923394d303b5ba0efa9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
use crate::errors::AppError;
use sqlx::postgres::PgPool;
static mut CONNECTION: Option<PgPool> = 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!"),
}
}
|