Skip to content

Commit

Permalink
fix: select of table type stuck when editing an unknown type
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Feb 4, 2023
1 parent 6decba3 commit e8447e5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
3 changes: 0 additions & 3 deletions src/common/interfaces/antares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
65 changes: 33 additions & 32 deletions src/main/libs/clients/MySQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,25 +254,15 @@ export class MySQLClient extends AntaresCore {
async getStructure (schemas: Set<string>) {
/* 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 {
Expand Down Expand Up @@ -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<antares.QueryResult<ShowTableResult>>(`SHOW TABLE STATUS FROM \`${db.Database}\``);
let { rows: tables } = await this.raw<antares.QueryResult<ShowTableResult>>(`
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);
Expand All @@ -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;
Expand All @@ -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
};
});

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/WorkspaceTabPropsTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down

0 comments on commit e8447e5

Please sign in to comment.