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(completion): use all table name initials for aliases

t8y2bd3c64737048
diff --git a/apps/desktop/src/lib/__tests__/sql/sqlCompletion.context.spec.ts b/apps/desktop/src/lib/__tests__/sql/sqlCompletion.context.spec.ts
index 28d004c408..43186403f8 100644
--- a/apps/desktop/src/lib/__tests__/sql/sqlCompletion.context.spec.ts
+++ b/apps/desktop/src/lib/__tests__/sql/sqlCompletion.context.spec.ts
@@ -114,6 +114,30 @@ describe("sqlCompletion table targets", () => {
});
describe("sqlCompletion table aliases", () => {
+ it("uses initials from all words for generated aliases", () => {
+ const sql = "SELECT * FROM mat";
+ const items = buildSqlCompletionItems(sql, sql.length, {
+ tables: [{ name: "materials_order_item", type: "table" }],
+ columnsByTable: new Map(),
+ autoAliasTables: true,
+ });
+
+ const table = items.find((item) => item.label === "materials_order_item" && item.type === "table");
+ expect(table?.apply).toBe("materials_order_item AS moi");
+ });
+
+ it("uses every word initial for longer multi-word names", () => {
+ const sql = "SELECT * FROM sup";
+ const items = buildSqlCompletionItems(sql, sql.length, {
+ tables: [{ name: "super_long_customer_order_history_archive_snapshot_daily_replica", type: "table" }],
+ columnsByTable: new Map(),
+ autoAliasTables: true,
+ });
+
+ const table = items.find((item) => item.label === "super_long_customer_order_history_archive_snapshot_daily_replica" && item.type === "table");
+ expect(table?.apply).toBe("super_long_customer_order_history_archive_snapshot_daily_replica AS slcohasdr");
+ });
+
it("applies generated aliases to table completions when enabled", () => {
const sql = "SELECT * FROM ord";
const items = buildSqlCompletionItems(sql, sql.length, {
diff --git a/apps/desktop/src/lib/sql/sqlCompletion.ts b/apps/desktop/src/lib/sql/sqlCompletion.ts
index 7021cd1769..22b47b7b98 100644
--- a/apps/desktop/src/lib/sql/sqlCompletion.ts
+++ b/apps/desktop/src/lib/sql/sqlCompletion.ts
@@ -3403,8 +3403,7 @@ function buildAliasCandidates(tableName: string): string[] {
if (parts.length > 1) {
const initials = parts.map((part) => part[0]).join("");
- if (initials.length >= 2) candidates.push(initials.slice(0, 2));
- if (initials.length >= 3) candidates.push(initials.slice(0, 3));
+ if (initials.length >= 2) candidates.push(initials);
candidates.push(parts[0].slice(0, 2), parts[0].slice(0, 3));
} else {
const name = parts[0] ?? tableName.toLowerCase().replace(/[^a-z0-9]/g, "");