refactor(frontend): centralize database feature capabilities

This commit is contained in:
t8y2
2026-05-13 22:14:33 +08:00
parent 298f57c160
commit 5832e1b194
12 changed files with 435 additions and 204 deletions
@@ -17,7 +17,7 @@ import * as api from "@/lib/api";
import { isTauriRuntime } from "@/lib/tauriRuntime";
import { applyParsedConnectionUrl, parseConnectionUrl } from "@/lib/connectionUrl";
import { connectionUrlPlaceholder as getUrlPlaceholder } from "@/lib/connectionPresentation";
import { AGENT_DRIVER_TYPES } from "@/lib/databaseCapabilities";
import { supportsDriverManagement } from "@/lib/databaseCapabilities";
import { ArrowLeft, ChevronRight, Copy, ExternalLink, FolderOpen, Grid3X3, Link2, List, Search } from "lucide-vue-next";
type DbOption = { value: string; label: string };
@@ -1130,7 +1130,7 @@ function openExternalUrl(url: string) {
<Input v-model="form.database" class="col-span-3" :placeholder="databasePlaceholder" />
</div>
<div v-if="AGENT_DRIVER_TYPES.has(form.db_type)" class="grid grid-cols-4 items-center gap-4">
<div v-if="supportsDriverManagement(form.db_type)" class="grid grid-cols-4 items-center gap-4">
<span />
<p class="col-span-3 text-xs text-muted-foreground">
需要在顶部导航栏「驱动管理」中安装对应的驱动才能连接。
@@ -9,7 +9,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
import { useConnectionStore } from "@/stores/connectionStore";
import DatabaseIcon from "@/components/icons/DatabaseIcon.vue";
import * as api from "@/lib/api";
import { DIAGRAM_SQL_TYPES, SCHEMA_AWARE_TYPES } from "@/lib/databaseCapabilities";
import { DIAGRAM_SQL_TYPES, isSchemaAware as isSchemaAwareDatabase } from "@/lib/databaseCapabilities";
import {
buildDiagramRelationships,
filterDiagramTables,
@@ -91,9 +91,7 @@ const sqlConnections = computed(() =>
const selectedConnection = computed(() => (connectionId.value ? store.getConfig(connectionId.value) : undefined));
const isSchemaAware = computed(
() => !!selectedConnection.value && SCHEMA_AWARE_TYPES.has(selectedConnection.value.db_type),
);
const isSchemaAware = computed(() => isSchemaAwareDatabase(selectedConnection.value?.db_type));
const allRelationships = computed(() => buildDiagramRelationships(tables.value));
@@ -12,7 +12,7 @@ import { useConnectionStore } from "@/stores/connectionStore";
import * as api from "@/lib/api";
import { buildDatabaseSearchSql, buildSearchResultWhere, findMatchedSearchColumns } from "@/lib/databaseSearch";
import type { DatabaseType, TableInfo } from "@/types/database";
import { SCHEMA_AWARE_TYPES } from "@/lib/databaseCapabilities";
import { isSchemaAware } from "@/lib/databaseCapabilities";
const props = defineProps<{
open: boolean;
@@ -116,10 +116,6 @@ function resetSearchState() {
currentExecutionId.value = "";
}
function isSchemaAware(databaseType?: DatabaseType): boolean {
return !!databaseType && SCHEMA_AWARE_TYPES.has(databaseType);
}
function isSearchableTable(table: TableInfo): boolean {
const type = table.table_type.toUpperCase();
return type.includes("TABLE") && !type.includes("VIEW");
@@ -12,7 +12,7 @@ import DatabaseIcon from "@/components/icons/DatabaseIcon.vue";
import * as api from "@/lib/api";
import type { TransferProgress, TransferMode } from "@/lib/api";
import type { DatabaseType } from "@/types/database";
import { TRANSFER_SQL_TYPES, isSchemaAware } from "@/lib/databaseCapabilities";
import { isSchemaAware, supportsTransfer } from "@/lib/databaseCapabilities";
import { nextTransferTerminalState } from "@/lib/transferProgressState";
import { ArrowRightLeft, Check, X, Loader2, Square, CheckSquare } from "lucide-vue-next";
@@ -26,7 +26,7 @@ const props = defineProps<{
const store = useConnectionStore();
const sqlConnections = computed(() => store.connections.filter((c) => TRANSFER_SQL_TYPES.has(c.db_type)));
const sqlConnections = computed(() => store.connections.filter((c) => supportsTransfer(c.db_type)));
// Source state
const sourceConnectionId = ref("");