feature connection alias (#129)

* feature connection alias

* add database_url_with_name method to Connection

* Revert "feature connection alias"

This reverts commit 88b70c1c33.

* fix struct error

* fix review #129

* fix review

* fix type error
pull/132/head
ryo watanabe 3 years ago committed by GitHub
parent 318764f064
commit 403b9c7385
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -89,7 +89,7 @@ impl StatefulDrawableComponent for ConnectionsComponent {
let mut connections: Vec<ListItem> = 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()),
)
}

@ -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<String>,
user: Option<String>,
host: Option<String>,
port: Option<u64>,
@ -265,6 +267,19 @@ impl Connection {
}
}
pub fn database_url_with_name(&self) -> anyhow::Result<String> {
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)
}

Loading…
Cancel
Save