diff --git a/src/common/fieldTypes.js b/src/common/fieldTypes.js index f67139af..d3968caf 100644 --- a/src/common/fieldTypes.js +++ b/src/common/fieldTypes.js @@ -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']; diff --git a/src/main/models/InformationSchema.js b/src/main/models/InformationSchema.js index 8fa47e30..108c4015 100644 --- a/src/main/models/InformationSchema.js +++ b/src/main/models/InformationSchema.js @@ -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 + }; + }); } } diff --git a/src/renderer/components/WorkspaceQueryTab.vue b/src/renderer/components/WorkspaceQueryTab.vue index 7ba08b3d..6d60b946 100644 --- a/src/renderer/components/WorkspaceQueryTab.vue +++ b/src/renderer/components/WorkspaceQueryTab.vue @@ -8,15 +8,11 @@ class="btn btn-link btn-sm" :class="{'loading':isQuering}" :disabled="!query" - @click="runQuery" + @click="runQuery(query)" > {{ $t('word.run') }} play_arrow -
@@ -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); } } }; diff --git a/src/renderer/components/WorkspaceTableTab.vue b/src/renderer/components/WorkspaceTableTab.vue index a9949967..310eb979 100644 --- a/src/renderer/components/WorkspaceTableTab.vue +++ b/src/renderer/components/WorkspaceTableTab.vue @@ -11,10 +11,14 @@ {{ $t('word.refresh') }} refresh - +
@@ -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 () {} } }; diff --git a/src/renderer/i18n/en-US.js b/src/renderer/i18n/en-US.js index a5cb12db..b62ac215 100644 --- a/src/renderer/i18n/en-US.js +++ b/src/renderer/i18n/en-US.js @@ -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!', diff --git a/src/renderer/scss/_data-types.scss b/src/renderer/scss/_data-types.scss index a9c50a31..74c716c1 100644 --- a/src/renderer/scss/_data-types.scss +++ b/src/renderer/scss/_data-types.scss @@ -21,6 +21,9 @@ "tinyint": cornflowerblue, "smallint": cornflowerblue, "mediumint": cornflowerblue, + "float": cornflowerblue, + "double": cornflowerblue, + "decimal": cornflowerblue, "bigint": cornflowerblue, "datetime": coral, "date": coral,