mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-31 08:23:34 +00:00
feat(connection): 为不同数据库类型展示各自对应的 connection URL placeholder
## 修改内容 - 新增 connectionUrlPlaceholder 纯函数于 connectionPresentation.ts,根据 db_type 返回对应 URL 格式 - ConnectionDialog.vue 中引用该函数替换原有统一的 i18n placeholder - 新增 20 个单元测试覆盖所有数据库类型及边界场景
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
import type { ConnectionConfig, DatabaseType } from "@/types/database";
|
||||
|
||||
type ConnectionPresentationConfig = Pick<
|
||||
ConnectionConfig,
|
||||
@@ -24,6 +24,53 @@ export function connectionEndpointLabel(connection?: ConnectionPresentationConfi
|
||||
return connection.host || connection.database || "";
|
||||
}
|
||||
|
||||
export function connectionUrlPlaceholder(dbType: DatabaseType): string {
|
||||
switch (dbType) {
|
||||
case "mysql":
|
||||
case "doris":
|
||||
case "starrocks":
|
||||
return "mysql://user:password@host:port/database";
|
||||
|
||||
case "postgres":
|
||||
case "gaussdb":
|
||||
case "redshift":
|
||||
return "postgresql://user:password@host:port/database";
|
||||
|
||||
case "redis":
|
||||
return "redis://:password@host:port/0";
|
||||
|
||||
case "sqlite":
|
||||
return "sqlite:///absolute/path/to/database.db";
|
||||
|
||||
case "duckdb":
|
||||
return "duckdb:///absolute/path/to/database.duckdb";
|
||||
|
||||
case "mongodb":
|
||||
return "mongodb://user:password@host:port/database";
|
||||
|
||||
case "clickhouse":
|
||||
return "clickhouse://user:password@host:port/database";
|
||||
|
||||
case "sqlserver":
|
||||
return "mssql://user:password@host:port/database";
|
||||
|
||||
case "oracle":
|
||||
return "oracle://user:password@host:port/service_name";
|
||||
|
||||
case "elasticsearch":
|
||||
return "http://user:password@host:port";
|
||||
|
||||
case "dameng":
|
||||
return "dm://user:password@host:port";
|
||||
|
||||
case "jdbc":
|
||||
return "jdbc:mysql://host:3306/database";
|
||||
|
||||
default:
|
||||
return "postgresql://user:password@host:port/database";
|
||||
}
|
||||
}
|
||||
|
||||
export function connectionOptionSubtitle(connection?: ConnectionPresentationConfig): string {
|
||||
return [connectionDriverLabel(connection), connectionEndpointLabel(connection)].filter(Boolean).join(" · ");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user