Initial Commit

This commit is contained in:
2024-10-12 14:36:36 +02:00
commit bfc5cbf624
67 changed files with 10860 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
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<sqlx::Postgres>,
}
impl Postgres {
pub async fn new(url: &str) -> Result<Self, anyhow::Error> {
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<sqlx::Postgres> {
self.pool.clone()
}
}