summaryrefslogtreecommitdiffstats
path: root/src/db/mod.rs
blob: 97a5b2505e2366c7e16112ff01aa2898bb868b7b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};

mod artworks;

#[derive(Clone)]
pub struct Database(Pool<Postgres>);

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)
    }
}