summaryrefslogtreecommitdiff
path: root/src/db.rs
blob: 87686fa9e5bea29fc6253a92a63d8a6ee1fdfda9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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(|_| DATABASE_URL_FALLBACK.to_owned());
    PgPoolOptions::new()
        .max_connections(5)
        .connect(&database_url)
        .await
}