feat: enhance MySQL connection handling and update connection dialog for Doris, SelectDB, and StarRocks

This commit is contained in:
t8y2
2026-05-01 19:36:17 +08:00
parent 48921cf811
commit 557897f428
4 changed files with 34 additions and 7 deletions
+12 -3
View File
@@ -86,7 +86,8 @@ impl AppState {
let (host, port) = self.connection_host_port(connection_id, &db_config).await?;
let url = connection_url_for_endpoint(&db_config, &host, port);
let pool = match db_config.db_type {
DatabaseType::Mysql | DatabaseType::Doris | DatabaseType::StarRocks => PoolKind::Mysql(db::mysql::connect(&url).await?),
DatabaseType::Mysql => PoolKind::Mysql(db::mysql::connect(&url).await?),
DatabaseType::Doris | DatabaseType::StarRocks => PoolKind::Mysql(db::mysql::connect_bare(&url).await?),
DatabaseType::Postgres | DatabaseType::Redshift => PoolKind::Postgres(db::postgres::connect(&url).await?),
DatabaseType::Sqlite => PoolKind::Sqlite(db::sqlite::connect(&url).await?),
DatabaseType::Redis => {
@@ -266,7 +267,14 @@ pub async fn test_connection(
target
);
let result = match config.db_type {
DatabaseType::Mysql | DatabaseType::Doris | DatabaseType::StarRocks => match db::mysql::connect(&url).await {
DatabaseType::Mysql => match db::mysql::connect(&url).await {
Ok(pool) => {
pool.close().await;
Ok("Connection successful".to_string())
}
Err(e) => Err(e),
},
DatabaseType::Doris | DatabaseType::StarRocks => match db::mysql::connect_bare(&url).await {
Ok(pool) => {
pool.close().await;
Ok("Connection successful".to_string())
@@ -359,7 +367,8 @@ pub async fn connect_db(
let url = connection_url_for_endpoint(&config, &host, port);
let pool = match config.db_type {
DatabaseType::Mysql | DatabaseType::Doris | DatabaseType::StarRocks => PoolKind::Mysql(db::mysql::connect(&url).await?),
DatabaseType::Mysql => PoolKind::Mysql(db::mysql::connect(&url).await?),
DatabaseType::Doris | DatabaseType::StarRocks => PoolKind::Mysql(db::mysql::connect_bare(&url).await?),
DatabaseType::Postgres | DatabaseType::Redshift => PoolKind::Postgres(db::postgres::connect(&url).await?),
DatabaseType::Sqlite => PoolKind::Sqlite(db::sqlite::connect(&url).await?),
DatabaseType::Redis => {
+15
View File
@@ -116,6 +116,21 @@ pub async fn connect(url: &str) -> Result<MySqlPool, String> {
.map_err(|e| format!("MySQL connection failed: {e}"))
}
pub async fn connect_bare(url: &str) -> Result<MySqlPool, String> {
let options: sqlx::mysql::MySqlConnectOptions = url.parse()
.map_err(|e: sqlx::Error| format!("Invalid MySQL URL: {e}"))?;
let options = options
.no_engine_substitution(false)
.set_names(false);
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}"))
}
pub async fn list_databases(pool: &MySqlPool) -> Result<Vec<DatabaseInfo>, String> {
let rows: Vec<MySqlRow> = sqlx::query("SELECT SCHEMA_NAME FROM information_schema.SCHEMATA ORDER BY SCHEMA_NAME")
.fetch_all(pool)
+4 -1
View File
@@ -202,7 +202,10 @@ impl ConnectionConfig {
}
DatabaseType::Doris | DatabaseType::StarRocks => {
let v = value.trim_start_matches('?');
if v.is_empty() { "ssl-mode=disabled".to_string() } else { v.to_string() }
let filtered: Vec<&str> = v.split('&')
.filter(|p| !p.is_empty() && !p.starts_with("charset=") && !p.starts_with("ssl-mode=preferred"))
.collect();
if filtered.is_empty() { "ssl-mode=disabled".to_string() } else { format!("ssl-mode=disabled&{}", filtered.join("&")) }
}
DatabaseType::Postgres | DatabaseType::Redshift => value.trim_start_matches('?').to_string(),
_ => value.trim_start_matches('?').to_string(),
@@ -93,9 +93,9 @@ const driverProfiles: Record<string, { type: DatabaseType; port: number; user: s
gaussdb: { type: "postgres", port: 5432, user: "gaussdb", label: "GaussDB", icon: "gaussdb" },
kingbase: { type: "postgres", port: 54321, user: "system", label: "KingBase", icon: "kingbase" },
vastbase: { type: "postgres", port: 5432, user: "vastbase", label: "Vastbase", icon: "vastbase" },
doris: { type: "mysql", port: 9030, user: "root", label: "Doris", icon: "doris" },
selectdb: { type: "mysql", port: 9030, user: "root", label: "SelectDB", icon: "selectdb" },
starrocks: { type: "mysql", port: 9030, user: "root", label: "StarRocks", icon: "starrocks" },
doris: { type: "mysql", port: 9030, user: "root", label: "Doris", icon: "doris", urlParams: "" },
selectdb: { type: "mysql", port: 9030, user: "root", label: "SelectDB", icon: "selectdb", urlParams: "" },
starrocks: { type: "mysql", port: 9030, user: "root", label: "StarRocks", icon: "starrocks", urlParams: "" },
redshift: { type: "postgres", port: 5439, user: "awsuser", label: "Redshift", icon: "redshift" },
cockroachdb:{ type: "postgres", port: 26257, user: "root", label: "CockroachDB", icon: "cockroachdb" },
tdengine: { type: "mysql", port: 6030, user: "root", label: "TDengine", icon: "tdengine" },