aboutsummaryrefslogtreecommitdiffstats
path: root/lib/shared-svc/src/database/mod.rs
blob: bbc1ba3726ba0ad1015fe4771547e171959a75b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use sqlx::PgPool;
use tracing::{debug, error};
use url::Url;

use crate::ServiceError;

pub async fn connect(url: &Url, pool_size: u32) -> Result<PgPool, ServiceError> {
    let host = url.host_str();
    debug!(host = host, "connecting to database");

    Ok(sqlx::postgres::PgPoolOptions::new()
        .max_connections(pool_size)
        .connect(url.as_str())
        .await
        .inspect_err(|e| error!("{e}"))?)
}