1
0
Fork 0
forked from gorb/backend

feat: use url format

This commit is contained in:
Radical 2025-05-21 20:48:43 +02:00
parent b9c7bda2b1
commit 746949f0e5

View file

@ -1,7 +1,6 @@
use crate::Error; use crate::Error;
use log::debug; use log::debug;
use serde::Deserialize; use serde::Deserialize;
use sqlx::postgres::PgConnectOptions;
use tokio::fs::read_to_string; use tokio::fs::read_to_string;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@ -81,13 +80,24 @@ pub struct Web {
} }
impl Database { impl Database {
pub fn connect_options(&self) -> PgConnectOptions { pub fn url(&self) -> String {
PgConnectOptions::new() let mut url = String::from("postgres://");
.database(&self.database)
.host(&self.host) url += &self.username;
.username(&self.username)
.password(&self.password) url += ":";
.port(self.port) url += &self.password;
url += "@";
url += &self.host;
url += ":";
url += &self.port.to_string();
url += "/";
url += &self.database;
url
} }
} }