use artists::Artists; use artworks::Artworks; use comments::Comments; use sqlx::{postgres::PgPoolOptions, Pool, Postgres}; pub mod artists; pub mod artworks; pub mod comments; #[derive(Clone)] pub struct Database(Pool); impl Database { pub async fn new(connection_string: &str) -> Self { let pool = PgPoolOptions::new() .max_connections(5) .connect(connection_string) .await .unwrap(); sqlx::migrate!("./migrations").run(&pool).await.unwrap(); Self(pool) } pub fn artists(&self) -> Artists { Artists::new(self.0.clone()) } pub fn artworks(&self) -> Artworks { Artworks::new(self.0.clone()) } pub fn comments(&self) -> Comments { Comments::new(self.0.clone()) } }