Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[editor] Auto propose to add a LIMIT
  • Loading branch information
romainr committed Feb 4, 2021
1 parent 44155e8 commit 0168055
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Expand Up @@ -67,7 +67,7 @@ export default class SqlAnalyzer implements Optimizer {
{
riskTables: [],
riskAnalysis: I18n('Query has no limit'),
riskId: 22, // To change
riskId: 17,
risk: 'low',
riskRecommendation: I18n('Append a limit clause to reduce the size of the result set')
}
Expand Down
Expand Up @@ -660,9 +660,10 @@ class AssistEditorContextPanel {
}

if (
riskId === 22 &&
location.type === 'whereClause' &&
!location.subquery &&
(location.missing || riskId === 22)
location.missing
) {
this.activeEditor().moveCursorToPosition({
row: location.location.last_line - 1,
Expand Down Expand Up @@ -694,6 +695,42 @@ class AssistEditorContextPanel {
return false;
}

if (
riskId === 17 &&
location.type === 'limitClause' &&
!location.subquery &&
location.missing
) {
this.activeEditor().moveCursorToPosition({
row: location.location.last_line - 1,
column: location.location.last_column - 1
});
this.activeEditor().clearSelection();

if (/\S$/.test(this.activeEditor().getTextBeforeCursor())) {
this.activeEditor().session.insert(this.activeEditor().getCursorPosition(), ' ');
}

const operation = 'LIMIT';
this.activeEditor().session.insert(
this.activeEditor().getCursorPosition(),
isLowerCase ? operation.toLowerCase() : operation
);
this.activeEditor().focus();

if (riskId === 17) {
huePubSub.publish('editor.autocomplete.temporary.sort.override', {
partitionColumnsFirst: true
});
}

window.setTimeout(() => {
this.activeEditor().execCommand('startAutocomplete');
}, 1);

return false;
}

return true;
});
}
Expand Down

0 comments on commit 0168055

Please sign in to comment.