mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
refactor: moved queri fields mapping to main process
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
export const TEXT = ['char', 'varchar'];
|
export const TEXT = ['char', 'varchar'];
|
||||||
export const LONG_TEXT = ['text', 'mediumtext', 'longtext'];
|
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 DATE = ['date'];
|
||||||
export const TIME = ['time'];
|
export const TIME = ['time'];
|
||||||
|
@ -13,13 +13,22 @@ export default class {
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
static getTableColumns (connection, schema, table) {
|
static async getTableColumns (connection, schema, table) {
|
||||||
return connection
|
const { rows } = await connection
|
||||||
.select('*')
|
.select('*')
|
||||||
.schema('information_schema')
|
.schema('information_schema')
|
||||||
.from('COLUMNS')
|
.from('COLUMNS')
|
||||||
.where({ TABLE_SCHEMA: `= '${schema}'`, TABLE_NAME: `= '${table}'` })
|
.where({ TABLE_SCHEMA: `= '${schema}'`, TABLE_NAME: `= '${table}'` })
|
||||||
.orderBy({ ORDINAL_POSITION: 'ASC' })
|
.orderBy({ ORDINAL_POSITION: 'ASC' })
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
|
return rows.map(field => {
|
||||||
|
return {
|
||||||
|
name: field.COLUMN_NAME,
|
||||||
|
key: field.COLUMN_KEY.toLowerCase(),
|
||||||
|
type: field.DATA_TYPE,
|
||||||
|
precision: field.DATETIME_PRECISION
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,11 @@
|
|||||||
class="btn btn-link btn-sm"
|
class="btn btn-link btn-sm"
|
||||||
:class="{'loading':isQuering}"
|
:class="{'loading':isQuering}"
|
||||||
:disabled="!query"
|
:disabled="!query"
|
||||||
@click="runQuery"
|
@click="runQuery(query)"
|
||||||
>
|
>
|
||||||
<span>{{ $t('word.run') }}</span>
|
<span>{{ $t('word.run') }}</span>
|
||||||
<i class="material-icons text-success">play_arrow</i>
|
<i class="material-icons text-success">play_arrow</i>
|
||||||
</button>
|
</button>
|
||||||
<!-- <button class="btn btn-link btn-sm">
|
|
||||||
<span>{{ $t('word.save') }}</span>
|
|
||||||
<i class="material-icons ml-1">save</i>
|
|
||||||
</button> -->
|
|
||||||
</div>
|
</div>
|
||||||
<div class="workspace-query-info">
|
<div class="workspace-query-info">
|
||||||
<div v-if="results.rows">
|
<div v-if="results.rows">
|
||||||
@ -33,7 +29,7 @@
|
|||||||
v-if="results"
|
v-if="results"
|
||||||
ref="queryTable"
|
ref="queryTable"
|
||||||
:results="results"
|
:results="results"
|
||||||
:fields="resultsFields"
|
:fields="fields"
|
||||||
@updateField="updateField"
|
@updateField="updateField"
|
||||||
@deleteSelected="deleteSelected"
|
@deleteSelected="deleteSelected"
|
||||||
/>
|
/>
|
||||||
@ -62,6 +58,7 @@ export default {
|
|||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
query: '',
|
query: '',
|
||||||
|
lastQuery: '',
|
||||||
isQuering: false,
|
isQuering: false,
|
||||||
results: {},
|
results: {},
|
||||||
fields: []
|
fields: []
|
||||||
@ -74,25 +71,6 @@ export default {
|
|||||||
workspace () {
|
workspace () {
|
||||||
return this.getWorkspace(this.connection.uid);
|
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 () {
|
table () {
|
||||||
if (this.results.fields.length)
|
if (this.results.fields.length)
|
||||||
return this.results.fields[0].orgTable;
|
return this.results.fields[0].orgTable;
|
||||||
@ -103,15 +81,15 @@ export default {
|
|||||||
...mapActions({
|
...mapActions({
|
||||||
addNotification: 'notifications/addNotification'
|
addNotification: 'notifications/addNotification'
|
||||||
}),
|
}),
|
||||||
async runQuery () {
|
async runQuery (query) {
|
||||||
if (!this.query) return;
|
if (!query) return;
|
||||||
this.isQuering = true;
|
this.isQuering = true;
|
||||||
this.results = {};
|
this.results = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const params = {
|
const params = {
|
||||||
uid: this.connection.uid,
|
uid: this.connection.uid,
|
||||||
query: this.query,
|
query,
|
||||||
schema: this.workspace.breadcrumbs.schema
|
schema: this.workspace.breadcrumbs.schema
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -134,7 +112,7 @@ export default {
|
|||||||
|
|
||||||
const { status, response } = await Tables.getTableColumns(params);
|
const { status, response } = await Tables.getTableColumns(params);
|
||||||
if (status === 'success')
|
if (status === 'success')
|
||||||
this.fields = response.rows;
|
this.fields = response;
|
||||||
else
|
else
|
||||||
this.addNotification({ status: 'error', message: response });
|
this.addNotification({ status: 'error', message: response });
|
||||||
}
|
}
|
||||||
@ -143,9 +121,10 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.isQuering = false;
|
this.isQuering = false;
|
||||||
|
this.lastQuery = query;
|
||||||
},
|
},
|
||||||
reloadTable () {
|
reloadTable () {
|
||||||
this.runQuery();// TODO: run last executed query
|
this.runQuery(this.lastQuery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -11,10 +11,14 @@
|
|||||||
<span>{{ $t('word.refresh') }}</span>
|
<span>{{ $t('word.refresh') }}</span>
|
||||||
<i class="material-icons ml-1">refresh</i>
|
<i class="material-icons ml-1">refresh</i>
|
||||||
</button>
|
</button>
|
||||||
<!-- <button class="btn btn-link btn-sm">
|
<button
|
||||||
<span>{{ $t('word.save') }}</span>
|
class="btn btn-link btn-sm"
|
||||||
<i class="material-icons ml-1">save</i>
|
:class="{'disabled':isQuering}"
|
||||||
</button> -->
|
@click="showAddModal"
|
||||||
|
>
|
||||||
|
<span>{{ $t('word.add') }}</span>
|
||||||
|
<i class="material-icons ml-1">playlist_add</i>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="workspace-query-info">
|
<div class="workspace-query-info">
|
||||||
<div v-if="results.rows">
|
<div v-if="results.rows">
|
||||||
@ -31,7 +35,7 @@
|
|||||||
v-if="results"
|
v-if="results"
|
||||||
ref="queryTable"
|
ref="queryTable"
|
||||||
:results="results"
|
:results="results"
|
||||||
:fields="resultsFields"
|
:fields="fields"
|
||||||
@updateField="updateField"
|
@updateField="updateField"
|
||||||
@deleteSelected="deleteSelected"
|
@deleteSelected="deleteSelected"
|
||||||
/>
|
/>
|
||||||
@ -72,16 +76,6 @@ export default {
|
|||||||
},
|
},
|
||||||
isSelected () {
|
isSelected () {
|
||||||
return this.workspace.selected_tab === 1;
|
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: {
|
watch: {
|
||||||
@ -119,7 +113,7 @@ export default {
|
|||||||
try {
|
try {
|
||||||
const { status, response } = await Tables.getTableColumns(params);
|
const { status, response } = await Tables.getTableColumns(params);
|
||||||
if (status === 'success')
|
if (status === 'success')
|
||||||
this.fields = response.rows;
|
this.fields = response;
|
||||||
else
|
else
|
||||||
this.addNotification({ status: 'error', message: response });
|
this.addNotification({ status: 'error', message: response });
|
||||||
}
|
}
|
||||||
@ -143,7 +137,8 @@ export default {
|
|||||||
},
|
},
|
||||||
reloadTable () {
|
reloadTable () {
|
||||||
this.getTableData();
|
this.getTableData();
|
||||||
}
|
},
|
||||||
|
showAddModal () {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -34,7 +34,8 @@ module.exports = {
|
|||||||
seconds: 'Seconds',
|
seconds: 'Seconds',
|
||||||
type: 'Type',
|
type: 'Type',
|
||||||
mimeType: 'Mime-Type',
|
mimeType: 'Mime-Type',
|
||||||
download: 'Download'
|
download: 'Download',
|
||||||
|
add: 'Add'
|
||||||
},
|
},
|
||||||
message: {
|
message: {
|
||||||
appWelcome: 'Welcome to Antares SQL Client!',
|
appWelcome: 'Welcome to Antares SQL Client!',
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
"tinyint": cornflowerblue,
|
"tinyint": cornflowerblue,
|
||||||
"smallint": cornflowerblue,
|
"smallint": cornflowerblue,
|
||||||
"mediumint": cornflowerblue,
|
"mediumint": cornflowerblue,
|
||||||
|
"float": cornflowerblue,
|
||||||
|
"double": cornflowerblue,
|
||||||
|
"decimal": cornflowerblue,
|
||||||
"bigint": cornflowerblue,
|
"bigint": cornflowerblue,
|
||||||
"datetime": coral,
|
"datetime": coral,
|
||||||
"date": coral,
|
"date": coral,
|
||||||
|
Reference in New Issue
Block a user