1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-02-11 01:00:52 +01:00

refactor: moved queri fields mapping to main process

This commit is contained in:
Fabio 2020-08-05 22:08:20 +02:00
parent 0089c0cbac
commit 5c05e3e9e9
6 changed files with 38 additions and 51 deletions

View File

@ -1,7 +1,7 @@
export const TEXT = ['char', 'varchar'];
export const LONG_TEXT = ['text', 'mediumtext', 'longtext'];
export const NUMBER = ['int', 'tinyint', 'smallint', 'mediumint', 'bigint'];
export const NUMBER = ['int', 'tinyint', 'smallint', 'mediumint', 'bigint', 'float', 'double', 'decimal'];
export const DATE = ['date'];
export const TIME = ['time'];

View File

@ -13,13 +13,22 @@ export default class {
.run();
}
static getTableColumns (connection, schema, table) {
return connection
static async getTableColumns (connection, schema, table) {
const { rows } = await connection
.select('*')
.schema('information_schema')
.from('COLUMNS')
.where({ TABLE_SCHEMA: `= '${schema}'`, TABLE_NAME: `= '${table}'` })
.orderBy({ ORDINAL_POSITION: 'ASC' })
.run();
return rows.map(field => {
return {
name: field.COLUMN_NAME,
key: field.COLUMN_KEY.toLowerCase(),
type: field.DATA_TYPE,
precision: field.DATETIME_PRECISION
};
});
}
}

View File

@ -8,15 +8,11 @@
class="btn btn-link btn-sm"
:class="{'loading':isQuering}"
:disabled="!query"
@click="runQuery"
@click="runQuery(query)"
>
<span>{{ $t('word.run') }}</span>
<i class="material-icons text-success">play_arrow</i>
</button>
<!-- <button class="btn btn-link btn-sm">
<span>{{ $t('word.save') }}</span>
<i class="material-icons ml-1">save</i>
</button> -->
</div>
<div class="workspace-query-info">
<div v-if="results.rows">
@ -33,7 +29,7 @@
v-if="results"
ref="queryTable"
:results="results"
:fields="resultsFields"
:fields="fields"
@updateField="updateField"
@deleteSelected="deleteSelected"
/>
@ -62,6 +58,7 @@ export default {
data () {
return {
query: '',
lastQuery: '',
isQuering: false,
results: {},
fields: []
@ -74,25 +71,6 @@ export default {
workspace () {
return this.getWorkspace(this.connection.uid);
},
resultsFields () {
if (this.results) {
return this.fields.map(field => { // TODO: move to main process
return {
name: field.COLUMN_NAME,
key: field.COLUMN_KEY.toLowerCase(),
type: field.DATA_TYPE,
precision: field.DATETIME_PRECISION
};
}).filter(field => {
if (this.results.fields) {
const queryFields = this.results.fields.map(field => field.name);
if (queryFields.includes(field.name)) return field;
}
});
}
else
return [];
},
table () {
if (this.results.fields.length)
return this.results.fields[0].orgTable;
@ -103,15 +81,15 @@ export default {
...mapActions({
addNotification: 'notifications/addNotification'
}),
async runQuery () {
if (!this.query) return;
async runQuery (query) {
if (!query) return;
this.isQuering = true;
this.results = {};
try {
const params = {
uid: this.connection.uid,
query: this.query,
query,
schema: this.workspace.breadcrumbs.schema
};
@ -134,7 +112,7 @@ export default {
const { status, response } = await Tables.getTableColumns(params);
if (status === 'success')
this.fields = response.rows;
this.fields = response;
else
this.addNotification({ status: 'error', message: response });
}
@ -143,9 +121,10 @@ export default {
}
this.isQuering = false;
this.lastQuery = query;
},
reloadTable () {
this.runQuery();// TODO: run last executed query
this.runQuery(this.lastQuery);
}
}
};

View File

@ -11,10 +11,14 @@
<span>{{ $t('word.refresh') }}</span>
<i class="material-icons ml-1">refresh</i>
</button>
<!-- <button class="btn btn-link btn-sm">
<span>{{ $t('word.save') }}</span>
<i class="material-icons ml-1">save</i>
</button> -->
<button
class="btn btn-link btn-sm"
:class="{'disabled':isQuering}"
@click="showAddModal"
>
<span>{{ $t('word.add') }}</span>
<i class="material-icons ml-1">playlist_add</i>
</button>
</div>
<div class="workspace-query-info">
<div v-if="results.rows">
@ -31,7 +35,7 @@
v-if="results"
ref="queryTable"
:results="results"
:fields="resultsFields"
:fields="fields"
@updateField="updateField"
@deleteSelected="deleteSelected"
/>
@ -72,16 +76,6 @@ export default {
},
isSelected () {
return this.workspace.selected_tab === 1;
},
resultsFields () {
return this.fields.map(field => { // TODO: move to main process
return {
name: field.COLUMN_NAME,
key: field.COLUMN_KEY.toLowerCase(),
type: field.DATA_TYPE,
precision: field.DATETIME_PRECISION
};
});
}
},
watch: {
@ -119,7 +113,7 @@ export default {
try {
const { status, response } = await Tables.getTableColumns(params);
if (status === 'success')
this.fields = response.rows;
this.fields = response;
else
this.addNotification({ status: 'error', message: response });
}
@ -143,7 +137,8 @@ export default {
},
reloadTable () {
this.getTableData();
}
},
showAddModal () {}
}
};
</script>

View File

@ -34,7 +34,8 @@ module.exports = {
seconds: 'Seconds',
type: 'Type',
mimeType: 'Mime-Type',
download: 'Download'
download: 'Download',
add: 'Add'
},
message: {
appWelcome: 'Welcome to Antares SQL Client!',

View File

@ -21,6 +21,9 @@
"tinyint": cornflowerblue,
"smallint": cornflowerblue,
"mediumint": cornflowerblue,
"float": cornflowerblue,
"double": cornflowerblue,
"decimal": cornflowerblue,
"bigint": cornflowerblue,
"datetime": coral,
"date": coral,