blob: 156de0fc1304abd3488cc6565bbeb4c7724de415 (
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 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)
}
|