diff --git a/src/components/connections.rs b/src/components/connections.rs index 5f5c57e..659f3db 100644 --- a/src/components/connections.rs +++ b/src/components/connections.rs @@ -89,7 +89,7 @@ impl StatefulDrawableComponent for ConnectionsComponent { let mut connections: Vec = Vec::new(); for c in conns { connections.push( - ListItem::new(vec![Spans::from(Span::raw(c.database_url()?))]) + ListItem::new(vec![Spans::from(Span::raw(c.database_url_with_name()?))]) .style(Style::default()), ) } diff --git a/src/config.rs b/src/config.rs index a7f116a..3d41831 100644 --- a/src/config.rs +++ b/src/config.rs @@ -51,6 +51,7 @@ impl Default for Config { Self { conn: vec![Connection { r#type: DatabaseType::MySql, + name: None, user: Some("root".to_string()), host: Some("localhost".to_string()), port: Some(3306), @@ -67,6 +68,7 @@ impl Default for Config { #[derive(Debug, Deserialize, Clone)] pub struct Connection { r#type: DatabaseType, + name: Option, user: Option, host: Option, port: Option, @@ -265,6 +267,19 @@ impl Connection { } } + pub fn database_url_with_name(&self) -> anyhow::Result { + let database_url = self.database_url()?; + + Ok(match &self.name { + Some(name) => format!( + "[{name}] {database_url}", + name = name, + database_url = database_url + ), + None => database_url, + }) + } + pub fn is_mysql(&self) -> bool { matches!(self.r#type, DatabaseType::MySql) }