From e8447e56551871a200517bdaa747ae215ad83cf4 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Sat, 4 Feb 2023 11:34:53 +0100 Subject: [PATCH] fix: select of table type stuck when editing an unknown type --- src/common/interfaces/antares.ts | 3 - src/main/libs/clients/MySQLClient.ts | 65 ++++++++++--------- .../components/WorkspaceTabPropsTableRow.vue | 2 +- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/common/interfaces/antares.ts b/src/common/interfaces/antares.ts index 2662b455..bb61eac1 100644 --- a/src/common/interfaces/antares.ts +++ b/src/common/interfaces/antares.ts @@ -85,12 +85,9 @@ export interface TableInfos { name: string; type: string; rows: number; - created: Date; - updated: Date; engine: string; comment: string; size: number | false; - autoIncrement: number; collation: string; } diff --git a/src/main/libs/clients/MySQLClient.ts b/src/main/libs/clients/MySQLClient.ts index 7993dd06..9e27c7a3 100644 --- a/src/main/libs/clients/MySQLClient.ts +++ b/src/main/libs/clients/MySQLClient.ts @@ -254,25 +254,15 @@ export class MySQLClient extends AntaresCore { async getStructure (schemas: Set) { /* eslint-disable camelcase */ interface ShowTableResult { - Db?: string; - Name: string; - Engine: string; - Version: number; - Row_format: string; - Rows: number; - Avg_row_length: number; - Data_length: number; - Max_data_length: number; - Index_length: number; - Data_free: number; - Auto_increment: number; - Create_time: Date; - Update_time: Date; - Check_time?: number; - Collation: string; - Checksum?: number; - Create_options: string; - Comment: string; + TABLE_SCHEMA?: string; + TABLE_NAME: string; + TABLE_TYPE: string; + TABLE_ROWS: number; + ENGINE: string; + DATA_LENGTH: number; + INDEX_LENGTH: number; + TABLE_COLLATION: string; + TABLE_COMMENT: string; } interface ShowTriggersResult { @@ -309,10 +299,24 @@ export class MySQLClient extends AntaresCore { for (const db of filteredDatabases) { if (!schemas.has(db.Database)) continue; - let { rows: tables } = await this.raw>(`SHOW TABLE STATUS FROM \`${db.Database}\``); + let { rows: tables } = await this.raw>(` + SELECT + TABLE_NAME, + TABLE_TYPE, + ENGINE, + DATA_LENGTH, + INDEX_LENGTH, + TABLE_COMMENT, + TABLE_COLLATION, + CREATE_TIME, + UPDATE_TIME + FROM information_schema.TABLES + WHERE TABLE_SCHEMA = "${db.Database}" + `); + if (tables.length) { tables = tables.map(table => { - table.Db = db.Database; + table.TABLE_SCHEMA = db.Database; return table; }); tablesArr.push(...tables); @@ -331,9 +335,9 @@ export class MySQLClient extends AntaresCore { return filteredDatabases.map(db => { if (schemas.has(db.Database)) { // TABLES - const remappedTables: antares.TableInfos[] = tablesArr.filter(table => table.Db === db.Database).map(table => { + const remappedTables: antares.TableInfos[] = tablesArr.filter(table => table.TABLE_SCHEMA === db.Database).map(table => { let tableType; - switch (table.Comment) { + switch (table.TABLE_TYPE) { case 'VIEW': tableType = 'view'; break; @@ -342,20 +346,17 @@ export class MySQLClient extends AntaresCore { break; } - const tableSize = Number(table.Data_length) + Number(table.Index_length); + const tableSize = Number(table.DATA_LENGTH) + Number(table.INDEX_LENGTH); schemaSize += tableSize; return { - name: table.Name, + name: table.TABLE_NAME, type: tableType, - rows: table.Rows, - created: table.Create_time, - updated: table.Update_time, - engine: table.Engine, - comment: table.Comment, + rows: table.TABLE_ROWS, + engine: table.ENGINE, + comment: table.TABLE_COMMENT, size: tableSize, - autoIncrement: table.Auto_increment, - collation: table.Collation + collation: table.TABLE_COLLATION }; }); diff --git a/src/renderer/components/WorkspaceTabPropsTableRow.vue b/src/renderer/components/WorkspaceTabPropsTableRow.vue index 5f2b7977..c9293a0a 100644 --- a/src/renderer/components/WorkspaceTabPropsTableRow.vue +++ b/src/renderer/components/WorkspaceTabPropsTableRow.vue @@ -410,7 +410,7 @@ const types = computed(() => { const types = [...props.dataTypes]; if (!isInDataTypes.value) // eslint-disable-next-line @typescript-eslint/no-explicit-any - (types as any).unshift({ name: props.row }); + (types as any).unshift({ name: props.row.type }); return types; });