feat(dameng): support dm6 connections via custom jdbc drivers
This commit is contained in:
20 files changed
+560
-21
No files matched your search
@@ -10,7 +10,7 @@ describe("BigQuery connection dialog", () => {
|
||||
|
||||
expect(nativeAgentDriverSupport).toContain('dbType === "bigquery"');
|
||||
expect(jdbcBackedDatabaseTypes).toContain('"bigquery"');
|
||||
expect(dialogSource).toContain("const supportsNativeAgentJdbcDriverConfig = computed(() => supportsNativeAgentJdbcDriverConfigType(form.value.db_type));");
|
||||
expect(dialogSource).toContain("const supportsNativeAgentJdbcDriverConfig = computed(() => supportsNativeAgentJdbcDriverConfigType(form.value.db_type)");
|
||||
expect(dialogSource).toContain('<template v-if="supportsNativeAgentJdbcDriverConfig">');
|
||||
expect(dialogSource).toContain('if (profile.type === "bigquery") {');
|
||||
expect(dialogSource).toContain("jdbcManualClasspathOpen.value = true;");
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DAMENG_CUSTOM_DRIVER_PROFILE, DAMENG_DEFAULT_JDBC_DRIVER_CLASS, damengCustomJdbcUrl, damengDriverModeForConfig, defaultDamengJdbcUrl } from "@/lib/database/damengDriverOptions";
|
||||
|
||||
describe("dameng driver options", () => {
|
||||
it("keeps existing connections on the built-in driver", () => {
|
||||
expect(damengDriverModeForConfig({ driver_profile: "dm", jdbc_driver_paths: [] })).toBe("builtin");
|
||||
});
|
||||
|
||||
it("recognizes custom DM6 profiles and legacy configs with an external JAR", () => {
|
||||
expect(damengDriverModeForConfig({ driver_profile: DAMENG_CUSTOM_DRIVER_PROFILE })).toBe("custom");
|
||||
expect(damengDriverModeForConfig({ driver_profile: "dm", jdbc_driver_paths: [" /drivers/DmJdbcDriver6.jar "] })).toBe("custom");
|
||||
});
|
||||
|
||||
it("builds DM6 driver defaults from host, port, and optional database", () => {
|
||||
expect(DAMENG_DEFAULT_JDBC_DRIVER_CLASS).toBe("dm6.jdbc.driver.DmDriver");
|
||||
expect(defaultDamengJdbcUrl({ host: "dm6.internal", port: 5237, database: "MAIN" })).toBe("jdbc:dm6://dm6.internal:5237/MAIN");
|
||||
expect(defaultDamengJdbcUrl({ host: "", port: 0, database: "" })).toBe("jdbc:dm6://127.0.0.1:5236");
|
||||
});
|
||||
|
||||
it("preserves a complete custom JDBC URL", () => {
|
||||
expect(damengCustomJdbcUrl({ host: "ignored", port: 5236, connection_string: " jdbc:dm6://dm6.internal:5236?foo=bar " })).toBe("jdbc:dm6://dm6.internal:5236?foo=bar");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
|
||||
export const DAMENG_BUILTIN_DRIVER_PROFILE = "dm";
|
||||
export const DAMENG_CUSTOM_DRIVER_PROFILE = "dm6-custom";
|
||||
export const DAMENG_DEFAULT_JDBC_DRIVER_CLASS = "dm6.jdbc.driver.DmDriver";
|
||||
|
||||
export type DamengDriverMode = "builtin" | "custom";
|
||||
|
||||
type DamengDriverConfig = Partial<Pick<ConnectionConfig, "driver_profile" | "host" | "port" | "database" | "connection_string" | "jdbc_driver_paths">>;
|
||||
|
||||
export function damengDriverModeForConfig(config: DamengDriverConfig): DamengDriverMode {
|
||||
if (config.driver_profile === DAMENG_CUSTOM_DRIVER_PROFILE || config.jdbc_driver_paths?.some((path) => path.trim())) {
|
||||
return "custom";
|
||||
}
|
||||
return "builtin";
|
||||
}
|
||||
|
||||
export function defaultDamengJdbcUrl(config: Pick<DamengDriverConfig, "host" | "port" | "database">): string {
|
||||
const host = config.host?.trim() || "127.0.0.1";
|
||||
const port = Number(config.port) > 0 ? Number(config.port) : 5236;
|
||||
const database = config.database?.trim();
|
||||
return `jdbc:dm6://${host}:${port}${database ? `/${database}` : ""}`;
|
||||
}
|
||||
|
||||
export function damengCustomJdbcUrl(config: DamengDriverConfig): string {
|
||||
return config.connection_string?.trim() || defaultDamengJdbcUrl(config);
|
||||
}
|
||||
Reference in new issue
Block a user