aboutsummaryrefslogtreecommitdiffstats
path: root/src/server/state/database.rs
blob: f8fd33208072d02af6f6d1f069e9e83e9cd6b9a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use anyhow::Result;
use sqlx::{PgPool, postgres::PgPoolOptions};
use tracing::{debug, trace};

use crate::config::DatabaseOptions;

pub(super) async fn connect(opts: &DatabaseOptions) -> Result<PgPool> {
    trace!(host = ?opts.url.host(), "connecting to database");
    let pg = PgPoolOptions::new()
        .max_connections(opts.pool_size)
        .connect(opts.url.as_str())
        .await?;
    debug!(host = ?opts.url.host(), "connected to database");

    Ok(pg)
}