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)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct DbConfig {
|
pub struct DbConfig {
|
||||||
hostname: String,
|
hostname: String,
|
||||||
username: String,
|
username: Option<String>,
|
||||||
password: String,
|
password: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DbConfig {
|
impl DbConfig {
|
||||||
pub async fn connect(&self) -> Result<PgPool> {
|
pub async fn connect(&self) -> Result<PgPool> {
|
||||||
let opt = PgConnectOptions::new()
|
let mut opt = PgConnectOptions::new().host(&self.hostname);
|
||||||
.host(&self.hostname)
|
if let Some(username) = &self.username {
|
||||||
.username(&self.username)
|
opt = opt.username(username);
|
||||||
.password(&self.password);
|
}
|
||||||
|
if let Some(password) = &self.password {
|
||||||
|
opt = opt.password(password);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(PgPool::connect_with(opt).await?)
|
Ok(PgPool::connect_with(opt).await?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue