Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat(table-info): show column default values

LRcoding63ea5f1fd88a
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index ecdb633e64..c68b1d9848 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -62,6 +62,7 @@ import TemporalCellEditor from "@/components/grid/TemporalCellEditor.vue";
import EnumCellEditor from "@/components/grid/EnumCellEditor.vue";
import type { QueryResult, ColumnInfo, DatabaseType, ForeignKeyInfo, IndexInfo, TriggerInfo, TableInfoTab } from "@/types/database";
import { tableObjectSourceKind } from "@/lib/table/tableObjectSourceKind";
+import { tableColumnDefaultDisplayValue } from "@/lib/table/tableColumnDefaultPresentation";
import * as api from "@/lib/backend/api";
import { formatElapsedSeconds } from "@/lib/common/elapsedTime";
import { dataGridCellDisplayText, dataGridCellEditorText } from "@/lib/dataGrid/dataGridCellCoercion";
@@ -8477,6 +8478,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
<th class="text-left text-nowrap font-medium px-3 py-2">{{ t("grid.columnName") }}</th>
<th class="text-left text-nowrap font-medium px-3 py-2">{{ t("grid.columnType") }}</th>
<th class="text-left text-nowrap font-medium px-3 py-2">{{ t("grid.tableInfoNullable") }}</th>
+ <th class="text-left text-nowrap font-medium px-3 py-2">{{ t("structureEditor.defaultValue") }}</th>
</tr>
</thead>
<tbody>
@@ -8503,6 +8505,9 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
</td>
<td class="px-3 py-2 font-mono text-[11px] text-muted-foreground">{{ column.data_type }}</td>
<td class="px-3 py-2">{{ column.is_nullable ? "YES" : "NO" }}</td>
+ <td data-table-info-column-default class="max-w-56 px-3 py-2 font-mono text-[11px]" :class="{ 'text-muted-foreground/70': column.column_default == null }" :title="column.column_default ?? undefined">
+ <span class="block max-w-56 truncate">{{ tableColumnDefaultDisplayValue(column.column_default) }}</span>
+ </td>
</tr>
</tbody>
</table>
diff --git a/apps/desktop/src/components/objects/ObjectBrowser.vue b/apps/desktop/src/components/objects/ObjectBrowser.vue
index dd612b24a8..40a145a794 100644
--- a/apps/desktop/src/components/objects/ObjectBrowser.vue
+++ b/apps/desktop/src/components/objects/ObjectBrowser.vue
@@ -96,6 +96,7 @@ import {
import { resolveRowClickAction, shouldDeferSingleClick, type ObjectBrowserRowAction } from "@/lib/table/objectBrowserRowAction";
import { createSidePanelRequestGuard } from "@/lib/table/sidePanelRequestGuard";
import { runBatchTableTruncate } from "@/lib/table/batchTableTruncate";
+import { tableColumnDefaultDisplayValue } from "@/lib/table/tableColumnDefaultPresentation";
type ObjectFilter = "all" | "tables" | "views" | "materializedViews" | "procedures" | "functions" | "sequences" | "packages";
type ObjectBrowserColumnKey = "select" | "name" | "type" | "estimatedRows" | "totalBytes" | "created_at" | "updated_at" | "comment";
@@ -2726,6 +2727,7 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
<th class="text-left text-nowrap font-medium px-3 py-2">{{ t("grid.columnName") }}</th>
<th class="text-left text-nowrap font-medium px-3 py-2">{{ t("grid.columnType") }}</th>
<th class="text-left text-nowrap font-medium px-3 py-2">{{ t("grid.tableInfoNullable") }}</th>
+ <th class="text-left text-nowrap font-medium px-3 py-2">{{ t("structureEditor.defaultValue") }}</th>
</tr>
</thead>
<tbody>
@@ -2742,6 +2744,9 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
</td>
<td class="px-3 py-2 font-mono text-[11px] text-muted-foreground">{{ column.data_type }}</td>
<td class="px-3 py-2">{{ column.is_nullable ? "YES" : "NO" }}</td>
+ <td data-table-info-column-default class="max-w-56 px-3 py-2 font-mono text-[11px]" :class="{ 'text-muted-foreground/70': column.column_default == null }" :title="column.column_default ?? undefined">
+ <span class="block max-w-56 truncate">{{ tableColumnDefaultDisplayValue(column.column_default) }}</span>
+ </td>
</tr>
</tbody>
</table>
diff --git a/apps/desktop/src/lib/table/tableColumnDefaultPresentation.ts b/apps/desktop/src/lib/table/tableColumnDefaultPresentation.ts
new file mode 100644
index 0000000000..6374ae7263
--- /dev/null
+++ b/apps/desktop/src/lib/table/tableColumnDefaultPresentation.ts
@@ -0,0 +1,4 @@
+/** Preserve database-specific default expressions exactly; only absent metadata gets a placeholder. */
+export function tableColumnDefaultDisplayValue(value: string | null | undefined): string {
+ return value ?? "—";
+}
diff --git a/packages/app-tests/tableInfoDefaultValue.test.ts b/packages/app-tests/tableInfoDefaultValue.test.ts
new file mode 100644
index 0000000000..11eea598ea
--- /dev/null
+++ b/packages/app-tests/tableInfoDefaultValue.test.ts
@@ -0,0 +1,31 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { test } from "vitest";
+import { compileTemplate, parse } from "vue/compiler-sfc";
+import { tableColumnDefaultDisplayValue } from "@/lib/table/tableColumnDefaultPresentation";
+
+const tableInfoSurfaces = ["apps/desktop/src/components/objects/ObjectBrowser.vue", "apps/desktop/src/components/grid/DataGrid.vue"];
+
+test("table column defaults preserve raw database expressions", () => {
+ const values = [null, "''", "0", "CURRENT_TIMESTAMP", "((1))", "('prefix (internal)')", "x".repeat(512)] as const;
+
+ assert.deepEqual(values.map(tableColumnDefaultDisplayValue), ["—", ...values.slice(1)]);
+ assert.equal(tableColumnDefaultDisplayValue(undefined), "—");
+ assert.equal(tableColumnDefaultDisplayValue(""), "");
+});
+
+test("both table information surfaces expose the same default-value column", () => {
+ for (const path of tableInfoSurfaces) {
+ const source = readFileSync(path, "utf8");
+ const { descriptor, errors } = parse(source, { filename: path });
+ assert.deepEqual(errors, []);
+ assert.ok(descriptor.template);
+ const result = compileTemplate({ id: path, filename: path, source: descriptor.template.content });
+ assert.deepEqual(result.errors, []);
+
+ assert.match(descriptor.template.content, /t\("structureEditor\.defaultValue"\)/);
+ assert.match(descriptor.template.content, /data-table-info-column-default/);
+ assert.match(descriptor.template.content, /:title="column\.column_default \?\? undefined"/);
+ assert.match(descriptor.template.content, /tableColumnDefaultDisplayValue\(column\.column_default\)/);
+ }
+});