Skip to content

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

feat(sql-editor): display procedures and functions (#11678)

Liu Jid0ca6800537f
diff --git a/frontend/package.json b/frontend/package.json
index 527390ff34..9f2f826d7c 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -13,7 +13,7 @@
"lint": "eslint --cache --ext .js,.ts,.tsx,.vue src",
"lint:fix": "eslint --cache --ext .js,.ts,.tsx,.vue --fix src",
"bundle-visualize": "vite-bundle-visualizer -c vite.config.ts",
- "type-check": "vue-tsc --build --force",
+ "type-check": "export NODE_OPTIONS=--max_old_space_size=8000 && vue-tsc --build --force",
"test": "vitest run --passWithNoTests",
"coverage": "vitest --coverage",
"postinstall": "npm run copy:monaco-workers && monaco-treemending",
diff --git a/frontend/src/components/Icon/FunctionIcon.vue b/frontend/src/components/Icon/FunctionIcon.vue
new file mode 100644
index 0000000000..1051145ff8
--- /dev/null
+++ b/frontend/src/components/Icon/FunctionIcon.vue
@@ -0,0 +1,7 @@
+<template>
+ <SquareFunctionIcon class="opacity-75" />
+</template>
+
+<script setup lang="ts">
+import { SquareFunctionIcon } from "lucide-vue-next";
+</script>
diff --git a/frontend/src/components/Icon/ProcedureIcon.vue b/frontend/src/components/Icon/ProcedureIcon.vue
new file mode 100644
index 0000000000..e203e6bd91
--- /dev/null
+++ b/frontend/src/components/Icon/ProcedureIcon.vue
@@ -0,0 +1,7 @@
+<template>
+ <ParenthesesIcon class="opacity-75" />
+</template>
+
+<script setup lang="ts">
+import { ParenthesesIcon } from "lucide-vue-next";
+</script>
diff --git a/frontend/src/components/Icon/index.ts b/frontend/src/components/Icon/index.ts
index 2eb3cbdcfd..9385c0827b 100644
--- a/frontend/src/components/Icon/index.ts
+++ b/frontend/src/components/Icon/index.ts
@@ -1,8 +1,10 @@
import ColumnIcon from "./ColumnIcon.vue";
import DatabaseIcon from "./DatabaseIcon.vue";
import EngineIcon from "./EngineIcon.vue";
+import FunctionIcon from "./FunctionIcon.vue";
import IndexIcon from "./IndexIcon.vue";
import PrimaryKeyIcon from "./PrimaryKeyIcon.vue";
+import ProcedureIcon from "./ProcedureIcon.vue";
import SchemaIcon from "./SchemaIcon.vue";
import SkipIcon from "./SkipIcon.vue";
import TableIcon from "./TableIcon.vue";
@@ -16,6 +18,8 @@ export {
SchemaIcon,
TableIcon,
ViewIcon,
+ ProcedureIcon,
+ FunctionIcon,
IndexIcon,
PrimaryKeyIcon,
ColumnIcon,
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index b4cddb4883..5604d11e6a 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1251,7 +1251,8 @@
"start-to-sync-schema": "Start to sync schema",
"failed-to-sync-schema": "Failed to sync schema",
"successfully-synced-schema": "Successfully synced schema",
- "create": "Create database"
+ "create": "Create database",
+ "procedures": "Procedures"
},
"instance": {
"select": "Select instance",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 433d2c6fda..ce0e132c0a 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1251,7 +1251,8 @@
"start-to-sync-schema": "Comenzar a sincronizar el esquema",
"failed-to-sync-schema": "No se pudo sincronizar el esquema",
"successfully-synced-schema": "Esquema sincronizado correctamente",
- "create": "Crear base de datos"
+ "create": "Crear base de datos",
+ "procedures": "Trámites"
},
"instance": {
"select": "Seleccionar instancia",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index cc060256f4..865998acdc 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1251,7 +1251,8 @@
"start-to-sync-schema": "スキーマ同期に失敗しました",
"failed-to-sync-schema": "スキーマを正常に同期しました",
"successfully-synced-schema": "インスタンスを選択してください",
- "create": "データベースの作成"
+ "create": "データベースの作成",
+ "procedures": "手順"
},
"instance": {
"select": "データベースユーザーを選択してください",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 8dd61f0d7d..4fdca269ec 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1251,7 +1251,8 @@
"start-to-sync-schema": "Bắt đầu đồng bộ hóa lược đồ",
"failed-to-sync-schema": "Không thể đồng bộ hóa lược đồ",
"successfully-synced-schema": "Đã đồng bộ hóa lược đồ thành công",
- "create": "Tạo nên cơ sở dữ liệu"
+ "create": "Tạo nên cơ sở dữ liệu",
+ "procedures": "Thủ tục"
},
"instance": {
"select": "Chọn phiên bản",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 49e6f77042..b1a7568ce5 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1251,7 +1251,8 @@
"start-to-sync-schema": "开始同步 schema",
"failed-to-sync-schema": "同步 schema 失败",
"successfully-synced-schema": "Schema 同步完成",
- "create": "创建数据库"
+ "create": "创建数据库",
+ "procedures": "存储过程"
},
"instance": {
"select": "选择实例",
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/CodeViewer.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/CodeViewer.vue
new file mode 100644
index 0000000000..e887887234
--- /dev/null
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/CodeViewer.vue
@@ -0,0 +1,83 @@
+<template>
+ <div class="w-[32rem] h-[20rem] flex flex-col gap-y-2">
+ <div class="flex flex-row content-justify items-center gap-x-2">
+ <div class="textlabel flex-1 truncate">
+ {{ name }}
+ </div>
+ <div class="flex flex-row justify-end items-center">
+ <NCheckbox v-if="!formatted.error" v-model:checked="format">
+ {{ $t("sql-editor.format") }}
+ </NCheckbox>
+ </div>
+ </div>
+ <div class="w-full flex-1 relative">
+ <MonacoEditor
+ :content="format ? formatted.data : code"
+ :readonly="true"
+ class="border w-full h-full"
+ />
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { computedAsync, useLocalStorage } from "@vueuse/core";
+import { NCheckbox } from "naive-ui";
+import { computed } from "vue";
+import { MonacoEditor } from "@/components/MonacoEditor";
+import formatSQL from "@/components/MonacoEditor/sqlFormatter";
+import type { ComposedDatabase } from "@/types";
+import { dialectOfEngineV1 } from "@/types";
+import { Engine } from "@/types/proto/v1/common";
+import type {
+ DatabaseMetadata,
+ SchemaMetadata,
+} from "@/types/proto/v1/database_service";
+
+const props = defineProps<{
+ db: ComposedDatabase;
+ database: DatabaseMetadata;
+ schema: SchemaMetadata;
+ name: string;
+ code: string;
+}>();
+const format = useLocalStorage<boolean>(
+ "bb.sql-editor.schema-hover-panel.code-viewer.format",
+ false
+);
+const instanceEngine = computed(() => props.db.instanceEntity.engine);
+
+const hasSchemaProperty = computed(() => {
+ return [Engine.POSTGRES, Engine.RISINGWAVE].includes(instanceEngine.value);
+});
+
+const name = computed(() => {
+ const { schema, name } = props;
+ if (hasSchemaProperty.value) {
+ return `${schema.name}.${name}`;
+ }
+ return name;
+});
+
+const formatted = computedAsync(
+ async () => {
+ const sql = props.code;
+ try {
+ const result = await formatSQL(
+ sql,
+ dialectOfEngineV1(instanceEngine.value)
+ );
+ return result;
+ } catch (err) {
+ return {
+ error: err,
+ data: sql,
+ };
+ }
+ },
+ {
+ error: null,
+ data: props.code,
+ }
+);
+</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/FunctionInfo.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/FunctionInfo.vue
new file mode 100644
index 0000000000..950533431b
--- /dev/null
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/FunctionInfo.vue
@@ -0,0 +1,26 @@
+<template>
+ <CodeViewer
+ :db="db"
+ :database="database"
+ :schema="schema"
+ :name="$props.function.name"
+ :code="$props.function.definition"
+ />
+</template>
+
+<script setup lang="ts">
+import type { ComposedDatabase } from "@/types";
+import type {
+ DatabaseMetadata,
+ SchemaMetadata,
+ FunctionMetadata,
+} from "@/types/proto/v1/database_service";
+import CodeViewer from "./CodeViewer.vue";
+
+defineProps<{
+ db: ComposedDatabase;
+ database: DatabaseMetadata;
+ schema: SchemaMetadata;
+ function: FunctionMetadata;
+}>();
+</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/HoverPanel.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/HoverPanel.vue
index 3c70e4763c..ba0856fd3f 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/HoverPanel.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/HoverPanel.vue
@@ -46,6 +46,20 @@
:schema="state.schema"
:view="state.view"
/>
+ <ProcedureInfo
+ v-else-if="state.procedure"
+ :db="state.db"
+ :database="state.database"
+ :schema="state.schema"
+ :procedure="state.procedure"
+ />
+ <FunctionInfo
+ v-else-if="state.function"
+ :db="state.db"
+ :database="state.database"
+ :schema="state.schema"
+ :function="state.function"
+ />
</template>
</div>
</template>
@@ -58,6 +72,8 @@ import type { Position } from "@/types";
import { minmax } from "@/utils";
import ColumnInfo from "./ColumnInfo.vue";
import ExternalTableInfo from "./ExternalTableInfo.vue";
+import FunctionInfo from "./FunctionInfo.vue";
+import ProcedureInfo from "./ProcedureInfo.vue";
import TableInfo from "./TableInfo.vue";
import TablePartitionInfo from "./TablePartitionInfo.vue";
import ViewInfo from "./ViewInfo.vue";
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/ProcedureInfo.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/ProcedureInfo.vue
new file mode 100644
index 0000000000..ce365a483a
--- /dev/null
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/ProcedureInfo.vue
@@ -0,0 +1,26 @@
+<template>
+ <CodeViewer
+ :db="db"
+ :database="database"
+ :schema="schema"
+ :name="procedure.name"
+ :code="procedure.definition"
+ />
+</template>
+
+<script setup lang="ts">
+import type { ComposedDatabase } from "@/types";
+import type {
+ DatabaseMetadata,
+ SchemaMetadata,
+ ProcedureMetadata,
+} from "@/types/proto/v1/database_service";
+import CodeViewer from "./CodeViewer.vue";
+
+defineProps<{
+ db: ComposedDatabase;
+ database: DatabaseMetadata;
+ schema: SchemaMetadata;
+ procedure: ProcedureMetadata;
+}>();
+</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/ViewInfo.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/ViewInfo.vue
index f02193bd29..984796ff22 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/ViewInfo.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/ViewInfo.vue
@@ -1,83 +1,26 @@
<template>
- <div class="w-[32rem] h-[20rem] flex flex-col gap-y-2">
- <div class="flex flex-row content-justify items-center gap-x-2">
- <div class="textlabel flex-1 truncate">
- {{ name }}
- </div>
- <div class="flex flex-row justify-end items-center">
- <NCheckbox v-if="!formatted.error" v-model:checked="format">
- {{ $t("sql-editor.format") }}
- </NCheckbox>
- </div>
- </div>
- <div class="w-full flex-1 relative">
- <MonacoEditor
- :content="format ? formatted.data : view.definition"
- :readonly="true"
- class="border w-full h-full"
- />
- </div>
- </div>
+ <CodeViewer
+ :db="db"
+ :database="database"
+ :schema="schema"
+ :name="view.name"
+ :code="view.definition"
+ />
</template>
<script setup lang="ts">
-import { computedAsync, useLocalStorage } from "@vueuse/core";
-import { NCheckbox } from "naive-ui";
-import { computed } from "vue";
-import { MonacoEditor } from "@/components/MonacoEditor";
-import formatSQL from "@/components/MonacoEditor/sqlFormatter";
import type { ComposedDatabase } from "@/types";
-import { dialectOfEngineV1 } from "@/types";
-import { Engine } from "@/types/proto/v1/common";
import type {
DatabaseMetadata,
SchemaMetadata,
ViewMetadata,
} from "@/types/proto/v1/database_service";
+import CodeViewer from "./CodeViewer.vue";
-const props = defineProps<{
+defineProps<{
db: ComposedDatabase;
database: DatabaseMetadata;
schema: SchemaMetadata;
view: ViewMetadata;
}>();
-const format = useLocalStorage<boolean>(
- "bb.sql-editor.schema-hover-panel.view-info.format",
- false
-);
-const instanceEngine = computed(() => props.db.instanceEntity.engine);
-
-const hasSchemaProperty = computed(() => {
- return [Engine.POSTGRES, Engine.RISINGWAVE].includes(instanceEngine.value);
-});
-
-const name = computed(() => {
- const { schema, view } = props;
- if (hasSchemaProperty.value) {
- return `${schema.name}.${view.name}`;
- }
- return view.name;
-});
-
-const formatted = computedAsync(
- async () => {
- const sql = props.view.definition;
- try {
- const result = await formatSQL(
- sql,
- dialectOfEngineV1(instanceEngine.value)
- );
- return result;
- } catch (err) {
- return {
- error: err,
- data: sql,
- };
- }
- },
- {
- error: null,
- data: props.view.definition,
- }
-);
</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/hover-state.ts b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/hover-state.ts
index a8cdba18bb..c5d06d0c46 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/hover-state.ts
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/HoverPanel/hover-state.ts
@@ -3,6 +3,8 @@ import type {
ColumnMetadata,
DatabaseMetadata,
ExternalTableMetadata,
+ FunctionMetadata,
+ ProcedureMetadata,
SchemaMetadata,
TableMetadata,
TablePartitionMetadata,
@@ -24,6 +26,8 @@ export type HoverState = {
view?: ViewMetadata;
column?: ColumnMetadata;
partition?: TablePartitionMetadata;
+ procedure?: ProcedureMetadata;
+ function?: FunctionMetadata;
};
export const useHoverStateContext = () => {
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
index 699291e6fd..497bdc1c4e 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
@@ -195,10 +195,18 @@ const nodeProps = ({ option }: { option: TreeOption }) => {
type === "external-table" ||
type === "column" ||
type === "view" ||
- type === "partition-table"
+ type === "partition-table" ||
+ type === "procedure" ||
+ type === "function"
) {
const target = node.meta.target as NodeTarget<
- "table" | "external-table" | "column" | "view" | "partition-table"
+ | "table"
+ | "external-table"
+ | "column"
+ | "view"
+ | "partition-table"
+ | "procedure"
+ | "function"
>;
if (hoverState.value) {
updateHoverState(target, "before", 0 /* overrideDelay */);
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/FunctionNode.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/FunctionNode.vue
new file mode 100644
index 0000000000..e753f46b2b
--- /dev/null
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/FunctionNode.vue
@@ -0,0 +1,24 @@
+<template>
+ <div class="flex items-center max-w-full overflow-hidden gap-x-1">
+ <FunctionIcon class="w-4 h-4" />
+ <HighlightLabelText
+ :text="target.function.name"
+ :keyword="keyword"
+ class="flex-1 truncate"
+ />
+ </div>
+</template>
+
+<script setup lang="ts">
+import { computed } from "vue";
+import { FunctionIcon } from "@/components/Icon";
+import type { TreeNode } from "../common";
+import HighlightLabelText from "./HighlightLabelText.vue";
+
+const props = defineProps<{
+ node: TreeNode;
+ keyword: string;
+}>();
+
+const target = computed(() => (props.node as TreeNode<"function">).meta.target);
+</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/Label.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/Label.vue
index 34f8eac90b..cf8a39727a 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/Label.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/Label.vue
@@ -20,6 +20,12 @@
<template v-if="type === 'view'">
<ViewNode :node="node" :keyword="keyword" />
</template>
+ <template v-if="type === 'procedure'">
+ <ProcedureNode :node="node" :keyword="keyword" />
+ </template>
+ <template v-if="type === 'function'">
+ <FunctionNode :node="node" :keyword="keyword" />
+ </template>
<template v-if="type === 'expandable-text'">
<TextNode :node="node" :keyword="keyword" />
</template>
@@ -35,7 +41,9 @@ import ColumnNode from "./ColumnNode.vue";
import DatabaseNode from "./DatabaseNode.vue";
import DummyNode from "./DummyNode.vue";
import ExternalTableNode from "./ExternalTableNode.vue";
+import FunctionNode from "./FunctionNode.vue";
import PartitionTableNode from "./PartitionTableNode.vue";
+import ProcedureNode from "./ProcedureNode.vue";
import SchemaNode from "./SchemaNode.vue";
import TableNode from "./TableNode.vue";
import TextNode from "./TextNode.vue";
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/ProcedureNode.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/ProcedureNode.vue
new file mode 100644
index 0000000000..3bc763e3b4
--- /dev/null
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/ProcedureNode.vue
@@ -0,0 +1,26 @@
+<template>
+ <div class="flex items-center max-w-full overflow-hidden gap-x-1">
+ <ProcedureIcon class="w-4 h-4" />
+ <HighlightLabelText
+ :text="target.procedure.name"
+ :keyword="keyword"
+ class="flex-1 truncate"
+ />
+ </div>
+</template>
+
+<script setup lang="ts">
+import { computed } from "vue";
+import { ProcedureIcon } from "@/components/Icon";
+import type { TreeNode } from "../common";
+import HighlightLabelText from "./HighlightLabelText.vue";
+
+const props = defineProps<{
+ node: TreeNode;
+ keyword: string;
+}>();
+
+const target = computed(
+ () => (props.node as TreeNode<"procedure">).meta.target
+);
+</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/common.ts b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/common.ts
index 13e5cf89d0..4fe6447fb1 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/common.ts
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/common.ts
@@ -7,6 +7,8 @@ import type {
ColumnMetadata,
DatabaseMetadata,
ExternalTableMetadata,
+ FunctionMetadata,
+ ProcedureMetadata,
SchemaMetadata,
TableMetadata,
TablePartitionMetadata,
@@ -19,6 +21,8 @@ export type NodeType =
| "table"
| "external-table"
| "view"
+ | "procedure"
+ | "function"
| "partition-table"
| "column"
| "expandable-text" // Text nodes to display "Tables / Views / Functions / Triggers" etc.
@@ -50,6 +54,12 @@ export type RichPartitionTableMetadata = RichTableMetadata & {
export type RichViewMetadata = RichSchemaMetadata & {
view: ViewMetadata;
};
+export type RichProcedureMetadata = RichSchemaMetadata & {
+ procedure: ProcedureMetadata;
+};
+export type RichFunctionMetadata = RichSchemaMetadata & {
+ function: FunctionMetadata;
+};
export type TextTarget<E extends boolean = any, S extends boolean = any> = {
expandable: E;
id: string;
@@ -76,11 +86,15 @@ export type NodeTarget<T extends NodeType = NodeType> = T extends "database"
? RichPartitionTableMetadata
: T extends "view"
? RichViewMetadata
- : T extends "expandable-text"
- ? TextTarget<true, any>
- : T extends "error"
- ? ErrorTarget
- : never;
+ : T extends "procedure"
+ ? RichProcedureMetadata
+ : T extends "function"
+ ? RichFunctionMetadata
+ : T extends "expandable-text"
+ ? TextTarget<true, any>
+ : T extends "error"
+ ? ErrorTarget
+ : never;
export type TreeState = "UNSET" | "LOADING" | "READY";
@@ -107,6 +121,8 @@ export const ExpandableNodeTypes: readonly NodeType[] = [
export const LeafNodeTypes: readonly NodeType[] = [
"column",
"view",
+ "procedure",
+ "function",
"error",
] as const;
@@ -162,6 +178,20 @@ export const keyForNodeTarget = <T extends NodeType>(
const { db, schema, view } = target as NodeTarget<"view">;
return [db.name, `schemas/${schema.name}`, `views/${view.name}`].join("/");
}
+ if (type === "procedure") {
+ const { db, schema, procedure } = target as NodeTarget<"procedure">;
+ return [
+ db.name,
+ `schemas/${schema.name}`,
+ `procedures/${procedure.name}`,
+ ].join("/");
+ }
+ if (type === "procedure") {
+ const { db, schema, function: func } = target as NodeTarget<"function">;
+ return [db.name, `schemas/${schema.name}`, `functions/${func.name}`].join(
+ "/"
+ );
+ }
if (type === "expandable-text") {
const { id } = target as NodeTarget<"expandable-text">;
return `expandableTexts/${id}`;
@@ -199,6 +229,12 @@ const readableTextForNodeTarget = <T extends NodeType>(
if (type === "view") {
return (target as RichViewMetadata).view.name;
}
+ if (type === "procedure") {
+ return (target as RichProcedureMetadata).procedure.name;
+ }
+ if (type === "function") {
+ return (target as RichFunctionMetadata).function.name;
+ }
if (type === "expandable-text") {
const { text, searchable } = target as TextTarget;
if (!searchable) return "";
@@ -236,7 +272,7 @@ export const mapTreeNodeByType = <T extends NodeType>(
};
const createDummyNode = (
- type: "column" | "table" | "view",
+ type: "column" | "table" | "view" | "procedure" | "function",
parent: TreeNode,
error: unknown | undefined = undefined
) => {
@@ -381,6 +417,32 @@ const mapViewNodes = (
}
return children;
};
+const mapProcedureNodes = (
+ target: NodeTarget<"schema">,
+ parent: TreeNode<"expandable-text">
+) => {
+ const { schema } = target;
+ const children = schema.procedures.map((procedure) =>
+ mapTreeNodeByType("procedure", { ...target, procedure }, parent)
+ );
+ if (children.length === 0) {
+ return [createDummyNode("procedure", parent)];
+ }
+ return children;
+};
+const mapFunctionNodes = (
+ target: NodeTarget<"schema">,
+ parent: TreeNode<"expandable-text">
+) => {
+ const { schema } = target;
+ const children = schema.functions.map((func) =>
+ mapTreeNodeByType("function", { ...target, function: func }, parent)
+ );
+ if (children.length === 0) {
+ return [createDummyNode("function", parent)];
+ }
+ return children;
+};
const buildSchemaNodeChildren = (
target: NodeTarget<"schema">,
parent: TreeNode<"schema"> | TreeNode<"database">
@@ -389,7 +451,9 @@ const buildSchemaNodeChildren = (
if (
schema.tables.length === 0 &&
schema.externalTables.length === 0 &&
- schema.views.length === 0
+ schema.views.length === 0 &&
+ schema.procedures.length === 0 &&
+ schema.functions.length === 0
) {
return [createDummyNode("table", parent)];
}
@@ -426,6 +490,24 @@ const buildSchemaNodeChildren = (
viewsNode.children = mapViewNodes(target, viewsNode);
children.push(viewsNode);
}
+
+ // Show "Procedures" if there's at least 1 procedure
+ if (schema.procedures.length > 0) {
+ const procedureNode = createExpandableTextNode("procedure", parent, () =>
+ t("db.procedures")
+ );
+ procedureNode.children = mapProcedureNodes(target, procedureNode);
+ children.push(procedureNode);
+ }
+
+ // Show "Functions" if there's at least 1 function
+ if (schema.functions.length > 0) {
+ const functionNode = createExpandableTextNode("function", parent, () =>
+ t("db.functions")
+ );
+ functionNode.children = mapFunctionNodes(target, functionNode);
+ children.push(functionNode);
+ }
return children;
};
export const buildDatabaseSchemaTree = (