mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 12:06:00 +00:00
execute current query
This commit is contained in:
@@ -75,6 +75,18 @@
|
|||||||
return editor;
|
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 = () => {};
|
const requireEditorPlugins = () => {};
|
||||||
requireEditorPlugins();
|
requireEditorPlugins();
|
||||||
|
|
||||||
@@ -155,7 +167,18 @@
|
|||||||
|
|
||||||
function changedCurrentQueryPart() {
|
function changedCurrentQueryPart() {
|
||||||
if (queryParts.length <= 1) return;
|
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(
|
const part = queryParts.find(
|
||||||
x =>
|
x =>
|
||||||
((cursor.row == x.startLine && cursor.column >= x.startColumn) || cursor.row > x.startLine) &&
|
((cursor.row == x.startLine && cursor.column >= x.startColumn) || cursor.row > x.startLine) &&
|
||||||
|
|||||||
@@ -32,6 +32,10 @@
|
|||||||
return domEditor.getEditor();
|
return domEditor.getEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getCurrentCommandText(): string {
|
||||||
|
return domEditor.getCurrentCommandText();
|
||||||
|
}
|
||||||
|
|
||||||
$: effect = useEffect(() => {
|
$: effect = useEffect(() => {
|
||||||
const editor = domEditor?.getEditor();
|
const editor = domEditor?.getEditor();
|
||||||
if ($tabVisible && conid && database && !readOnly && editor) {
|
if ($tabVisible && conid && database && !readOnly && editor) {
|
||||||
|
|||||||
@@ -30,6 +30,15 @@
|
|||||||
findReplace: true,
|
findReplace: true,
|
||||||
executeAdditionalCondition: () => getCurrentEditor()?.hasConnection(),
|
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>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -128,11 +137,10 @@
|
|||||||
return !!conid;
|
return !!conid;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function execute() {
|
async function executeCore(sql) {
|
||||||
if (busy) return;
|
if (busy) return;
|
||||||
executeNumber++;
|
executeNumber++;
|
||||||
visibleResultTabs = true;
|
visibleResultTabs = true;
|
||||||
const selectedText = domEditor.getEditor().getSelectedText();
|
|
||||||
|
|
||||||
let sesid = sessionId;
|
let sesid = sessionId;
|
||||||
if (!sesid) {
|
if (!sesid) {
|
||||||
@@ -145,7 +153,6 @@
|
|||||||
}
|
}
|
||||||
busy = true;
|
busy = true;
|
||||||
timerLabel.start();
|
timerLabel.start();
|
||||||
const sql = selectedText || $editorValue;
|
|
||||||
await axiosInstance.post('sessions/execute-query', {
|
await axiosInstance.post('sessions/execute-query', {
|
||||||
sesid,
|
sesid,
|
||||||
sql,
|
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() {
|
export async function kill() {
|
||||||
await axiosInstance.post('sessions/kill', {
|
await axiosInstance.post('sessions/kill', {
|
||||||
sesid: sessionId,
|
sesid: sessionId,
|
||||||
@@ -253,7 +270,7 @@
|
|||||||
<AceEditor
|
<AceEditor
|
||||||
mode="javascript"
|
mode="javascript"
|
||||||
value={$editorState.value || ''}
|
value={$editorState.value || ''}
|
||||||
splitterOptions={driver?.getQuerySplitterOptions('stream')}
|
splitterOptions={driver?.getQuerySplitterOptions('script')}
|
||||||
menu={createMenu()}
|
menu={createMenu()}
|
||||||
on:input={e => setEditorData(e.detail)}
|
on:input={e => setEditorData(e.detail)}
|
||||||
on:focus={() => {
|
on:focus={() => {
|
||||||
@@ -267,7 +284,7 @@
|
|||||||
engine={$connection && $connection.engine}
|
engine={$connection && $connection.engine}
|
||||||
{conid}
|
{conid}
|
||||||
{database}
|
{database}
|
||||||
splitterOptions={driver?.getQuerySplitterOptions('stream')}
|
splitterOptions={driver?.getQuerySplitterOptions('script')}
|
||||||
value={$editorState.value || ''}
|
value={$editorState.value || ''}
|
||||||
menu={createMenu()}
|
menu={createMenu()}
|
||||||
on:input={e => setEditorData(e.detail)}
|
on:input={e => setEditorData(e.detail)}
|
||||||
|
|||||||
Reference in New Issue
Block a user