fix(jdbc): show schemas for generic JDBC connections

This commit is contained in:
t8y2 committed 2026-07-25 21:51:11 +08:00
1 parent 1e21a5ad52
commit 47d48a09e9
5 files changed
+144 -5

No files matched your search

+19 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { connectionObjectTreeNodeSchema, connectionQueryExecutionSchema, effectiveDatabaseTypeForConnection, inferJdbcDialect } from "@/lib/database/jdbcDialect";
import { connectionObjectTreeNodeSchema, connectionQueryExecutionSchema, connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection, inferJdbcDialect } from "@/lib/database/jdbcDialect";
describe("jdbc dialect inference", () => {
it("detects InterSystems IRIS and Caché JDBC connections", () => {
@@ -46,6 +46,24 @@ describe("jdbc dialect inference", () => {
}),
).toBe("sqlserver");
});
it("detects GaussDB-compatible JDBC connections as schema-aware", () => {
const gaussdbConnection = {
db_type: "jdbc" as const,
connection_string: "jdbc:gaussdb://localhost:8000/testdb",
jdbc_driver_class: "com.huawei.gaussdb.jdbc.Driver",
};
const opengaussConnection = {
db_type: "jdbc" as const,
connection_string: "jdbc:opengauss://localhost:5432/postgres",
jdbc_driver_class: "org.opengauss.Driver",
};
expect(inferJdbcDialect(gaussdbConnection)).toBe("gaussdb");
expect(connectionUsesDatabaseObjectTreeMode(gaussdbConnection)).toBe(false);
expect(inferJdbcDialect(opengaussConnection)).toBe("opengauss");
expect(connectionUsesDatabaseObjectTreeMode(opengaussConnection)).toBe(false);
});
});
describe("query execution schema", () => {
+6 -1
View File
@@ -12,6 +12,8 @@ const JDBC_DIALECT_MATCHERS: Array<{ type: DatabaseType; patterns: RegExp[] }> =
{ type: "goldendb", patterns: [/jdbc:goldendb:/i, /goldendb/i] },
{ type: "hive", patterns: [/org\.apache\.hive\.jdbc\.HiveDriver/i, /hive-jdbc/i] },
{ type: "mysql", patterns: [/jdbc:mysql:/i, /mysql/i, /mariadb/i, /kyuubi/i, /hive2/i] },
{ type: "gaussdb", patterns: [/jdbc:gaussdb:/i, /com\.huawei\.gaussdb/i, /gaussdb/i] },
{ type: "opengauss", patterns: [/jdbc:opengauss:/i, /org\.opengauss/i, /opengauss/i] },
{ type: "postgres", patterns: [/jdbc:postgresql:/i, /postgres/i] },
{ type: "sqlserver", patterns: [/jdbc:sqlserver:/i, /sqlserver/i, /mssql/i] },
{ type: "oracle", patterns: [/jdbc:oracle:/i, /oracle/i] },
@@ -76,6 +78,10 @@ export function connectionUsesDatabaseObjectTreeMode(connection?: JdbcDialectCon
return !usesTreeSchemaMode(dialect);
}
export function connectionShouldDiscoverJdbcSchemas(connection?: JdbcDialectConnection): boolean {
return connection?.db_type === "jdbc" && !inferJdbcDialect(connection);
}
export function connectionUsesSchemaExecutionContext(connection?: Pick<ConnectionConfig, "db_type" | "connection_string" | "jdbc_driver_class" | "jdbc_driver_paths">): boolean {
return connection?.db_type === "jdbc" && inferJdbcDialect(connection) === "databend";
}
@@ -103,7 +109,6 @@ export function metadataSchemaForConnection(connection: JdbcDialectConnection |
}
export function connectionObjectTreeNodeSchema(connection: JdbcDialectConnection | undefined, database: string, schema?: string): string | undefined {
if (connection?.db_type === "jdbc" && inferJdbcDialect(connection) === "databend") return schema || database;
if (connection?.db_type === "jdbc" && inferJdbcDialect(connection) === "databend") return schema || database;
if (connectionUsesDatabaseObjectTreeMode(connection)) return undefined;
if (schema) return schema;