articles_rs/databases/
config.rspub 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
)
}
}