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(databend): enable editing and procedures

t8y23ee2514d07f9
diff --git a/apps/desktop/src/lib/databaseObjectCapabilities.ts b/apps/desktop/src/lib/databaseObjectCapabilities.ts
index 1b2edd8e07..ee696f9f16 100644
--- a/apps/desktop/src/lib/databaseObjectCapabilities.ts
+++ b/apps/desktop/src/lib/databaseObjectCapabilities.ts
@@ -10,6 +10,7 @@ export interface DatabaseObjectCapabilities {
const TABLE_OBJECTS: SidebarObjectKind[] = ["TABLE"];
const TABLE_VIEW_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW"];
+const TABLE_VIEW_PROCEDURE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "PROCEDURE"];
const TABLE_FUNCTION_OBJECTS: SidebarObjectKind[] = ["TABLE", "FUNCTION"];
const ROUTINE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "PROCEDURE", "FUNCTION"];
const POSTGRES_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "PROCEDURE", "FUNCTION", "SEQUENCE"];
@@ -17,7 +18,8 @@ const ORACLE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "PROCEDURE", "FUNC
const TABLE_ONLY_TYPES = new Set<DatabaseType>(["influxdb"]);
const TABLE_FUNCTION_TYPES = new Set<DatabaseType>(["manticoresearch"]);
-const TABLE_VIEW_ONLY_TYPES = new Set<DatabaseType>(["sqlite", "rqlite", "turso", "duckdb", "clickhouse", "doris", "starrocks", "databend", "hive", "trino", "cassandra", "bigquery", "kylin", "tdengine", "iotdb", "neo4j", "questdb"]);
+const TABLE_VIEW_PROCEDURE_TYPES = new Set<DatabaseType>(["databend"]);
+const TABLE_VIEW_ONLY_TYPES = new Set<DatabaseType>(["sqlite", "rqlite", "turso", "duckdb", "clickhouse", "doris", "starrocks", "hive", "trino", "cassandra", "bigquery", "kylin", "tdengine", "iotdb", "neo4j", "questdb"]);
const ORACLE_PACKAGE_TYPES = new Set<DatabaseType>(["oracle", "oceanbase-oracle"]);
const POSTGRES_SEQUENCE_TYPES = new Set<DatabaseType>(["postgres", "gaussdb", "kwdb", "opengauss"]);
@@ -36,6 +38,7 @@ export function sidebarObjectKindsForDatabase(dbType?: DatabaseType): SidebarObj
if (ORACLE_PACKAGE_TYPES.has(dbType)) return [...ORACLE_OBJECTS];
if (TABLE_ONLY_TYPES.has(dbType)) return [...TABLE_OBJECTS];
if (TABLE_FUNCTION_TYPES.has(dbType)) return [...TABLE_FUNCTION_OBJECTS];
+ if (TABLE_VIEW_PROCEDURE_TYPES.has(dbType)) return [...TABLE_VIEW_PROCEDURE_OBJECTS];
if (TABLE_VIEW_ONLY_TYPES.has(dbType)) return [...TABLE_VIEW_OBJECTS];
if (POSTGRES_SEQUENCE_TYPES.has(dbType)) return [...POSTGRES_OBJECTS];
return [...ROUTINE_OBJECTS];
diff --git a/apps/desktop/src/lib/databaseTableDataCapabilities.ts b/apps/desktop/src/lib/databaseTableDataCapabilities.ts
index ca51f80f57..05af6b0b13 100644
--- a/apps/desktop/src/lib/databaseTableDataCapabilities.ts
+++ b/apps/desktop/src/lib/databaseTableDataCapabilities.ts
@@ -83,6 +83,7 @@ const NAVICAT_STYLE_TABLE_DATA_TYPES = new Set<DatabaseType>([
"informix",
"bigquery",
"sundb",
+ "databend",
]);
const DATABASE_CAPABILITY_OVERRIDES: Partial<Record<DatabaseType, Partial<DatabaseCapability>>> = {
diff --git a/apps/desktop/src/lib/routineExecutionSql.ts b/apps/desktop/src/lib/routineExecutionSql.ts
index 11c1bcaac8..7899f212c9 100644
--- a/apps/desktop/src/lib/routineExecutionSql.ts
+++ b/apps/desktop/src/lib/routineExecutionSql.ts
@@ -27,6 +27,7 @@ export interface RoutineParameterValue extends RoutineParameter {
export function qualifiedRoutineName(options: BuildRoutineExecutionSqlOptions): string {
const { databaseType, schema, routineName } = options;
+ if (databaseType === "databend") return routineName;
if (isSchemaAware(databaseType) && schema) {
return `${quoteTableIdentifier(databaseType, schema)}.${quoteTableIdentifier(databaseType, routineName)}`;
}
@@ -49,6 +50,9 @@ export function buildProcedureExecutionSqlFromValues(options: BuildRoutineExecut
if (options.databaseType === "oracle" || options.databaseType === "dameng" || options.databaseType === "oceanbase-oracle") {
return `BEGIN\n ${routine}(${values.map((parameter) => routineArgumentSql(options.databaseType, parameter, useNamedArguments)).join(", ")});\nEND;`;
}
+ if (options.databaseType === "databend") {
+ return `CALL PROCEDURE ${routine}(${values.map((parameter) => routineArgumentSql(options.databaseType, parameter, useNamedArguments)).join(", ")});`;
+ }
return `CALL ${routine}(${values.map((parameter) => routineArgumentSql(options.databaseType, parameter, useNamedArguments)).join(", ")});`;
}
diff --git a/apps/desktop/src/lib/routineParameters.ts b/apps/desktop/src/lib/routineParameters.ts
index 1699269e0c..5fe6f63459 100644
--- a/apps/desktop/src/lib/routineParameters.ts
+++ b/apps/desktop/src/lib/routineParameters.ts
@@ -17,11 +17,11 @@ export async function loadRoutineParameters(options: LoadRoutineParametersOption
maxRows: 200,
pageSize: 200,
});
- return routineParametersFromResult(result);
+ return routineParametersFromResult(result, options.databaseType);
}
export function supportsRoutineParameterMetadata(databaseType?: DatabaseType): boolean {
- return databaseType === "postgres" || databaseType === "mysql" || databaseType === "doris" || databaseType === "starrocks" || databaseType === "sqlserver" || databaseType === "oracle" || databaseType === "dameng" || databaseType === "oceanbase-oracle";
+ return databaseType === "postgres" || databaseType === "mysql" || databaseType === "doris" || databaseType === "starrocks" || databaseType === "sqlserver" || databaseType === "oracle" || databaseType === "dameng" || databaseType === "oceanbase-oracle" || databaseType === "databend";
}
export function routineParametersQuery(options: Pick<LoadRoutineParametersOptions, "database" | "databaseType" | "schema" | "routineName">): string | null {
@@ -79,6 +79,14 @@ WHERE SPECIFIC_SCHEMA = ${schema}
AND SPECIFIC_NAME = ${name}
AND ORDINAL_POSITION > 0
ORDER BY ORDINAL_POSITION;`.trim();
+ }
+ if (options.databaseType === "databend") {
+ return `
+SELECT arguments
+FROM system.procedures
+WHERE name = ${name}
+ORDER BY procedure_id
+LIMIT 1;`.trim();
}
if (options.databaseType === "sqlserver") {
return `
@@ -113,7 +121,8 @@ ORDER BY SEQUENCE;`.trim();
return null;
}
-export function routineParametersFromResult(result: QueryResult): RoutineParameter[] {
+export function routineParametersFromResult(result: QueryResult, databaseType?: DatabaseType): RoutineParameter[] {
+ if (databaseType === "databend") return databendRoutineParametersFromResult(result);
return result.rows
.map((row, index) => ({
name: String(row[0] || `arg${index + 1}`),
@@ -125,6 +134,54 @@ export function routineParametersFromResult(result: QueryResult): RoutineParamet
.filter((parameter) => parameter.mode !== "RETURN");
}
+function databendRoutineParametersFromResult(result: QueryResult): RoutineParameter[] {
+ const argumentsIndex = result.columns.findIndex((column) => column.toLowerCase() === "arguments");
+ const signature = String(result.rows[0]?.[argumentsIndex >= 0 ? argumentsIndex : 0] || "");
+ const inputTypes = databendInputTypesFromArguments(signature);
+ return inputTypes.map((dataType, index) => ({
+ name: `arg${index + 1}`,
+ dataType,
+ mode: "IN",
+ ordinal: index + 1,
+ hasDefault: false,
+ }));
+}
+
+function databendInputTypesFromArguments(signature: string): string[] {
+ const openIndex = signature.indexOf("(");
+ if (openIndex < 0) return [];
+ let depth = 0;
+ for (let index = openIndex; index < signature.length; index += 1) {
+ const char = signature[index];
+ if (char === "(") depth += 1;
+ if (char === ")") {
+ depth -= 1;
+ if (depth === 0) {
+ return splitTopLevelComma(signature.slice(openIndex + 1, index)).filter(Boolean);
+ }
+ }
+ }
+ return [];
+}
+
+function splitTopLevelComma(value: string): string[] {
+ const parts: string[] = [];
+ let current = "";
+ let depth = 0;
+ for (const char of value) {
+ if (char === "(") depth += 1;
+ if (char === ")") depth = Math.max(0, depth - 1);
+ if (char === "," && depth === 0) {
+ parts.push(current.trim());
+ current = "";
+ continue;
+ }
+ current += char;
+ }
+ if (current.trim()) parts.push(current.trim());
+ return parts;
+}
+
function normalizeParameterMode(value: unknown): RoutineParameterMode {
const mode = String(value || "IN")
.toUpperCase()
diff --git a/crates/dbx-core/assets/database-drivers.manifest.json b/crates/dbx-core/assets/database-drivers.manifest.json
index 0dc4302fd2..324d585e91 100644
--- a/crates/dbx-core/assets/database-drivers.manifest.json
+++ b/crates/dbx-core/assets/database-drivers.manifest.json
@@ -604,7 +604,7 @@
"objectSource": false,
"schemaSearch": false,
"diagram": false,
- "tableDataEdit": false,
+ "tableDataEdit": true,
"tableStructureEdit": true,
"tableImport": false,
"dataTransfer": false,
diff --git a/crates/dbx-core/src/connection.rs b/crates/dbx-core/src/connection.rs
index a0dd88bca9..6eeb8421e7 100644
--- a/crates/dbx-core/src/connection.rs
+++ b/crates/dbx-core/src/connection.rs
@@ -359,7 +359,7 @@ impl AppState {
.await?;
PoolKind::Mysql(pool, mode)
}
- DatabaseType::Doris | DatabaseType::StarRocks | DatabaseType::ManticoreSearch | DatabaseType::Databend => {
+ DatabaseType::Doris | DatabaseType::StarRocks | DatabaseType::ManticoreSearch => {
let pool = if database.is_none() {
connect_bare_metadata_pool(&db_config, &host, port, connect_timeout, mysql_pool_max_connections)
.await?
@@ -538,6 +538,7 @@ impl AppState {
| DatabaseType::Highgo
| DatabaseType::Vastbase
| DatabaseType::Goldendb
+ | DatabaseType::Databend
| DatabaseType::Yashandb
| DatabaseType::Databricks
| DatabaseType::SapHana
@@ -1131,6 +1132,11 @@ fn shares_database_pool_with_connection(db_type: &DatabaseType) -> bool {
matches!(db_type, DatabaseType::Oracle)
}
+#[cfg(test)]
+fn uses_bare_mysql_pool(db_type: &DatabaseType) -> bool {
+ matches!(db_type, DatabaseType::Doris | DatabaseType::StarRocks | DatabaseType::ManticoreSearch)
+}
+
fn default_plugin_dir() -> PathBuf {
default_dbx_dir().join("plugins")
}
@@ -1308,14 +1314,15 @@ async fn detect_ob_oracle_mode(config: &ConnectionConfig, pool: &db::mysql::MySq
mod tests {
use super::{
connection_url_for_endpoint, database_connection_config, metadata_connection_config,
- mysql_metadata_fallback_url, redacted_connection_url_for_endpoint, uses_tcp_probe, validate_h2_database_path,
- AppState, PoolKind,
+ mysql_metadata_fallback_url, redacted_connection_url_for_endpoint, uses_bare_mysql_pool, uses_tcp_probe,
+ validate_h2_database_path, AppState, PoolKind,
};
use crate::agent_connection::{
agent_connect_params, mongo_legacy_error_with_auth_hint, mongo_uses_legacy_driver,
oracle_alternate_connect_config, should_retry_mongo_with_legacy_driver, should_retry_oracle_with_10g_driver,
};
use crate::agent_manager::{AgentState, JavaRuntimeConfig, JavaRuntimeMode, DEFAULT_JRE_KEY};
+ use crate::database_capabilities;
use crate::db;
use crate::models::connection::{
default_connect_timeout_secs, default_redis_key_separator, ConnectionConfig, DatabaseType, ProxyTunnelConfig,
@@ -1387,6 +1394,15 @@ mod tests {
assert_eq!(params["url_params"], "INFORMIXSERVER=informix;CLIENT_LOCALE=en_US.utf8");
}
+ #[test]
+ fn databend_uses_agent_pool_not_bare_mysql_pool() {
+ assert!(uses_bare_mysql_pool(&DatabaseType::Doris));
+ assert!(uses_bare_mysql_pool(&DatabaseType::StarRocks));
+ assert!(uses_bare_mysql_pool(&DatabaseType::ManticoreSearch));
+ assert!(!uses_bare_mysql_pool(&DatabaseType::Databend));
+ assert!(database_capabilities::is_agent_type(&DatabaseType::Databend));
+ }
+
#[test]
fn validates_h2_database_base_path_when_mv_db_file_exists() {
let dir = std::env::temp_dir().join(format!("dbx-h2-test-{}", uuid::Uuid::new_v4()));
diff --git a/crates/dbx-core/src/data_grid_sql.rs b/crates/dbx-core/src/data_grid_sql.rs
index b75552c0c5..4a2e376362 100644
--- a/crates/dbx-core/src/data_grid_sql.rs
+++ b/crates/dbx-core/src/data_grid_sql.rs
@@ -1584,6 +1584,34 @@ mod tests {
);
}
+ #[test]
+ fn prepares_databend_save_statements() {
+ let result = prepare_data_grid_save(DataGridSaveStatementOptions {
+ database_type: Some(DatabaseType::Databend),
+ table_meta: DataGridTableMeta {
+ schema: Some("default".to_string()),
+ table_name: "people".to_string(),
+ primary_keys: vec!["id".to_string()],
+ columns: Some(vec![column("id", "int", false, None), column("name", "string", true, None)]),
+ },
+ columns: vec!["id".to_string(), "name".to_string()],
+ source_columns: None,
+ rows: vec![vec![json!(1), json!("Ada")]],
+ dirty_rows: vec![(0, vec![(1, json!("Linus"))])],
+ deleted_rows: vec![0],
+ new_rows: vec![vec![json!(2), json!("Grace")]],
+ });
+
+ assert_eq!(
+ result.statements,
+ vec![
+ "UPDATE `default`.`people` SET `name` = 'Linus' WHERE `id` = 1;",
+ "DELETE FROM `default`.`people` WHERE `id` = 1;",
+ "INSERT INTO `default`.`people` (`id`, `name`) VALUES (2, 'Grace');",
+ ]
+ );
+ }
+
#[test]
fn skips_expression_only_source_columns() {
let result = prepare_data_grid_save(DataGridSaveStatementOptions {
diff --git a/packages/app-tests/databaseCapabilities.test.ts b/packages/app-tests/databaseCapabilities.test.ts
index 2a7861367b..866001c105 100644
--- a/packages/app-tests/databaseCapabilities.test.ts
+++ b/packages/app-tests/databaseCapabilities.test.ts
@@ -201,6 +201,14 @@ test("uses Navicat-style table editing defaults for updateable SQL table engines
requiresTransactionalTableForExistingRows: false,
transaction: true,
});
+ assert.deepEqual(getDatabaseCapability("databend").tableData, {
+ insert: true,
+ updateRequiresPrimaryKey: false,
+ deleteRequiresPrimaryKey: false,
+ keylessRowPredicate: true,
+ requiresTransactionalTableForExistingRows: false,
+ transaction: true,
+ });
});
test("keeps conservative table editing defaults for unknown database types", () => {
@@ -318,7 +326,7 @@ test("object browser entry follows database tree shape", () => {
});
test("sidebar object capability registry describes object groups by database type", () => {
- assert.deepEqual(sidebarObjectKindsForDatabase("databend"), ["TABLE", "VIEW"]);
+ assert.deepEqual(sidebarObjectKindsForDatabase("databend"), ["TABLE", "VIEW", "PROCEDURE"]);
assert.deepEqual(sidebarObjectKindsForDatabase("manticoresearch"), ["TABLE", "FUNCTION"]);
assert.deepEqual(sidebarObjectKindsForDatabase("postgres"), ["TABLE", "VIEW", "PROCEDURE", "FUNCTION", "SEQUENCE"]);
assert.deepEqual(sidebarObjectKindsForDatabase("oracle"), ["TABLE", "VIEW", "PROCEDURE", "FUNCTION", "PACKAGE", "PACKAGE_BODY"]);
diff --git a/packages/app-tests/routineExecutionSql.test.ts b/packages/app-tests/routineExecutionSql.test.ts
index 927885d111..05e0e971d9 100644
--- a/packages/app-tests/routineExecutionSql.test.ts
+++ b/packages/app-tests/routineExecutionSql.test.ts
@@ -8,6 +8,7 @@ test("builds procedure execution templates for common dialect families", () => {
assert.equal(buildProcedureExecutionSql({ databaseType: "mysql", schema: "app", routineName: "refresh_stats" }), "CALL `refresh_stats`();");
assert.equal(buildProcedureExecutionSql({ databaseType: "sqlserver", schema: "dbo", routineName: "refresh_stats" }), "EXEC [dbo].[refresh_stats];");
assert.equal(buildProcedureExecutionSql({ databaseType: "dameng", schema: "SYSDBA", routineName: "refresh_stats" }), 'BEGIN\n "SYSDBA"."refresh_stats"();\nEND;');
+ assert.equal(buildProcedureExecutionSql({ databaseType: "databend", schema: "default", routineName: "refresh_stats" }), "CALL PROCEDURE refresh_stats();");
});
test("builds procedure execution templates from parameter values", () => {
@@ -122,10 +123,28 @@ test("maps routine parameter query results into form metadata", () => {
]);
});
+test("maps Databend procedure signatures into positional input parameters", () => {
+ const parameters = routineParametersFromResult(
+ {
+ columns: ["arguments"],
+ rows: [["convert_weight(Decimal(10, 2), String) RETURN (Decimal(10, 2))"]],
+ affected_rows: 0,
+ execution_time_ms: 1,
+ },
+ "databend",
+ );
+
+ assert.deepEqual(parameters, [
+ { name: "arg1", dataType: "Decimal(10, 2)", mode: "IN", ordinal: 1, hasDefault: false },
+ { name: "arg2", dataType: "String", mode: "IN", ordinal: 2, hasDefault: false },
+ ]);
+});
+
test("builds parameter metadata queries for supported dialects", () => {
assert.match(routineParametersQuery({ database: "app", databaseType: "postgres", schema: "public", routineName: "demo" }) ?? "", /pg_proc/);
assert.match(routineParametersQuery({ database: "app", databaseType: "sqlserver", schema: "dbo", routineName: "demo" }) ?? "", /sys\.parameters/);
assert.match(routineParametersQuery({ database: "app", databaseType: "mysql", routineName: "demo" }) ?? "", /SPECIFIC_SCHEMA = 'app'/);
+ assert.match(routineParametersQuery({ database: "default", databaseType: "databend", schema: "default", routineName: "demo" }) ?? "", /system\.procedures/);
assert.match(routineParametersQuery({ database: "app", databaseType: "postgres", routineName: "demo" }) ?? "", /n\.nspname = 'public'/);
assert.equal(routineParametersQuery({ database: "app", databaseType: "sqlite", schema: "main", routineName: "demo" }), null);
});
diff --git a/packages/app-tests/tableEditing.test.ts b/packages/app-tests/tableEditing.test.ts
index 1081825d43..9fb6db9770 100644
--- a/packages/app-tests/tableEditing.test.ts
+++ b/packages/app-tests/tableEditing.test.ts
@@ -53,6 +53,7 @@ test("allows updateable SQL table data editing even without declared primary key
assert.equal(isTableDataEditable("tdengine", []), true);
assert.equal(isTableDataEditable("mysql", []), true);
assert.equal(isTableDataEditable("manticoresearch", []), true);
+ assert.equal(isTableDataEditable("databend", []), true);
assert.equal(isTableDataEditable("postgres", []), true);
assert.equal(isTableDataEditable("postgres", ["id"]), true);
});
@@ -78,6 +79,7 @@ test("allows existing row edits according to database-specific key requirements"
assert.equal(canEditExistingTableRows("trino", undefined, ["id"]), true);
assert.equal(canEditExistingTableRows("mysql", undefined, []), true);
assert.equal(canEditExistingTableRows("manticoresearch", undefined, []), true);
+ assert.equal(canEditExistingTableRows("databend", undefined, []), true);
assert.equal(canEditExistingTableRows("postgres", undefined, []), true);
assert.equal(canEditExistingTableRows("sqlite", undefined, []), true);
assert.equal(canEditExistingTableRows("sqlite", undefined, ["id"]), true);