pub mod oauth_repository; pub mod user_repository; use std::str::FromStr; use anyhow::Context; use sqlx::{postgres::PgConnectOptions, PgPool, Pool}; #[derive(Debug, Clone)] pub struct Postgres { pool: Pool, } impl Postgres { pub async fn new(url: &str) -> Result { let pool = PgPool::connect_with( PgConnectOptions::from_str(url) .with_context(|| format!("Invalid database url: {}", url))?, ) .await .with_context(|| format!("Failed to open database at {}", url))?; Ok(Self { pool }) } pub fn pool(&self) -> Pool { self.pool.clone() } }