Skip to main content

ephemeral_postgres/
database.rs

1use std::sync::Arc;
2
3use sqlx::PgPool;
4
5use crate::cluster::Cluster;
6
7pub struct Database {
8    #[expect(
9        dead_code,
10        reason = "cluster Arc keeps the postgres container alive while this database is in use"
11    )]
12    cluster: Arc<Cluster>,
13    database_url: String,
14    db_name: String,
15    pool: PgPool,
16}
17
18impl Database {
19    #[doc(hidden)]
20    #[must_use]
21    pub fn new(cluster: Arc<Cluster>, database_url: String, db_name: String, pool: PgPool) -> Self {
22        Self {
23            cluster,
24            database_url,
25            db_name,
26            pool,
27        }
28    }
29
30    #[must_use]
31    pub fn db_name(&self) -> &str {
32        &self.db_name
33    }
34
35    #[must_use]
36    pub fn database_url(&self) -> &str {
37        &self.database_url
38    }
39
40    #[must_use]
41    pub fn pool(&self) -> &PgPool {
42        &self.pool
43    }
44}