feat(objects): add view DDL action

This commit is contained in:
t8y2 committed 2026-05-21 12:57:20 +08:00
1 parent 895c0d58af
commit 2bf01c5cc7
7 files changed
+152

No files matched your search

@@ -41,6 +41,7 @@ import {
supportsSourceBackedRoutineRename,
} from "@/lib/objectSourceEditor";
import { buildRenameObjectSql, supportsObjectRename } from "@/lib/objectRenameSql";
import { buildViewDdl } from "@/lib/viewDdl";
import { useConnectionStore } from "@/stores/connectionStore";
import { useQueryStore } from "@/stores/queryStore";
import QueryEditor from "@/components/editor/QueryEditor.vue";
@@ -215,6 +216,29 @@ async function openSource(row: ObjectBrowserRow) {
}
}
async function openViewDdl(row: ObjectBrowserRow) {
if (row.type !== "VIEW") return;
try {
const result = await api.getObjectSource(
props.connection.id,
props.database,
row.schema || selectedSchema.value || props.database,
row.name,
"VIEW",
);
const ddl = buildViewDdl({
databaseType: props.connection.db_type,
schema: row.schema || selectedSchema.value || props.database,
name: row.name,
source: result.source,
});
const tabId = queryStore.createTab(props.connection.id, props.database, `DDL - ${row.name}`);
queryStore.updateSql(tabId, ddl);
} catch (e: any) {
toast(e?.message || String(e), 5000);
}
}
function openNewQuery(row: ObjectBrowserRow) {
const tabId = queryStore.createTab(props.connection.id, props.database, row.name);
queryStore.updateSql(
@@ -659,6 +683,9 @@ watch(
<ContextMenuItem @click="openSource(item)">
<Code2 class="w-4 h-4 mr-2" /> {{ t("contextMenu.viewSource") }}
</ContextMenuItem>
<ContextMenuItem @click="openViewDdl(item)">
<ScrollText class="w-4 h-4 mr-2" /> {{ t("contextMenu.viewDdl") }}
</ContextMenuItem>
<ContextMenuItem v-if="canRename(item)" @click="requestRename(item)">
<Pencil class="w-4 h-4 mr-2" /> {{ t("contextMenu.renameObject") }}
</ContextMenuItem>