diff --git a/apps/desktop/src/components/objects/DdlViewDialog.vue b/apps/desktop/src/components/objects/DdlViewDialog.vue new file mode 100644 index 000000000..0ae73bf14 --- /dev/null +++ b/apps/desktop/src/components/objects/DdlViewDialog.vue @@ -0,0 +1,211 @@ + + + + + + + DDL - {{ props.tableName }} + + + + + {{ t("contextMenu.viewDdlLoading") }} + + + {{ ddlError }} + + + {{ t("common.retry") }} + + + + + + + + + {{ t("common.close") }} + + + {{ t("grid.copyDdl") }} + + + + + diff --git a/apps/desktop/src/components/objects/ObjectBrowser.vue b/apps/desktop/src/components/objects/ObjectBrowser.vue index 98103e30e..38ea6c577 100644 --- a/apps/desktop/src/components/objects/ObjectBrowser.vue +++ b/apps/desktop/src/components/objects/ObjectBrowser.vue @@ -48,7 +48,7 @@ import type { ConnectionConfig, ForeignKeyInfo, ObjectInfo, ObjectSourceKind } f import { sortTablesByFkDependency, type TableWithFk } from "@/lib/tableDependencySort"; import { isSchemaAware } from "@/lib/databaseCapabilities"; import { supportsSchemaDiagram, supportsTableImport, supportsTableStructureEditing, supportsTableTruncate } from "@/lib/databaseFeatureSupport"; -import { connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection, tableStructureDatabaseTypeForConnection } from "@/lib/jdbcDialect"; +import { codeMirrorSqlDialect, connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection, tableStructureDatabaseTypeForConnection } from "@/lib/jdbcDialect"; import { buildTableSelectSql } from "@/lib/tableSelectSql"; import { buildDropObjectSql, buildDuplicateTableStructureSql, buildEmptyTableSql, buildTruncateTableSql, type TableAdminSqlOptions } from "@/lib/dbAdminSql"; import { useToast } from "@/composables/useToast"; @@ -65,6 +65,7 @@ import { useExportTracker, type ExportTask } from "@/composables/useExportTracke import { useSettingsStore } from "@/stores/settingsStore"; import { useQueryStore } from "@/stores/queryStore"; import QueryEditor from "@/components/editor/QueryEditor.vue"; +import DdlViewDialog from "./DdlViewDialog.vue"; import type { SqlFormatDialect } from "@/lib/sqlFormatter"; import { isCancelSearchShortcut } from "@/lib/keyboardShortcuts"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; @@ -130,6 +131,8 @@ const duplicateTarget = ref(null); const duplicateTableName = ref(""); const showProcedureExecutionConfirm = ref(false); const procedureExecutionTarget = ref(null); +const ddlDialogTarget = ref(null); +const showDdlDialog = ref(false); const selectedTableIds = ref>(new Set()); const expandedPartitionParentIds = ref>(new Set()); const showBatchDropConfirm = ref(false); @@ -150,11 +153,7 @@ const canOpenStructureEditor = computed(() => supportsTableStructureEditing(tabl const canOpenDiagram = computed(() => !!props.database && supportsSchemaDiagram(effectiveDatabaseType.value)); const canOpenTableImport = computed(() => !!props.database && supportsTableImport(effectiveDatabaseType.value)); const supportsTruncateTable = computed(() => supportsTableTruncate(effectiveDatabaseType.value)); -const sourceDialect = computed<"mysql" | "postgres" | "sqlserver">(() => { - if (effectiveDatabaseType.value === "postgres" || effectiveDatabaseType.value === "gaussdb" || effectiveDatabaseType.value === "kwdb" || effectiveDatabaseType.value === "opengauss") return "postgres"; - if (effectiveDatabaseType.value === "sqlserver") return "sqlserver"; - return "mysql"; -}); +const sourceDialect = computed(() => codeMirrorSqlDialect(effectiveDatabaseType.value)); const sourceFormatDialect = computed(() => { switch (effectiveDatabaseType.value) { case "mysql": @@ -1127,6 +1126,14 @@ function exportDataSubmenu(item: ObjectBrowserRow): ContextMenuItem { function getTableMenuItems(item: ObjectBrowserRow): ContextMenuItem[] { return [ { label: t("contextMenu.viewData"), action: () => openRow(item), icon: Table2 }, + { + label: t("contextMenu.viewDdl"), + action: () => { + ddlDialogTarget.value = item; + showDdlDialog.value = true; + }, + icon: FileCode, + }, ...(canOpenStructureEditor.value ? [{ label: t("contextMenu.editStructure"), action: () => openStructureEditor(item), icon: PencilRuler }] : []), ...(canRename(item) ? [{ label: t("contextMenu.renameObject"), action: () => requestRename(item), icon: Pencil }] : []), { label: t("contextMenu.newQuery"), action: () => openNewQuery(item), icon: TerminalSquare }, @@ -1483,6 +1490,8 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] { + +
{{ ddlError }}