Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(connection): keep config after disconnect

t8y2e725dd037940
diff --git a/crates/dbx-web/src/routes/connection.rs b/crates/dbx-web/src/routes/connection.rs
index 8636eba54f..f82d9d0711 100644
--- a/crates/dbx-web/src/routes/connection.rs
+++ b/crates/dbx-web/src/routes/connection.rs
@@ -86,7 +86,6 @@ pub async fn disconnect_db(
}
drop(connections);
- app.configs.write().await.remove(&body.connection_id);
app.tunnels.stop_tunnel(&body.connection_id).await;
app.proxy_tunnels.stop_tunnel(&body.connection_id).await;
@@ -153,6 +152,7 @@ mod tests {
ssh_key_passphrase: String::new(),
ssh_expose_lan: false,
ssh_connect_timeout_secs: dbx_core::models::connection::default_ssh_connect_timeout_secs(),
+ connect_timeout_secs: dbx_core::models::connection::default_connect_timeout_secs(),
query_timeout_secs: dbx_core::models::connection::default_query_timeout_secs(),
proxy_enabled: false,
proxy_type: ProxyType::Socks5,
@@ -238,4 +238,30 @@ mod tests {
let _ = std::fs::remove_dir_all(dir);
}
+
+ #[tokio::test]
+ async fn disconnect_db_keeps_connection_config_for_reconnect() {
+ let (state, dir) = test_web_state().await;
+ let conn_path = dir.join("conn.db");
+ std::fs::File::create(&conn_path).unwrap();
+ let conn_pool = dbx_core::db::sqlite::connect_path(&conn_path.to_string_lossy()).await.unwrap();
+
+ {
+ let mut connections = state.app.connections.write().await;
+ connections.insert("conn".to_string(), PoolKind::Sqlite(conn_pool));
+ }
+ {
+ let mut configs = state.app.configs.write().await;
+ configs.insert("conn".to_string(), sqlite_config("conn", &conn_path.to_string_lossy()));
+ }
+
+ let result =
+ disconnect_db(State(state.clone()), Json(DisconnectRequest { connection_id: "conn".to_string() })).await;
+ assert!(result.is_ok());
+
+ let configs = state.app.configs.read().await;
+ assert!(configs.contains_key("conn"));
+
+ let _ = std::fs::remove_dir_all(dir);
+ }
}
diff --git a/src-tauri/src/commands/connection.rs b/src-tauri/src/commands/connection.rs
index 99f2affccc..6be8e98a36 100644
--- a/src-tauri/src/commands/connection.rs
+++ b/src-tauri/src/commands/connection.rs
@@ -529,7 +529,6 @@ pub async fn disconnect_db(state: State<'_, Arc<AppState>>, connection_id: Strin
}
}
drop(conns);
- state.configs.write().await.remove(&connection_id);
state.reset_connection_transport(&connection_id).await;
Ok(())
}