use std::time::Duration; use anyhow::Error; use sqlx::{self, postgres::PgPoolOptions, Executor, Pool, Postgres}; use crate::config; pub type DB = Pool; pub trait Queryer<'c>: Executor<'c, Database = sqlx::Postgres> {} impl Queryer<'_> for &DB {} pub async fn connect(database: &config::Database) -> Result { PgPoolOptions::new() .max_connections(database.pool_size) .max_lifetime(Duration::from_secs(database.max_lifetime)) .connect(&database.url) .await .map_err(|err| { tracing::error!("{}", err); err.into() }) }