mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-21 12:41:39 +00:00
feat(completion): use all table name initials for aliases
This commit is contained in:
@@ -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, {
|
||||
|
||||
@@ -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, "");
|
||||
|
||||
Reference in New Issue
Block a user