articles_rs/databases/
config.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pub struct DbConfig {
    pub hostname: String,
    pub port: u32,
    pub database: String,
    pub username: String,
    pub password: String,
}

impl DbConfig {
    pub fn new(
        hostname: String,
        port: u32,
        database: String,
        username: String,
        password: String,
    ) -> DbConfig {
        DbConfig {
            hostname,
            port,
            database,
            username,
            password,
        }
    }

    pub fn get_connection_url(&self) -> String {
        format!(
            "postgres://{}:{}@{}:{}/{}?sslmode=disable",
            self.username, self.password, self.hostname, self.port, self.database
        )
    }
}