execute current query

This commit is contained in:
Jan Prochazka
2021-12-12 11:00:48 +01:00
parent 2309f99dad
commit ec94b99f4b
3 changed files with 50 additions and 6 deletions

View File

@@ -75,6 +75,18 @@
return editor;
}
export function getCurrentCommandText(): string {
if (currentPart != null) return currentPart.text;
if (!editor) return '';
const selectedText = editor.getSelectedText();
if (selectedText) return selectedText;
if (editor.getHighlightActiveLine()) {
const line = editor.getSelectionRange().start.row;
return editor.session.getLine(line);
}
return '';
}
const requireEditorPlugins = () => {};
requireEditorPlugins();
@@ -155,7 +167,18 @@
function changedCurrentQueryPart() {
if (queryParts.length <= 1) return;
const cursor = editor.getSelectionRange().start;
const selectionRange = editor.getSelectionRange();
if (
selectionRange.start.row != selectionRange.end.row ||
selectionRange.start.column != selectionRange.end.column
) {
removeCurrentPartMarker();
currentPart = null;
return;
}
const cursor = selectionRange.start;
const part = queryParts.find(
x =>
((cursor.row == x.startLine && cursor.column >= x.startColumn) || cursor.row > x.startLine) &&

View File

@@ -32,6 +32,10 @@
return domEditor.getEditor();
}
export function getCurrentCommandText(): string {
return domEditor.getCurrentCommandText();
}
$: effect = useEffect(() => {
const editor = domEditor?.getEditor();
if ($tabVisible && conid && database && !readOnly && editor) {

View File

@@ -30,6 +30,15 @@
findReplace: true,
executeAdditionalCondition: () => getCurrentEditor()?.hasConnection(),
});
registerCommand({
id: 'query.executeCurrent',
category: 'Query',
name: 'Execute current',
keyText: 'Ctrl+Shift+Enter',
testEnabled: () =>
getCurrentEditor() != null && !getCurrentEditor()?.isBusy() && getCurrentEditor()?.hasConnection(),
onClick: () => getCurrentEditor().executeCurrent(),
});
</script>
<script lang="ts">
@@ -128,11 +137,10 @@
return !!conid;
}
export async function execute() {
async function executeCore(sql) {
if (busy) return;
executeNumber++;
visibleResultTabs = true;
const selectedText = domEditor.getEditor().getSelectedText();
let sesid = sessionId;
if (!sesid) {
@@ -145,7 +153,6 @@
}
busy = true;
timerLabel.start();
const sql = selectedText || $editorValue;
await axiosInstance.post('sessions/execute-query', {
sesid,
sql,
@@ -160,6 +167,16 @@
});
}
export async function executeCurrent() {
const sql = domEditor.getCurrentCommandText();
await executeCore(sql);
}
export async function execute() {
const selectedText = domEditor.getEditor().getSelectedText();
await executeCore(selectedText || $editorValue);
}
export async function kill() {
await axiosInstance.post('sessions/kill', {
sesid: sessionId,
@@ -253,7 +270,7 @@
<AceEditor
mode="javascript"
value={$editorState.value || ''}
splitterOptions={driver?.getQuerySplitterOptions('stream')}
splitterOptions={driver?.getQuerySplitterOptions('script')}
menu={createMenu()}
on:input={e => setEditorData(e.detail)}
on:focus={() => {
@@ -267,7 +284,7 @@
engine={$connection && $connection.engine}
{conid}
{database}
splitterOptions={driver?.getQuerySplitterOptions('stream')}
splitterOptions={driver?.getQuerySplitterOptions('script')}
value={$editorState.value || ''}
menu={createMenu()}
on:input={e => setEditorData(e.detail)}