Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: show view schema in SQL editor (#15668)

rebelice918b6ff2b311
diff --git a/frontend/src/components/TableSchemaViewer.vue b/frontend/src/components/TableSchemaViewer.vue
index 23ae47f82f..e008eef759 100644
--- a/frontend/src/components/TableSchemaViewer.vue
+++ b/frontend/src/components/TableSchemaViewer.vue
@@ -52,7 +52,8 @@ import { hasSchemaProperty } from "@/utils";
const props = defineProps<{
database: ComposedDatabase;
schema?: string;
- table?: string;
+ object?: string;
+ type?: GetSchemaStringRequest_ObjectType;
}>();
const { t } = useI18n();
@@ -67,11 +68,11 @@ const engine = computed(() => {
});
const resourceName = computed(() => {
- if (props.table) {
+ if (props.object) {
if (hasSchemaProperty(engine.value)) {
- return `${props.schema}.${props.table}`;
+ return `${props.schema}.${props.object}`;
} else {
- return props.table;
+ return props.object;
}
}
if (props.schema) {
@@ -84,9 +85,9 @@ onMounted(async () => {
nextTick(async () => {
const response = await databaseServiceClient.getSchemaString({
name: props.database.name,
- type: GetSchemaStringRequest_ObjectType.TABLE,
+ type: props.type,
schema: props.schema,
- object: props.table,
+ object: props.object,
})
schemaString.value = response.schemaString.trim();
});
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx
index ee589665ee..be18aa8e63 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx
@@ -29,10 +29,11 @@ import {
type SQLEditorConnection,
} from "@/types";
import { Engine } from "@/types/proto/v1/common";
-import type {
- SchemaMetadata,
- TableMetadata,
- ViewMetadata,
+import {
+ GetSchemaStringRequest_ObjectType,
+ type SchemaMetadata,
+ type TableMetadata,
+ type ViewMetadata,
} from "@/types/proto/v1/database_service";
import { DataSource, DataSourceType } from "@/types/proto/v1/instance_service";
import {
@@ -407,6 +408,25 @@ export const useDropdown = () => {
copyToClipboard(name);
},
});
+ if (type === 'view') {
+ const {db, schema, view} = target as NodeTarget<"view">;
+ if (supportGetStringSchema(db.instanceResource.engine)) {
+ items.push({
+ key: "view-schema-text",
+ label: t("sql-editor.view-schema-text"),
+ icon: () => <CodeIcon class="w-4 h-4" />,
+ onSelect: () => {
+ schemaViewer.value = {
+ database: db,
+ schema: schema.name,
+ object: view.name,
+ type: GetSchemaStringRequest_ObjectType.VIEW
+ };
+ },
+ });
+ }
+ }
+
if (type === "table") {
const { db, schema, table } = target as NodeTarget<"table">;
@@ -429,7 +449,8 @@ export const useDropdown = () => {
schemaViewer.value = {
database: db,
schema: schema.name,
- table: table.name,
+ object: table.name,
+ type: GetSchemaStringRequest_ObjectType.TABLE,
};
},
});
diff --git a/frontend/src/views/sql-editor/context.ts b/frontend/src/views/sql-editor/context.ts
index 74f17c94a1..bf885d9a58 100644
--- a/frontend/src/views/sql-editor/context.ts
+++ b/frontend/src/views/sql-editor/context.ts
@@ -5,6 +5,7 @@ import { inject, provide, ref } from "vue";
import { useSQLEditorStore } from "@/store";
import type { ComposedDatabase, SQLEditorTab } from "@/types";
import type { Worksheet } from "@/types/proto/v1/worksheet_service";
+import type { GetSchemaStringRequest_ObjectType } from "@/types/proto/v1/database_service";
export type AsidePanelTab = "SCHEMA" | "WORKSHEET" | "HISTORY";
@@ -46,7 +47,8 @@ export type SQLEditorContext = {
| {
database: ComposedDatabase;
schema?: string;
- table?: string;
+ object?: string;
+ type?: GetSchemaStringRequest_ObjectType;
}
| undefined
>;