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。

Updated

Agent-43b6709a0280b3
diff --git a/crates/dbx-core/src/db/mysql.rs b/crates/dbx-core/src/db/mysql.rs
index d11860d126..2411af113d 100644
--- a/crates/dbx-core/src/db/mysql.rs
+++ b/crates/dbx-core/src/db/mysql.rs
@@ -155,13 +155,16 @@ fn mysql_value_to_json(row: &MySqlRow, idx: usize, type_name: &str) -> serde_jso
}
pub async fn connect(url: &str) -> Result<MySqlPool, String> {
- MySqlPoolOptions::new()
- .max_connections(5)
- .acquire_timeout(Duration::from_secs(10))
- .idle_timeout(Duration::from_secs(300))
- .connect(url)
- .await
- .map_err(|e| format!("MySQL connection failed: {e}"))
+ super::with_connection_timeout("MySQL", async {
+ MySqlPoolOptions::new()
+ .max_connections(5)
+ .acquire_timeout(super::connection_timeout())
+ .idle_timeout(Duration::from_secs(300))
+ .connect(url)
+ .await
+ .map_err(|e| format!("MySQL connection failed: {e}"))
+ })
+ .await
}
pub async fn connect_bare(url: &str) -> Result<MySqlPool, String> {
@@ -172,13 +175,16 @@ pub async fn connect_bare(url: &str) -> Result<MySqlPool, String> {
.set_names(false)
.pipes_as_concat(false)
.timezone(None);
- MySqlPoolOptions::new()
- .max_connections(5)
- .acquire_timeout(Duration::from_secs(10))
- .idle_timeout(Duration::from_secs(300))
- .connect_with(options)
- .await
- .map_err(|e| format!("MySQL connection failed: {e}"))
+ super::with_connection_timeout("MySQL", async {
+ MySqlPoolOptions::new()
+ .max_connections(5)
+ .acquire_timeout(super::connection_timeout())
+ .idle_timeout(Duration::from_secs(300))
+ .connect_with(options)
+ .await
+ .map_err(|e| format!("MySQL connection failed: {e}"))
+ })
+ .await
}
pub async fn list_databases(pool: &MySqlPool) -> Result<Vec<DatabaseInfo>, String> {
diff --git a/crates/dbx-core/src/db/postgres.rs b/crates/dbx-core/src/db/postgres.rs
index f0fe60a590..f0a779a111 100644
--- a/crates/dbx-core/src/db/postgres.rs
+++ b/crates/dbx-core/src/db/postgres.rs
@@ -92,13 +92,16 @@ pub async fn connect(url: &str) -> Result<PgPool, String> {
// Validate SSL certificate paths if present in the URL
validate_postgres_ssl_paths(url)?;
- PgPoolOptions::new()
- .max_connections(5)
- .acquire_timeout(Duration::from_secs(10))
- .idle_timeout(Duration::from_secs(300))
- .connect(url)
- .await
- .map_err(|e| format!("PostgreSQL connection failed: {e}"))
+ super::with_connection_timeout("PostgreSQL", async {
+ PgPoolOptions::new()
+ .max_connections(5)
+ .acquire_timeout(super::connection_timeout())
+ .idle_timeout(Duration::from_secs(300))
+ .connect(url)
+ .await
+ .map_err(|e| format!("PostgreSQL connection failed: {e}"))
+ })
+ .await
}
/// Validates SSL certificate file paths in PostgreSQL connection URLs.
diff --git a/crates/dbx-core/src/db/redis_driver.rs b/crates/dbx-core/src/db/redis_driver.rs
index f0dd1b03b2..fd7c750e7b 100644
--- a/crates/dbx-core/src/db/redis_driver.rs
+++ b/crates/dbx-core/src/db/redis_driver.rs
@@ -28,17 +28,20 @@ pub struct RedisValue {
pub async fn connect(url: &str) -> Result<redis::aio::MultiplexedConnection, String> {
let client = redis::Client::open(url).map_err(|e| format!("Redis connection failed: {e}"))?;
let mut con = tokio::time::timeout(
- std::time::Duration::from_secs(10),
+ super::connection_timeout(),
client.get_multiplexed_async_connection(),
)
.await
- .map_err(|_| "Redis connection timed out (10s)".to_string())?
+ .map_err(|_| format!("Redis connection timed out ({}s)", super::CONNECTION_TIMEOUT_SECS))?
.map_err(|e| format!("Redis connection failed: {e}"))?;
- redis::cmd("PING")
- .query_async::<String>(&mut con)
- .await
- .map_err(|e| format!("Redis authentication failed or command rejected: {e}"))?;
+ tokio::time::timeout(
+ super::connection_timeout(),
+ redis::cmd("PING").query_async::<String>(&mut con),
+ )
+ .await
+ .map_err(|_| format!("Redis ping timed out ({}s)", super::CONNECTION_TIMEOUT_SECS))?
+ .map_err(|e| format!("Redis authentication failed or command rejected: {e}"))?;
Ok(con)
}