mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
Improvements to query builder
This commit is contained in:
@ -2,8 +2,8 @@
|
||||
<details class="accordion workspace-explorebar-database">
|
||||
<summary
|
||||
class="accordion-header database-name pb-0"
|
||||
:class="{'text-bold': breadcrumbs.database === database.name}"
|
||||
@click="changeBreadcrumbs({database: database.name, table:null})"
|
||||
:class="{'text-bold': breadcrumbs.schema === database.name}"
|
||||
@click="changeBreadcrumbs({schema: database.name, table:null})"
|
||||
>
|
||||
<i class="icon material-icons md-18 mr-1">navigate_next</i>
|
||||
<i class="material-icons md-18 mr-1">view_agenda</i>
|
||||
@ -16,8 +16,8 @@
|
||||
v-for="table of database.tables"
|
||||
:key="table.TABLE_NAME"
|
||||
class="menu-item"
|
||||
:class="{'text-bold': breadcrumbs.database === database.name && breadcrumbs.table === table.TABLE_NAME}"
|
||||
@click="changeBreadcrumbs({database: database.name, table: table.TABLE_NAME})"
|
||||
:class="{'text-bold': breadcrumbs.schema === database.name && breadcrumbs.table === table.TABLE_NAME}"
|
||||
@click="changeBreadcrumbs({schema: database.name, table: table.TABLE_NAME})"
|
||||
>
|
||||
<a class="table-name">
|
||||
<i class="material-icons md-18 mr-1">grid_on</i>
|
||||
|
@ -22,8 +22,8 @@
|
||||
<div v-if="results.rows">
|
||||
{{ $t('word.results') }}: <b>{{ results.rows.length }}</b>
|
||||
</div>
|
||||
<div v-if="workspace.breadcrumbs.database">
|
||||
{{ $t('word.schema') }}: <b>{{ workspace.breadcrumbs.database }}</b>
|
||||
<div v-if="workspace.breadcrumbs.schema">
|
||||
{{ $t('word.schema') }}: <b>{{ workspace.breadcrumbs.schema }}</b>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -76,7 +76,7 @@ export default {
|
||||
const params = {
|
||||
uid: this.connection.uid,
|
||||
query: this.query,
|
||||
database: this.workspace.breadcrumbs.database
|
||||
schema: this.workspace.breadcrumbs.schema
|
||||
};
|
||||
|
||||
try {
|
||||
|
@ -6,7 +6,7 @@
|
||||
<button
|
||||
class="btn btn-link btn-sm"
|
||||
:class="{'loading':isQuering}"
|
||||
@click="runQuery"
|
||||
@click="getTableData"
|
||||
>
|
||||
<span>{{ $t('word.refresh') }}</span>
|
||||
<i class="material-icons ml-1">refresh</i>
|
||||
@ -33,7 +33,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Connection from '@/ipc-api/Connection';
|
||||
import Structure from '@/ipc-api/Structure';
|
||||
import WorkspaceQueryTable from '@/components/WorkspaceQueryTable';
|
||||
import { mapGetters, mapActions } from 'vuex';
|
||||
|
||||
@ -50,6 +50,7 @@ export default {
|
||||
return {
|
||||
isQuering: false,
|
||||
results: {},
|
||||
fields: {},
|
||||
lastTable: null
|
||||
};
|
||||
},
|
||||
@ -62,45 +63,54 @@ export default {
|
||||
},
|
||||
isSelected () {
|
||||
return this.workspace.selected_tab === 1;
|
||||
},
|
||||
query () {
|
||||
return `SELECT * FROM \`${this.table}\` LIMIT 1000`;// TODO: use query builder
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
table: function () {
|
||||
if (this.isSelected) {
|
||||
this.runQuery();
|
||||
this.getTableData();
|
||||
this.lastTable = this.table;
|
||||
}
|
||||
},
|
||||
isSelected: function (val) {
|
||||
if (val && this.lastTable !== this.table) {
|
||||
this.runQuery();
|
||||
this.getTableData();
|
||||
this.lastTable = this.table;
|
||||
}
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.runQuery();
|
||||
this.getTableData();
|
||||
},
|
||||
methods: {
|
||||
...mapActions({
|
||||
addNotification: 'notifications/addNotification'
|
||||
}),
|
||||
async runQuery () {
|
||||
async getTableData () {
|
||||
if (!this.table) return;
|
||||
this.isQuering = true;
|
||||
this.results = {};
|
||||
|
||||
const params = {
|
||||
uid: this.connection.uid,
|
||||
query: this.query,
|
||||
database: this.workspace.breadcrumbs.database
|
||||
schema: this.workspace.breadcrumbs.schema,
|
||||
table: this.workspace.breadcrumbs.table
|
||||
};
|
||||
|
||||
try {
|
||||
const { status, response } = await Connection.rawQuery(params);
|
||||
const { status, response } = await Structure.getTableColumns(params);
|
||||
if (status === 'success')
|
||||
this.fields = response.rows;
|
||||
else
|
||||
this.addNotification({ status: 'error', message: response });
|
||||
}
|
||||
catch (err) {
|
||||
this.addNotification({ status: 'error', message: err.stack });
|
||||
}
|
||||
|
||||
try {
|
||||
const { status, response } = await Structure.getTableData(params);
|
||||
console.log(status, response);
|
||||
if (status === 'success')
|
||||
this.results = response;
|
||||
else
|
||||
|
Reference in New Issue
Block a user