From bebba64d06532990405763284e27cb768dc050f7 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Tue, 4 May 2021 21:50:41 +0200 Subject: [PATCH] feat(MySQL): ENUM and SET fields support, closes #61 --- src/common/data-types/mysql.js | 19 +++++++++----- src/main/libs/clients/MySQLClient.js | 10 ++++--- .../components/WorkspacePropsTableRow.vue | 26 +++++++++++++++---- .../components/WorkspaceQueryTableRow.vue | 15 +++++++++++ 4 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/common/data-types/mysql.js b/src/common/data-types/mysql.js index 3e0315ea..78e3d2c9 100644 --- a/src/common/data-types/mysql.js +++ b/src/common/data-types/mysql.js @@ -277,13 +277,6 @@ module.exports = [ { group: 'other', types: [ - { - name: 'UNKNOWN', - length: false, - collation: false, - unsigned: false, - zerofill: false - }, { name: 'ENUM', length: true, @@ -299,5 +292,17 @@ module.exports = [ zerofill: false } ] + }, + { + group: 'unknown', + types: [ + { + name: 'UNKNOWN', + length: false, + collation: false, + unsigned: false, + zerofill: false + } + ] } ]; diff --git a/src/main/libs/clients/MySQLClient.js b/src/main/libs/clients/MySQLClient.js index ffdf3ce8..29680a28 100644 --- a/src/main/libs/clients/MySQLClient.js +++ b/src/main/libs/clients/MySQLClient.js @@ -310,6 +310,9 @@ export class MySQLClient extends AntaresCore { return rows.map(field => { let numLength = field.COLUMN_TYPE.match(/int\(([^)]+)\)/); numLength = numLength ? +numLength.pop() : null; + const enumValues = /(enum|set)/.test(field.COLUMN_TYPE) + ? field.COLUMN_TYPE.match(/\(([^)]+)\)/)[0].slice(1, -1) + : null; return { name: field.COLUMN_NAME, @@ -319,6 +322,7 @@ export class MySQLClient extends AntaresCore { table: field.TABLE_NAME, numPrecision: field.NUMERIC_PRECISION, numLength, + enumValues, datePrecision: field.DATETIME_PRECISION, charLength: field.CHARACTER_MAXIMUM_LENGTH, nullable: field.IS_NULLABLE.includes('YES'), @@ -1116,7 +1120,7 @@ export class MySQLClient extends AntaresCore { // CHANGE FIELDS changes.forEach(change => { const typeInfo = this._getTypeInfo(change.type); - const length = typeInfo.length ? change.numLength || change.charLength || change.datePrecision : false; + const length = typeInfo.length ? change.enumValues || change.numLength || change.charLength || change.datePrecision : false; alterColumns.push(`CHANGE COLUMN \`${change.orgName}\` \`${change.name}\` ${change.type.toUpperCase()}${length ? `(${length})` : ''} @@ -1190,7 +1194,7 @@ export class MySQLClient extends AntaresCore { * @memberof MySQLClient */ async truncateTable (params) { - const sql = `TRUNCATE TABLE \`${params.table}\``; + const sql = `TRUNCATE TABLE \`${this._schema}\`.\`${params.table}\``; return await this.raw(sql); } @@ -1201,7 +1205,7 @@ export class MySQLClient extends AntaresCore { * @memberof MySQLClient */ async dropTable (params) { - const sql = `DROP TABLE \`${params.table}\``; + const sql = `DROP TABLE \`${this._schema}\`.\`${params.table}\``; return await this.raw(sql); } diff --git a/src/renderer/components/WorkspacePropsTableRow.vue b/src/renderer/components/WorkspacePropsTableRow.vue index 8394bacd..3464f4b7 100644 --- a/src/renderer/components/WorkspacePropsTableRow.vue +++ b/src/renderer/components/WorkspacePropsTableRow.vue @@ -98,6 +98,15 @@ > {{ localLength }} + [...acc, ...group.types], []).filter(type => @@ -458,14 +467,21 @@ export default { editON (event, content, field) { if (field === 'length') { if (['integer', 'float', 'binary', 'spatial'].includes(this.fieldType.group)) this.editingField = 'numLength'; - if (['string', 'other'].includes(this.fieldType.group)) this.editingField = 'charLength'; - if (['time'].includes(this.fieldType.group)) this.editingField = 'datePrecision'; + else if (['string', 'unknown'].includes(this.fieldType.group)) this.editingField = 'charLength'; + else if (['other'].includes(this.fieldType.group)) this.editingField = 'enumValues'; + else if (['time'].includes(this.fieldType.group)) this.editingField = 'datePrecision'; } else this.editingField = field; - this.editingContent = content; - this.originalContent = content; + if (this.localRow.enumValues && field === 'length') { + this.editingContent = this.localRow.enumValues; + this.originalContent = this.localRow.enumValues; + } + else { + this.editingContent = content; + this.originalContent = content; + } const obj = { [field]: true }; this.isInlineEditor = { ...this.isInlineEditor, ...obj }; diff --git a/src/renderer/components/WorkspaceQueryTableRow.vue b/src/renderer/components/WorkspaceQueryTableRow.vue index 2f9b2a57..2a485b9f 100644 --- a/src/renderer/components/WorkspaceQueryTableRow.vue +++ b/src/renderer/components/WorkspaceQueryTableRow.vue @@ -43,6 +43,16 @@ +