2020-06-06 16:27:42 +02:00
|
|
|
<template>
|
2021-04-19 19:15:06 +02:00
|
|
|
<div
|
|
|
|
v-show="isSelected"
|
2021-07-12 19:18:29 +02:00
|
|
|
class="workspace-query-tab column col-12 columns col-gapless no-outline p-0"
|
2021-04-19 19:15:06 +02:00
|
|
|
tabindex="0"
|
2022-04-21 14:39:24 +02:00
|
|
|
@keydown.f5="runQuery(query)"
|
|
|
|
@keydown.k="killTabQuery"
|
|
|
|
@keydown.ctrl.alt.w="clear"
|
|
|
|
@keydown.ctrl.b="beautify"
|
|
|
|
@keydown.ctrl.g="openHistoryModal"
|
2021-04-19 19:15:06 +02:00
|
|
|
>
|
2020-06-06 16:27:42 +02:00
|
|
|
<div class="workspace-query-runner column col-12">
|
2020-12-11 15:55:18 +01:00
|
|
|
<QueryEditor
|
2021-02-22 19:14:02 +01:00
|
|
|
v-show="isSelected"
|
2021-01-31 13:03:25 +01:00
|
|
|
ref="queryEditor"
|
2022-04-21 14:39:24 +02:00
|
|
|
v-model="query"
|
2020-12-11 15:55:18 +01:00
|
|
|
:auto-focus="true"
|
2020-12-22 22:31:31 +01:00
|
|
|
:workspace="workspace"
|
2021-07-20 19:19:54 +02:00
|
|
|
:schema="breadcrumbsSchema"
|
2021-02-22 19:14:02 +01:00
|
|
|
:is-selected="isSelected"
|
2021-01-31 13:03:25 +01:00
|
|
|
:height="editorHeight"
|
2020-12-11 15:55:18 +01:00
|
|
|
/>
|
2021-01-31 13:03:25 +01:00
|
|
|
<div ref="resizer" class="query-area-resizer" />
|
2020-06-06 16:27:42 +02:00
|
|
|
<div class="workspace-query-runner-footer">
|
|
|
|
<div class="workspace-query-buttons">
|
2021-12-19 11:59:09 +01:00
|
|
|
<div @mouseenter="setCancelButtonVisibility(true)" @mouseleave="setCancelButtonVisibility(false)">
|
|
|
|
<button
|
|
|
|
v-if="showCancel && isQuering"
|
|
|
|
class="btn btn-primary btn-sm cancellable"
|
|
|
|
:disabled="!query"
|
|
|
|
:title="$t('word.cancel')"
|
|
|
|
@click="killTabQuery()"
|
|
|
|
>
|
|
|
|
<i class="mdi mdi-24px mdi-window-close" />
|
|
|
|
<span class="d-invisible pr-1">{{ $t('word.run') }}</span>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-else
|
|
|
|
class="btn btn-primary btn-sm"
|
|
|
|
:class="{'loading':isQuering}"
|
|
|
|
:disabled="!query"
|
|
|
|
title="F5"
|
|
|
|
@click="runQuery(query)"
|
|
|
|
>
|
|
|
|
<i class="mdi mdi-24px mdi-play pr-1" />
|
|
|
|
<span>{{ $t('word.run') }}</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
2022-02-11 23:19:43 +01:00
|
|
|
<button
|
|
|
|
v-if="!autocommit"
|
|
|
|
class="btn btn-dark btn-sm"
|
|
|
|
:class="{'loading':isQuering}"
|
|
|
|
@click="commitTab()"
|
|
|
|
>
|
|
|
|
<i class="mdi mdi-24px mdi-cube-send pr-1" />
|
|
|
|
<span>{{ $t('word.commit') }}</span>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-if="!autocommit"
|
|
|
|
class="btn btn-dark btn-sm"
|
|
|
|
:class="{'loading':isQuering}"
|
|
|
|
@click="rollbackTab()"
|
|
|
|
>
|
|
|
|
<i class="mdi mdi-24px mdi-undo-variant pr-1" />
|
|
|
|
<span>{{ $t('word.rollback') }}</span>
|
|
|
|
</button>
|
2021-06-28 18:34:39 +02:00
|
|
|
<button
|
2021-09-17 18:32:28 +02:00
|
|
|
class="btn btn-link btn-sm mr-0"
|
2021-06-28 18:34:39 +02:00
|
|
|
:disabled="!query || isQuering"
|
|
|
|
title="CTRL+W"
|
|
|
|
@click="clear()"
|
|
|
|
>
|
2021-07-09 15:51:02 +02:00
|
|
|
<i class="mdi mdi-24px mdi-delete-sweep pr-1" />
|
2021-06-28 18:34:39 +02:00
|
|
|
<span>{{ $t('word.clear') }}</span>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<div class="divider-vert py-3" />
|
|
|
|
|
2021-09-17 18:32:28 +02:00
|
|
|
<button
|
|
|
|
class="btn btn-dark btn-sm"
|
|
|
|
:disabled="!query || isQuering"
|
|
|
|
title="CTRL+B"
|
|
|
|
@click="beautify()"
|
|
|
|
>
|
|
|
|
<i class="mdi mdi-24px mdi-brush pr-1" />
|
|
|
|
<span>{{ $t('word.format') }}</span>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-dark btn-sm"
|
|
|
|
:disabled="isQuering"
|
|
|
|
title="CTRL+G"
|
|
|
|
@click="openHistoryModal()"
|
|
|
|
>
|
|
|
|
<i class="mdi mdi-24px mdi-history pr-1" />
|
|
|
|
<span>{{ $t('word.history') }}</span>
|
|
|
|
</button>
|
2021-06-29 23:31:18 +02:00
|
|
|
<div class="dropdown table-dropdown pr-2">
|
2021-04-22 15:08:22 +02:00
|
|
|
<button
|
2022-02-11 23:19:43 +01:00
|
|
|
:disabled="!hasResults || isQuering"
|
2021-04-22 15:08:22 +02:00
|
|
|
class="btn btn-dark btn-sm dropdown-toggle mr-0 pr-0"
|
|
|
|
tabindex="0"
|
|
|
|
>
|
2021-07-09 15:51:02 +02:00
|
|
|
<i class="mdi mdi-24px mdi-file-export mr-1" />
|
2021-04-22 15:08:22 +02:00
|
|
|
<span>{{ $t('word.export') }}</span>
|
|
|
|
<i class="mdi mdi-24px mdi-menu-down" />
|
|
|
|
</button>
|
|
|
|
<ul class="menu text-left">
|
|
|
|
<li class="menu-item">
|
|
|
|
<a class="c-hand" @click="downloadTable('json')">JSON</a>
|
|
|
|
</li>
|
|
|
|
<li class="menu-item">
|
|
|
|
<a class="c-hand" @click="downloadTable('csv')">CSV</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2022-02-11 23:19:43 +01:00
|
|
|
<div class="input-group pr-2" :title="$t('message.commitMode')">
|
|
|
|
<i class="input-group-addon addon-sm mdi mdi-24px mdi-source-commit p-0" />
|
|
|
|
<select v-model="autocommit" class="form-select select-sm text-bold">
|
|
|
|
<option :value="true">
|
|
|
|
{{ $t('message.autoCommit') }}
|
|
|
|
</option>
|
|
|
|
<option :value="false">
|
|
|
|
{{ $t('message.manualCommit') }}
|
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
2020-06-06 16:27:42 +02:00
|
|
|
</div>
|
2020-06-12 18:10:45 +02:00
|
|
|
<div class="workspace-query-info">
|
2021-02-26 18:45:00 +01:00
|
|
|
<div
|
|
|
|
v-if="results.length"
|
|
|
|
class="d-flex"
|
|
|
|
:title="$t('message.queryDuration')"
|
|
|
|
>
|
|
|
|
<i class="mdi mdi-timer-sand mdi-rotate-180 pr-1" /> <b>{{ durationsCount / 1000 }}s</b>
|
|
|
|
</div>
|
2022-02-11 23:19:43 +01:00
|
|
|
<div
|
|
|
|
v-if="resultsCount"
|
|
|
|
class="d-flex"
|
|
|
|
:title="$t('word.results')"
|
|
|
|
>
|
|
|
|
<i class="mdi mdi-equal pr-1" /> <b>{{ resultsCount.toLocaleString() }}</b>
|
2020-06-12 18:10:45 +02:00
|
|
|
</div>
|
2022-02-11 23:19:43 +01:00
|
|
|
<div
|
|
|
|
v-if="hasAffected"
|
|
|
|
class="d-flex"
|
|
|
|
:title="$t('message.affectedRows')"
|
|
|
|
>
|
|
|
|
<i class="mdi mdi-target pr-1" /> <b>{{ affectedCount }}</b>
|
2020-09-03 13:44:58 +02:00
|
|
|
</div>
|
2021-07-20 19:19:54 +02:00
|
|
|
<div class="input-group" :title="$t('word.schema')">
|
|
|
|
<i class="input-group-addon addon-sm mdi mdi-24px mdi-database" />
|
|
|
|
<select v-model="selectedSchema" class="form-select select-sm text-bold">
|
|
|
|
<option :value="null">
|
|
|
|
{{ $t('message.noSchema') }}
|
|
|
|
</option>
|
|
|
|
<option v-for="schemaName in databaseSchemas" :key="schemaName">
|
|
|
|
{{ schemaName }}
|
|
|
|
</option>
|
|
|
|
</select>
|
2020-06-12 18:10:45 +02:00
|
|
|
</div>
|
2020-06-06 16:27:42 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-19 11:59:09 +01:00
|
|
|
<WorkspaceTabQueryEmptyState v-if="!results.length && !isQuering" :customizations="workspace.customizations" />
|
2021-03-09 19:14:02 +01:00
|
|
|
<div class="workspace-query-results p-relative column col-12">
|
|
|
|
<BaseLoader v-if="isQuering" />
|
2021-08-12 09:54:13 +02:00
|
|
|
<WorkspaceTabQueryTable
|
2020-06-16 18:01:22 +02:00
|
|
|
v-if="results"
|
2020-08-14 18:07:29 +02:00
|
|
|
v-show="!isQuering"
|
2020-06-28 15:31:16 +02:00
|
|
|
ref="queryTable"
|
2020-06-16 18:01:22 +02:00
|
|
|
:results="results"
|
2021-02-24 12:46:31 +01:00
|
|
|
:tab-uid="tab.uid"
|
2020-09-18 12:54:02 +02:00
|
|
|
:conn-uid="connection.uid"
|
2021-03-05 17:10:52 +01:00
|
|
|
:is-selected="isSelected"
|
2020-09-18 12:54:02 +02:00
|
|
|
mode="query"
|
2020-08-18 18:03:59 +02:00
|
|
|
@update-field="updateField"
|
|
|
|
@delete-selected="deleteSelected"
|
2020-06-16 18:01:22 +02:00
|
|
|
/>
|
2020-06-06 16:27:42 +02:00
|
|
|
</div>
|
2021-09-17 18:32:28 +02:00
|
|
|
<ModalHistory
|
|
|
|
v-if="isHistoryOpen"
|
|
|
|
:connection="connection"
|
|
|
|
@select-query="selectQuery"
|
|
|
|
@close="isHistoryOpen = false"
|
|
|
|
/>
|
2020-06-06 16:27:42 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-04-30 11:45:49 +02:00
|
|
|
import { storeToRefs } from 'pinia';
|
2021-04-19 19:15:06 +02:00
|
|
|
import { format } from 'sql-formatter';
|
2022-04-30 00:47:37 +02:00
|
|
|
import { useHistoryStore } from '@/stores/history';
|
|
|
|
import { useNotificationsStore } from '@/stores/notifications';
|
|
|
|
import { useWorkspacesStore } from '@/stores/workspaces';
|
2021-03-17 11:15:14 +01:00
|
|
|
import Schema from '@/ipc-api/Schema';
|
2020-06-06 16:27:42 +02:00
|
|
|
import QueryEditor from '@/components/QueryEditor';
|
2021-03-09 19:14:02 +01:00
|
|
|
import BaseLoader from '@/components/BaseLoader';
|
2021-08-12 09:54:13 +02:00
|
|
|
import WorkspaceTabQueryTable from '@/components/WorkspaceTabQueryTable';
|
|
|
|
import WorkspaceTabQueryEmptyState from '@/components/WorkspaceTabQueryEmptyState';
|
2021-09-17 18:32:28 +02:00
|
|
|
import ModalHistory from '@/components/ModalHistory';
|
2020-07-23 19:10:14 +02:00
|
|
|
import tableTabs from '@/mixins/tableTabs';
|
2020-06-06 16:27:42 +02:00
|
|
|
|
|
|
|
export default {
|
2021-08-12 09:54:13 +02:00
|
|
|
name: 'WorkspaceTabQuery',
|
2020-06-06 16:27:42 +02:00
|
|
|
components: {
|
2021-03-09 19:14:02 +01:00
|
|
|
BaseLoader,
|
2020-06-10 19:29:10 +02:00
|
|
|
QueryEditor,
|
2021-08-12 09:54:13 +02:00
|
|
|
WorkspaceTabQueryTable,
|
2021-09-17 18:32:28 +02:00
|
|
|
WorkspaceTabQueryEmptyState,
|
|
|
|
ModalHistory
|
2020-06-06 16:27:42 +02:00
|
|
|
},
|
2020-07-23 19:10:14 +02:00
|
|
|
mixins: [tableTabs],
|
2020-06-06 16:27:42 +02:00
|
|
|
props: {
|
2020-08-14 18:07:29 +02:00
|
|
|
connection: Object,
|
2021-02-24 12:46:31 +01:00
|
|
|
tab: Object,
|
2020-08-20 18:06:02 +02:00
|
|
|
isSelected: Boolean
|
2020-06-06 16:27:42 +02:00
|
|
|
},
|
2022-04-30 00:47:37 +02:00
|
|
|
setup () {
|
|
|
|
const { getHistoryByWorkspace, saveHistory } = useHistoryStore();
|
|
|
|
const { addNotification } = useNotificationsStore();
|
|
|
|
const workspacesStore = useWorkspacesStore();
|
|
|
|
|
|
|
|
const { getSelected: selectedWorkspace } = storeToRefs(workspacesStore);
|
|
|
|
|
|
|
|
const {
|
|
|
|
getWorkspace,
|
|
|
|
changeBreadcrumbs,
|
|
|
|
updateTabContent,
|
|
|
|
setUnsavedChanges
|
|
|
|
} = workspacesStore;
|
|
|
|
|
|
|
|
return {
|
|
|
|
getHistoryByWorkspace,
|
|
|
|
saveHistory,
|
|
|
|
addNotification,
|
|
|
|
selectedWorkspace,
|
|
|
|
getWorkspace,
|
|
|
|
changeBreadcrumbs,
|
|
|
|
updateTabContent,
|
|
|
|
setUnsavedChanges
|
|
|
|
};
|
|
|
|
},
|
2020-06-06 16:27:42 +02:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
query: '',
|
2020-08-05 22:08:20 +02:00
|
|
|
lastQuery: '',
|
2020-06-10 19:29:10 +02:00
|
|
|
isQuering: false,
|
2021-12-19 11:59:09 +01:00
|
|
|
isCancelling: false,
|
|
|
|
showCancel: false,
|
2022-02-11 23:19:43 +01:00
|
|
|
autocommit: true,
|
2020-09-06 08:41:57 +02:00
|
|
|
results: [],
|
2021-07-20 19:19:54 +02:00
|
|
|
selectedSchema: null,
|
2020-10-27 16:41:00 +01:00
|
|
|
resultsCount: 0,
|
2021-02-26 18:45:00 +01:00
|
|
|
durationsCount: 0,
|
2021-11-15 18:09:34 +01:00
|
|
|
affectedCount: null,
|
2021-09-17 18:32:28 +02:00
|
|
|
editorHeight: 200,
|
|
|
|
isHistoryOpen: false
|
2020-06-06 16:27:42 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
workspace () {
|
|
|
|
return this.getWorkspace(this.connection.uid);
|
2021-02-18 18:01:12 +01:00
|
|
|
},
|
2022-02-13 10:27:10 +01:00
|
|
|
tabUid () {
|
2022-04-22 17:49:13 +02:00
|
|
|
return this.$vnode?.key;
|
2022-02-13 10:27:10 +01:00
|
|
|
},
|
2021-07-20 19:19:54 +02:00
|
|
|
breadcrumbsSchema () {
|
2021-07-22 10:41:06 +02:00
|
|
|
return this.workspace.breadcrumbs.schema || null;
|
2021-07-13 09:09:25 +02:00
|
|
|
},
|
2021-07-20 19:19:54 +02:00
|
|
|
databaseSchemas () {
|
|
|
|
return this.workspace.structure.reduce((acc, curr) => {
|
|
|
|
acc.push(curr.name);
|
|
|
|
return acc;
|
|
|
|
}, []);
|
|
|
|
},
|
2021-02-18 18:01:12 +01:00
|
|
|
isWorkspaceSelected () {
|
|
|
|
return this.workspace.uid === this.selectedWorkspace;
|
2021-09-17 18:32:28 +02:00
|
|
|
},
|
|
|
|
history () {
|
|
|
|
return this.getHistoryByWorkspace(this.connection.uid) || [];
|
2022-02-11 23:19:43 +01:00
|
|
|
},
|
|
|
|
hasResults () {
|
|
|
|
return this.results.length && this.results[0].rows;
|
|
|
|
},
|
|
|
|
hasAffected () {
|
|
|
|
return this.affectedCount || (!this.resultsCount && this.affectedCount !== null);
|
2020-06-06 16:27:42 +02:00
|
|
|
}
|
|
|
|
},
|
2021-07-14 16:10:34 +02:00
|
|
|
watch: {
|
|
|
|
isSelected (val) {
|
2022-01-09 12:28:01 +01:00
|
|
|
if (val) {
|
2021-07-20 19:19:54 +02:00
|
|
|
this.changeBreadcrumbs({ schema: this.selectedSchema, query: `Query #${this.tab.index}` });
|
2022-01-09 12:28:01 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
if (this.$refs.queryEditor)
|
|
|
|
this.$refs.queryEditor.editor.focus();
|
|
|
|
}, 0);
|
|
|
|
}
|
2021-07-20 19:19:54 +02:00
|
|
|
},
|
|
|
|
selectedSchema () {
|
|
|
|
this.changeBreadcrumbs({ schema: this.selectedSchema, query: `Query #${this.tab.index}` });
|
2021-07-14 16:10:34 +02:00
|
|
|
}
|
|
|
|
},
|
2020-10-04 17:32:15 +02:00
|
|
|
created () {
|
2021-02-24 12:46:31 +01:00
|
|
|
this.query = this.tab.content;
|
2021-07-22 10:41:06 +02:00
|
|
|
this.selectedSchema = this.tab.schema || this.breadcrumbsSchema;
|
2021-02-24 12:46:31 +01:00
|
|
|
|
2020-10-04 17:32:15 +02:00
|
|
|
window.addEventListener('keydown', this.onKey);
|
|
|
|
},
|
2021-01-31 13:03:25 +01:00
|
|
|
mounted () {
|
|
|
|
const resizer = this.$refs.resizer;
|
|
|
|
|
|
|
|
resizer.addEventListener('mousedown', e => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
window.addEventListener('mousemove', this.resize);
|
|
|
|
window.addEventListener('mouseup', this.stopResize);
|
|
|
|
});
|
2021-02-24 12:46:31 +01:00
|
|
|
|
|
|
|
if (this.tab.autorun)
|
|
|
|
this.runQuery(this.query);
|
2021-01-31 13:03:25 +01:00
|
|
|
},
|
2022-04-21 14:39:24 +02:00
|
|
|
beforeUnmount () {
|
2020-10-04 17:32:15 +02:00
|
|
|
window.removeEventListener('keydown', this.onKey);
|
2022-02-11 23:19:43 +01:00
|
|
|
const params = {
|
|
|
|
uid: this.connection.uid,
|
|
|
|
tabUid: this.tab.uid
|
|
|
|
};
|
|
|
|
Schema.destroyConnectionToCommit(params);
|
2020-10-04 17:32:15 +02:00
|
|
|
},
|
2020-06-06 16:27:42 +02:00
|
|
|
methods: {
|
2020-08-05 22:08:20 +02:00
|
|
|
async runQuery (query) {
|
2020-10-04 17:32:15 +02:00
|
|
|
if (!query || this.isQuering) return;
|
2020-06-10 19:29:10 +02:00
|
|
|
this.isQuering = true;
|
2020-09-03 13:44:58 +02:00
|
|
|
this.clearTabData();
|
2020-12-07 17:51:48 +01:00
|
|
|
this.$refs.queryTable.resetSort();
|
2020-06-06 16:27:42 +02:00
|
|
|
|
2020-08-14 18:07:29 +02:00
|
|
|
try { // Query Data
|
2020-06-16 18:01:22 +02:00
|
|
|
const params = {
|
|
|
|
uid: this.connection.uid,
|
2021-07-20 19:19:54 +02:00
|
|
|
schema: this.selectedSchema,
|
2021-12-19 11:59:09 +01:00
|
|
|
tabUid: this.tab.uid,
|
2022-02-11 23:19:43 +01:00
|
|
|
autocommit: this.autocommit,
|
2020-08-14 11:25:50 +02:00
|
|
|
query
|
2020-06-16 18:01:22 +02:00
|
|
|
};
|
|
|
|
|
2021-03-17 11:15:14 +01:00
|
|
|
const { status, response } = await Schema.rawQuery(params);
|
2020-09-06 08:41:57 +02:00
|
|
|
|
2020-08-13 13:24:03 +02:00
|
|
|
if (status === 'success') {
|
2020-09-06 08:41:57 +02:00
|
|
|
this.results = Array.isArray(response) ? response : [response];
|
2021-11-15 18:09:34 +01:00
|
|
|
this.resultsCount = this.results.reduce((acc, curr) => acc + (curr.rows ? curr.rows.length : 0), 0);
|
|
|
|
this.durationsCount = this.results.reduce((acc, curr) => acc + curr.duration, 0);
|
|
|
|
this.affectedCount = this.results
|
|
|
|
.filter(result => result.report !== null)
|
|
|
|
.reduce((acc, curr) => {
|
|
|
|
if (acc === null) acc = 0;
|
|
|
|
return acc + (curr.report ? curr.report.affectedRows : 0);
|
|
|
|
}, null);
|
2021-07-22 10:41:06 +02:00
|
|
|
|
2021-09-17 18:32:28 +02:00
|
|
|
this.updateTabContent({
|
|
|
|
uid: this.connection.uid,
|
|
|
|
tab: this.tab.uid,
|
|
|
|
type: 'query',
|
|
|
|
schema: this.selectedSchema,
|
|
|
|
content: query
|
|
|
|
});
|
|
|
|
this.saveHistory(params);
|
2022-02-13 10:27:10 +01:00
|
|
|
if (!this.autocommit)
|
|
|
|
this.setUnsavedChanges({ uid: this.connection.uid, tUid: this.tabUid, isChanged: true });
|
2020-08-14 18:07:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
this.addNotification({ status: 'error', message: response });
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.addNotification({ status: 'error', message: err.stack });
|
|
|
|
}
|
|
|
|
|
2020-06-10 19:29:10 +02:00
|
|
|
this.isQuering = false;
|
2020-08-05 22:08:20 +02:00
|
|
|
this.lastQuery = query;
|
2020-08-04 17:54:19 +02:00
|
|
|
},
|
2021-12-19 11:59:09 +01:00
|
|
|
async killTabQuery () {
|
|
|
|
if (this.isCancelling) return;
|
|
|
|
|
|
|
|
this.isCancelling = true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const params = {
|
|
|
|
uid: this.connection.uid,
|
|
|
|
tabUid: this.tab.uid
|
|
|
|
};
|
|
|
|
|
|
|
|
await Schema.killTabQuery(params);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.addNotification({ status: 'error', message: err.stack });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isCancelling = false;
|
|
|
|
},
|
|
|
|
setCancelButtonVisibility (val) {
|
|
|
|
if (this.workspace.customizations.cancelQueries)
|
|
|
|
this.showCancel = val;
|
|
|
|
},
|
2020-08-04 17:54:19 +02:00
|
|
|
reloadTable () {
|
2020-08-05 22:08:20 +02:00
|
|
|
this.runQuery(this.lastQuery);
|
2020-09-03 13:44:58 +02:00
|
|
|
},
|
|
|
|
clearTabData () {
|
2020-09-06 08:41:57 +02:00
|
|
|
this.results = [];
|
2020-10-27 16:41:00 +01:00
|
|
|
this.resultsCount = 0;
|
2021-02-26 18:45:00 +01:00
|
|
|
this.durationsCount = 0;
|
2021-11-15 18:09:34 +01:00
|
|
|
this.affectedCount = null;
|
2020-10-04 17:32:15 +02:00
|
|
|
},
|
2021-01-31 13:03:25 +01:00
|
|
|
resize (e) {
|
|
|
|
const el = this.$refs.queryEditor.$el;
|
|
|
|
let editorHeight = e.pageY - el.getBoundingClientRect().top;
|
|
|
|
if (editorHeight > 400) editorHeight = 400;
|
|
|
|
if (editorHeight < 50) editorHeight = 50;
|
|
|
|
this.editorHeight = editorHeight;
|
|
|
|
},
|
|
|
|
stopResize () {
|
|
|
|
window.removeEventListener('mousemove', this.resize);
|
|
|
|
if (this.$refs.queryTable && this.results.length)
|
|
|
|
this.$refs.queryTable.resizeResults();
|
|
|
|
|
|
|
|
if (this.$refs.queryEditor)
|
|
|
|
this.$refs.queryEditor.editor.resize();
|
|
|
|
},
|
2021-04-19 19:15:06 +02:00
|
|
|
beautify () {
|
|
|
|
if (this.$refs.queryEditor) {
|
|
|
|
let language = 'sql';
|
|
|
|
|
|
|
|
switch (this.workspace.client) {
|
|
|
|
case 'mysql':
|
|
|
|
language = 'mysql';
|
|
|
|
break;
|
|
|
|
case 'maria':
|
|
|
|
language = 'mariadb';
|
|
|
|
break;
|
|
|
|
case 'pg':
|
|
|
|
language = 'postgresql';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const formattedQuery = format(this.query, {
|
|
|
|
language,
|
|
|
|
uppercase: true
|
|
|
|
});
|
|
|
|
this.$refs.queryEditor.editor.session.setValue(formattedQuery);
|
2020-10-27 17:04:39 +01:00
|
|
|
}
|
2021-04-19 19:15:06 +02:00
|
|
|
},
|
2021-09-17 18:32:28 +02:00
|
|
|
openHistoryModal () {
|
|
|
|
this.isHistoryOpen = true;
|
|
|
|
},
|
|
|
|
selectQuery (sql) {
|
|
|
|
if (this.$refs.queryEditor)
|
|
|
|
this.$refs.queryEditor.editor.session.setValue(sql);
|
|
|
|
|
|
|
|
this.isHistoryOpen = false;
|
|
|
|
},
|
2021-04-19 19:15:06 +02:00
|
|
|
clear () {
|
|
|
|
if (this.$refs.queryEditor)
|
|
|
|
this.$refs.queryEditor.editor.session.setValue('');
|
|
|
|
this.clearTabData();
|
2021-04-22 15:08:22 +02:00
|
|
|
},
|
|
|
|
downloadTable (format) {
|
|
|
|
this.$refs.queryTable.downloadTable(format, `${this.tab.type}-${this.tab.index}`);
|
2022-02-11 23:19:43 +01:00
|
|
|
},
|
|
|
|
async commitTab () {
|
|
|
|
this.isQuering = true;
|
|
|
|
try {
|
|
|
|
const params = {
|
|
|
|
uid: this.connection.uid,
|
|
|
|
tabUid: this.tab.uid
|
|
|
|
};
|
|
|
|
|
|
|
|
await Schema.commitTab(params);
|
2022-02-13 10:27:10 +01:00
|
|
|
this.setUnsavedChanges({ uid: this.connection.uid, tUid: this.tabUid, isChanged: false });
|
2022-02-13 10:16:01 +01:00
|
|
|
this.addNotification({ status: 'success', message: this.$t('message.actionSuccessful', { action: 'COMMIT' }) });
|
2022-02-11 23:19:43 +01:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.addNotification({ status: 'error', message: err.stack });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isQuering = false;
|
|
|
|
},
|
|
|
|
async rollbackTab () {
|
|
|
|
this.isQuering = true;
|
|
|
|
try {
|
|
|
|
const params = {
|
|
|
|
uid: this.connection.uid,
|
|
|
|
tabUid: this.tab.uid
|
|
|
|
};
|
|
|
|
|
|
|
|
await Schema.rollbackTab(params);
|
2022-02-13 10:27:10 +01:00
|
|
|
this.setUnsavedChanges({ uid: this.connection.uid, tUid: this.tabUid, isChanged: false });
|
2022-02-13 10:16:01 +01:00
|
|
|
this.addNotification({ status: 'success', message: this.$t('message.actionSuccessful', { action: 'ROLLBACK' }) });
|
2022-02-11 23:19:43 +01:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.addNotification({ status: 'error', message: err.stack });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isQuering = false;
|
2020-06-06 16:27:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2020-07-31 18:16:28 +02:00
|
|
|
.workspace-tabs {
|
|
|
|
align-content: baseline;
|
2020-06-06 16:27:42 +02:00
|
|
|
|
2020-07-31 18:16:28 +02:00
|
|
|
.workspace-query-runner {
|
2021-01-31 13:03:25 +01:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
.query-area-resizer {
|
|
|
|
position: absolute;
|
2021-07-01 19:18:57 +02:00
|
|
|
height: 4px;
|
2021-01-31 13:03:25 +01:00
|
|
|
bottom: 40px;
|
|
|
|
width: 100%;
|
|
|
|
cursor: ns-resize;
|
|
|
|
z-index: 99;
|
2021-06-30 09:49:32 +02:00
|
|
|
transition: background 0.2s;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: rgba($primary-color, 50%);
|
|
|
|
}
|
2021-01-31 13:03:25 +01:00
|
|
|
}
|
|
|
|
|
2020-07-31 18:16:28 +02:00
|
|
|
.workspace-query-runner-footer {
|
|
|
|
display: flex;
|
2022-02-11 23:19:43 +01:00
|
|
|
flex-wrap: wrap;
|
|
|
|
row-gap: 0.4rem;
|
2020-07-31 18:16:28 +02:00
|
|
|
justify-content: space-between;
|
|
|
|
padding: 0.3rem 0.6rem 0.4rem;
|
|
|
|
align-items: center;
|
2022-02-11 23:19:43 +01:00
|
|
|
min-height: 42px;
|
2020-06-06 16:27:42 +02:00
|
|
|
|
2021-07-20 19:19:54 +02:00
|
|
|
.workspace-query-buttons,
|
|
|
|
.workspace-query-info {
|
2020-07-31 18:16:28 +02:00
|
|
|
display: flex;
|
2021-07-20 19:19:54 +02:00
|
|
|
align-items: center;
|
2020-06-06 16:27:42 +02:00
|
|
|
|
2020-07-31 18:16:28 +02:00
|
|
|
.btn {
|
|
|
|
display: flex;
|
|
|
|
align-self: center;
|
|
|
|
margin-right: 0.4rem;
|
|
|
|
}
|
|
|
|
}
|
2020-06-06 16:27:42 +02:00
|
|
|
|
2020-07-31 18:16:28 +02:00
|
|
|
.workspace-query-info {
|
2021-07-20 19:19:54 +02:00
|
|
|
overflow: visible;
|
2020-06-10 19:29:10 +02:00
|
|
|
|
2020-07-31 18:16:28 +02:00
|
|
|
> div + div {
|
|
|
|
padding-left: 0.6rem;
|
|
|
|
}
|
2020-06-06 16:27:42 +02:00
|
|
|
}
|
2020-07-31 18:16:28 +02:00
|
|
|
}
|
|
|
|
}
|
2021-03-09 19:14:02 +01:00
|
|
|
|
|
|
|
.workspace-query-results {
|
|
|
|
min-height: 200px;
|
|
|
|
}
|
2020-06-06 16:27:42 +02:00
|
|
|
}
|
|
|
|
</style>
|