fix(desktop): scope SQL alias completions to columns
This commit is contained in:
1 parent
b35c1486e6
commit
41e97baa6e
3 files changed
+90
-1
No files matched your search
@@ -917,7 +917,9 @@ async function performAsyncCompletionWithResult(
|
||||
}
|
||||
}
|
||||
|
||||
const shouldLoadTables = completionContext.suggestTables || !!completionContext.qualifier;
|
||||
const shouldLoadTables =
|
||||
completionContext.suggestTables ||
|
||||
(!!completionContext.qualifier && !isReferencedTableQualifier(completionContext));
|
||||
let tables = shouldLoadTables
|
||||
? await connectionStore.listCompletionTables(
|
||||
props.connectionId!,
|
||||
@@ -1075,6 +1077,14 @@ async function performAsyncCompletionWithResult(
|
||||
return buildCompletionResult(items, position, completionContext.prefix.length, fullDoc);
|
||||
}
|
||||
|
||||
function isReferencedTableQualifier(completionContext: ReturnType<typeof getSqlCompletionContext>): boolean {
|
||||
if (!completionContext.qualifier) return false;
|
||||
const qualifier = completionContext.qualifier.toLowerCase();
|
||||
return completionContext.referencedTables.some(
|
||||
(table) => table.alias?.toLowerCase() === qualifier || table.name.toLowerCase() === qualifier,
|
||||
);
|
||||
}
|
||||
|
||||
async function refreshCompletionCache() {
|
||||
cachedTables = [];
|
||||
cachedColumnsByTable.clear();
|
||||
|
||||
@@ -1926,6 +1926,12 @@ function buildJoinConditionItemsForPair(
|
||||
) {
|
||||
boost = 1800;
|
||||
}
|
||||
// Pattern 7: Generic FK column → id when table names do not reveal the relationship.
|
||||
else if (leftName !== "id" && leftName.endsWith("_id") && rightName === "id") {
|
||||
boost = 1650;
|
||||
} else if (rightName !== "id" && rightName.endsWith("_id") && leftName === "id") {
|
||||
boost = 1650;
|
||||
}
|
||||
|
||||
if (!boost) continue;
|
||||
const label = `${leftLabel} = ${rightLabel}`;
|
||||
|
||||
Reference in new issue
Block a user