blob: 21c7db4a23b5b2d3820c65ba983a661935037fec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
use sqlx::{PgPool, postgres::PgPoolOptions};
use std::env;
const DATABASE_URL_FALLBACK: &str = "postgres://health:health@127.0.0.1:5432/health";
pub async fn connect() -> Result<PgPool, sqlx::Error> {
let database_url = env::var("DATABASE_URL").unwrap_or_else(|_| {
tracing::warn!("DATABASE_URL not set, falling back to the default local database");
DATABASE_URL_FALLBACK.to_string()
});
PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
.await
}
|