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(editor): show column comments in SQL completions

t8y2967b9df6046c
diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vue
index 9f35d950f8..c50e5d6b4c 100644
--- a/apps/desktop/src/components/editor/QueryEditor.vue
+++ b/apps/desktop/src/components/editor/QueryEditor.vue
@@ -611,6 +611,7 @@ async function resolveSqlHoverTooltip(currentView: EditorViewType, pos: number)
create: () => ({
dom: createHoverDom(column.name, column.dataType || "column", [
column.schema ? `${column.schema}.${column.table}` : column.table,
+ ...(column.comment?.trim() ? [column.comment.trim()] : []),
]),
}),
};
@@ -869,12 +870,14 @@ function buildCompletionResult(items: QueryCompletionItem[], from: number, valid
label: item.label,
type: item.type,
detail: item.detail,
+ info: item.info,
boost: item.boost,
})
: {
label: item.label,
type: item.type,
detail: item.detail,
+ info: item.info,
apply: item.apply,
boost: item.boost,
},
diff --git a/apps/desktop/src/lib/elasticsearchCompletion.ts b/apps/desktop/src/lib/elasticsearchCompletion.ts
index 8422d78d50..d31c961f7f 100644
--- a/apps/desktop/src/lib/elasticsearchCompletion.ts
+++ b/apps/desktop/src/lib/elasticsearchCompletion.ts
@@ -4,6 +4,7 @@ export interface ElasticsearchCompletionItem {
label: string;
type: "keyword" | "property" | "text" | "snippet";
detail?: string;
+ info?: string;
apply?: string;
boost: number;
}
diff --git a/apps/desktop/src/lib/sqlCompletion.ts b/apps/desktop/src/lib/sqlCompletion.ts
index 81c77250cb..1e52d150c5 100644
--- a/apps/desktop/src/lib/sqlCompletion.ts
+++ b/apps/desktop/src/lib/sqlCompletion.ts
@@ -614,6 +614,7 @@ export interface SqlCompletionColumn {
schema?: string;
dataType?: string;
isNullable?: boolean;
+ comment?: string | null;
}
export interface SqlCompletionForeignKey {
@@ -628,6 +629,7 @@ export interface SqlCompletionItem {
label: string;
type: "keyword" | "table" | "column" | "snippet" | "function" | "schema";
detail?: string;
+ info?: string;
apply?: string;
boost: number;
}
@@ -1895,6 +1897,7 @@ function buildColumnItems(
label: column.displayLabel,
type: "column" as const,
detail: buildColumnDetail(column),
+ info: buildColumnInfo(column),
apply: buildColumnApply(column, context, dialect),
boost: computeBoost(column.displayLabel, context.prefix) + keyBoost,
};
@@ -1924,9 +1927,23 @@ function buildColumnDetail(column: SqlCompletionColumn): string {
if (column.isNullable === false) {
detail += " NOT NULL";
}
+ const comment = column.comment?.trim();
+ if (comment) {
+ detail += ` -- ${comment}`;
+ }
return detail;
}
+function buildColumnInfo(column: SqlCompletionColumn): string | undefined {
+ const parts = [
+ column.schema ? `${column.schema}.${column.table}.${column.name}` : `${column.table}.${column.name}`,
+ column.dataType ? `Type: ${column.dataType}` : undefined,
+ column.isNullable === false ? "Nullable: no" : column.isNullable === true ? "Nullable: yes" : undefined,
+ column.comment?.trim() ? `Comment: ${column.comment.trim()}` : undefined,
+ ].filter((part): part is string => !!part);
+ return parts.length > 1 ? parts.join("\n") : undefined;
+}
+
function buildJoinConditionItems(
context: SqlCompletionContext,
columnsByTable: Map<string, SqlCompletionColumn[]>,
diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.ts
index 3e843e3894..6ea3b96220 100644
--- a/apps/desktop/src/stores/connectionStore.ts
+++ b/apps/desktop/src/stores/connectionStore.ts
@@ -1720,6 +1720,8 @@ export const useConnectionStore = defineStore("connection", () => {
table,
schema,
dataType: column.data_type,
+ isNullable: column.is_nullable,
+ comment: column.comment,
}));
}
diff --git a/packages/app-tests/sqlCompletion.test.ts b/packages/app-tests/sqlCompletion.test.ts
index b7e74a97b0..9d5cdabc22 100644
--- a/packages/app-tests/sqlCompletion.test.ts
+++ b/packages/app-tests/sqlCompletion.test.ts
@@ -211,6 +211,32 @@ test("keeps explicit alias column suggestions scoped to the alias table", () =>
);
});
+test("shows column comments in WHERE field completions", () => {
+ const sql = "select * from public.orders where st";
+ const items = buildSqlCompletionItems(sql, sql.length, {
+ tables,
+ columnsByTable: new Map([
+ [
+ "public.orders",
+ [
+ {
+ name: "status",
+ table: "orders",
+ schema: "public",
+ dataType: "varchar",
+ isNullable: false,
+ comment: "Order lifecycle state",
+ },
+ ],
+ ],
+ ]),
+ });
+
+ const column = items.find((item) => item.type === "column" && item.label === "status");
+ assert.equal(column?.detail, "public.orders [varchar] NOT NULL -- Order lifecycle state");
+ assert.equal(column?.info, "public.orders.status\nType: varchar\nNullable: no\nComment: Order lifecycle state");
+});
+
test("suggests only fields after numbered table aliases in join conditions", () => {
const sql = "select * from public.users t1 join public.orders t2 on t1.";
const items = buildSqlCompletionItems(sql, sql.length, {