mirror of
https://codeberg.org/demostf/frontend.git
synced 2026-06-03 18:24:12 +02:00
optional db username/password
This commit is contained in:
parent
b403dd2b94
commit
9c1d7225db
1 changed files with 10 additions and 6 deletions
|
|
@ -35,16 +35,20 @@ impl Config {
|
|||
#[derive(Debug, Deserialize)]
|
||||
pub struct DbConfig {
|
||||
hostname: String,
|
||||
username: String,
|
||||
password: String,
|
||||
username: Option<String>,
|
||||
password: Option<String>,
|
||||
}
|
||||
|
||||
impl DbConfig {
|
||||
pub async fn connect(&self) -> Result<PgPool> {
|
||||
let opt = PgConnectOptions::new()
|
||||
.host(&self.hostname)
|
||||
.username(&self.username)
|
||||
.password(&self.password);
|
||||
let mut opt = PgConnectOptions::new().host(&self.hostname);
|
||||
if let Some(username) = &self.username {
|
||||
opt = opt.username(username);
|
||||
}
|
||||
if let Some(password) = &self.password {
|
||||
opt = opt.password(password);
|
||||
}
|
||||
|
||||
Ok(PgPool::connect_with(opt).await?)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue