feat(connection): centralize connection type registration

This commit is contained in:
t8y2 committed 2026-08-23 16:38:06 +08:00
1 parent 38664e6aea
commit 0827478078
114 files changed
+5284 -1342

No files matched your search

@@ -4,7 +4,7 @@ import { manifestDatabaseTypes } from "@/lib/database/databaseDriverManifest";
import { supportsTransfer } from "@/lib/database/databaseFeatureSupport";
import type { DatabaseType } from "@/types/database";
const TABLE_ONLY_TRANSFER_DATABASES: DatabaseType[] = ["sqlite", "rqlite", "cloudflare-d1", "duckdb", "clickhouse", "mongodb", "goldendb", "questdb", "hive", "kyuubi", "impala", "spark"];
const TABLE_ONLY_TRANSFER_DATABASES: DatabaseType[] = ["sqlite", "rqlite", "turso", "cloudflare-d1", "duckdb", "clickhouse", "mongodb", "goldendb", "questdb", "hive", "kyuubi", "impala", "spark"];
describe("transferObjectKinds", () => {
it("groups databases into transfer families", () => {
@@ -1,104 +1,24 @@
import type { DatabaseType } from "@/types/database";
import { databaseTypesWithTrait } from "@/lib/database/databaseDriverManifest";
export const SCHEMA_AWARE_TYPES = new Set<DatabaseType>([
"postgres",
// Cloud Spanner supports named schemas; GoogleSQL's default schema is the empty string, which
// `spannerObjectTreeSchema` keeps intact through the `schema || database` fallbacks.
"spanner",
"sqlserver",
"oracle",
"redshift",
"dameng",
"gaussdb",
"kwdb",
"kingbase",
"highgo",
"uxdb",
"vastbase",
"yashandb",
"databricks",
"saphana",
"teradata",
"vertica",
"exasol",
"opengauss",
"oceanbase-oracle",
"gbase",
"jdbc",
"h2",
"ignite",
"ignite3",
"snowflake",
"trino",
"prestosql",
"hive",
"kyuubi",
"impala",
"spark",
"databend",
"db2",
"informix",
"xugu",
"oscar",
"iotdb",
"iris",
"duckdb",
]);
export const SCHEMA_AWARE_TYPES = databaseTypesWithTrait("schemaAware");
// Engines where an object can be addressed as database/catalog.schema.table.
// Keep this narrower than SCHEMA_AWARE_TYPES: PostgreSQL, for example, cannot
// query another database through a three-part name on the same connection.
export const DATABASE_SCHEMA_QUALIFIED_TYPES = new Set<DatabaseType>(["sqlserver", "trino", "prestosql"]);
export const DATABASE_SCHEMA_QUALIFIED_TYPES = databaseTypesWithTrait("databaseSchemaQualified");
export const SINGLE_DATABASE_TYPES = new Set<DatabaseType>(["oracle", "dameng", "firebird", "oceanbase-oracle", "access", "questdb", "victoriametrics"]);
export const SINGLE_DATABASE_TYPES = databaseTypesWithTrait("singleDatabase");
export const CLEARABLE_QUERY_SCHEMA_TYPES = new Set<DatabaseType>(["oracle", "dameng", "gaussdb", "oceanbase-oracle"]);
export const CLEARABLE_QUERY_SCHEMA_TYPES = databaseTypesWithTrait("clearableQuerySchema");
export const FETCH_FIRST_TYPES = new Set<DatabaseType>(["oracle", "dameng"]);
export const FETCH_FIRST_TYPES = databaseTypesWithTrait("fetchFirst");
export const TREE_SCHEMA_TYPES = new Set<DatabaseType>([
"postgres",
// Cloud Spanner needs the schema level for the same reason it is in SCHEMA_AWARE_TYPES: named
// schemas exist and are queryable, so the tree has to expose them. Membership here is what makes
// a database node load schemas instead of tables; SCHEMA_AWARE_TYPES alone only reaches the
// schema pickers in dialogs. The sites gated on `database === ""` stay unreachable because a
// Spanner database is always the resource path.
"spanner",
"redshift",
"sqlserver",
"db2",
"gaussdb",
"kwdb",
"kingbase",
"highgo",
"uxdb",
"vastbase",
"yashandb",
"databricks",
"saphana",
"teradata",
"vertica",
"exasol",
"opengauss",
"oceanbase-oracle",
"gbase",
"jdbc",
"trino",
"prestosql",
"h2",
"ignite",
"ignite3",
"informix",
"xugu",
"oscar",
"iris",
"duckdb",
]);
export const TREE_SCHEMA_TYPES = databaseTypesWithTrait("treeSchema");
export const DATABASE_OBJECT_TREE_TYPES = new Set<DatabaseType>(["jdbc"]);
export const DATABASE_OBJECT_TREE_TYPES = databaseTypesWithTrait("databaseObjectTree");
export const PG_VACUUM_TYPES = new Set<DatabaseType>(["postgres", "gaussdb", "kwdb", "kingbase", "highgo", "uxdb", "vastbase", "opengauss"]);
export const PG_VACUUM_TYPES = databaseTypesWithTrait("pgVacuum");
export const PG_LIKE_STRUCTURE_TYPES = new Set<DatabaseType>(["postgres", "redshift", "gaussdb", "kwdb", "opengauss", "questdb"]);
export const PG_LIKE_STRUCTURE_TYPES = databaseTypesWithTrait("pgLikeStructure");
export const DIAGRAM_SQL_TYPES = new Set<DatabaseType>(["mysql", "postgres", "sqlite", "rqlite", "turso", "cloudflare-d1", "sqlserver", "oracle", "redshift", "dameng", "gaussdb", "kwdb", "opengauss", "questdb", "oceanbase-oracle"]);
export const DIAGRAM_SQL_TYPES = databaseTypesWithTrait("diagramSql");
@@ -3,6 +3,7 @@ import driverManifest from "../../../../../crates/dbx-core/assets/database-drive
export type DatabaseSupportLevel = "connect" | "browse" | "understand" | "operate";
export type DatabaseRuntimeMode = "native" | "file" | "agent" | "external";
export type ConnectionFormKind = "standard" | "jdbc" | "mq" | "mqtt" | "nacos";
export const DATABASE_PRODUCT_CAPABILITY_KEYS = [
"queryExecution",
@@ -26,9 +27,46 @@ export const DATABASE_PRODUCT_CAPABILITY_KEYS = [
export type DatabaseProductCapability = (typeof DATABASE_PRODUCT_CAPABILITY_KEYS)[number];
export type DatabaseProductCapabilities = Record<DatabaseProductCapability, boolean>;
interface DatabaseDriverManifestEntry {
export const DATABASE_BEHAVIOR_TRAIT_KEYS = ["schemaAware", "databaseSchemaQualified", "singleDatabase", "clearableQuerySchema", "fetchFirst", "treeSchema", "databaseObjectTree", "pgVacuum", "pgLikeStructure", "diagramSql"] as const;
export type DatabaseBehaviorTrait = (typeof DATABASE_BEHAVIOR_TRAIT_KEYS)[number];
export type DatabaseBehaviorTraits = Partial<Record<DatabaseBehaviorTrait, boolean>>;
export interface DatabaseDriverProfile {
profile: string;
agentKey: string;
packageKey?: string;
label: string;
storeVisible: boolean;
storeOrder?: number;
}
export interface ManagedDatabaseDriver {
key: string;
label: string;
storeVisible: boolean;
storeOrder?: number;
}
export interface DatabaseDriverManifestEntry {
dbType: DatabaseType;
label: string;
dialect?: string;
runtimeMode: DatabaseRuntimeMode;
mcpMode: "direct" | "bridge" | "unsupported";
agentKey?: string;
driverStoreVisible?: boolean;
driverStoreOrder?: number;
driverProfiles?: DatabaseDriverProfile[];
managedDrivers?: ManagedDatabaseDriver[];
singleConnectionPool: boolean;
metadataConnectionScoped: boolean;
skipTcpProbe: boolean;
defaultPort?: number;
localFile?: boolean;
specializedSurface?: boolean;
formKind?: ConnectionFormKind;
traits?: DatabaseBehaviorTraits;
supportLevel: DatabaseSupportLevel;
capabilities: Partial<DatabaseProductCapabilities>;
}
@@ -74,6 +112,30 @@ export function databaseSupportLevel(dbType?: DatabaseType): DatabaseSupportLeve
return dbType ? DATABASE_DRIVER_BY_TYPE.get(dbType)?.supportLevel : undefined;
}
export function databaseManifestEntry(dbType?: DatabaseType): DatabaseDriverManifestEntry | undefined {
return dbType ? DATABASE_DRIVER_BY_TYPE.get(dbType) : undefined;
}
export function databaseDefaultPort(dbType?: DatabaseType): number | undefined {
return databaseManifestEntry(dbType)?.defaultPort;
}
export function databaseConnectionFormKind(dbType?: DatabaseType): ConnectionFormKind {
return databaseManifestEntry(dbType)?.formKind ?? "standard";
}
export function isKnownDatabaseType(value: string): value is DatabaseType {
return DATABASE_DRIVER_BY_TYPE.has(value as DatabaseType);
}
export function isLocalFileDatabaseType(dbType?: DatabaseType): boolean {
return databaseManifestEntry(dbType)?.localFile === true;
}
export function databaseTypesWithTrait(trait: DatabaseBehaviorTrait): Set<DatabaseType> {
return new Set(DATABASE_DRIVER_ENTRIES.filter((entry) => entry.traits?.[trait] === true).map((entry) => entry.dbType));
}
export function databaseRuntimeMode(dbType?: DatabaseType): DatabaseRuntimeMode | undefined {
return dbType ? DATABASE_DRIVER_BY_TYPE.get(dbType)?.runtimeMode : undefined;
}