aboutsummaryrefslogtreecommitdiffstats
path: root/src/server/state/database.rs
blob: 32d3f9835b3d8797087cd283c22fdf98d2840a2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)
}