feat: display all keys in properties tab

This commit is contained in:
Fabio Di Stasio 2020-11-20 17:24:02 +01:00
parent dfb24c65f3
commit 27769f204f
7 changed files with 83 additions and 11 deletions

View File

@ -30,6 +30,17 @@ export default (connections) => {
} }
}); });
ipcMain.handle('get-table-indexes', async (event, params) => {
try {
const result = await connections[params.uid].getTableIndexes(params);
return { status: 'success', response: result };
}
catch (err) {
return { status: 'error', response: err.toString() };
}
});
ipcMain.handle('get-key-usage', async (event, params) => { ipcMain.handle('get-key-usage', async (event, params) => {
try { try {
const result = await connections[params.uid].getKeyUsage(params); const result = await connections[params.uid].getKeyUsage(params);

View File

@ -198,6 +198,30 @@ export class MySQLClient extends AntaresCore {
}); });
} }
/**
* @param {Object} params
* @param {String} params.schema
* @param {String} params.table
* @returns {Object} table indexes
* @memberof MySQLClient
*/
async getTableIndexes ({ schema, table }) {
const { rows } = await this.raw(`SHOW INDEXES FROM \`${table}\` FROM \`${schema}\``);
return rows.map(row => {
return {
unique: !row.Non_unique,
name: row.Key_name,
column: row.Column_name,
indexType: row.Index_type,
type: row.Key_name === 'PRIMARY' ? 'PRIMARY' : !row.Non_unique ? 'UNIQUE' : row.Index_type === 'FULLTEXT' ? 'FULLTEXT' : 'INDEX',
cardinality: row.Cardinality,
comment: row.Comment,
indexComment: row.Index_comment
};
});
}
/** /**
* @param {Object} params * @param {Object} params
* @param {String} params.schema * @param {String} params.schema

View File

@ -32,7 +32,7 @@
<span>{{ $t('word.add') }}</span> <span>{{ $t('word.add') }}</span>
<i class="mdi mdi-24px mdi-playlist-plus ml-1" /> <i class="mdi mdi-24px mdi-playlist-plus ml-1" />
</button> </button>
<button class="btn btn-dark btn-sm d-none"> <button class="btn btn-dark btn-sm">
<span>{{ $t('word.indexes') }}</span> <span>{{ $t('word.indexes') }}</span>
<i class="mdi mdi-24px mdi-key mdi-rotate-45 ml-1" /> <i class="mdi mdi-24px mdi-key mdi-rotate-45 ml-1" />
</button> </button>
@ -52,6 +52,7 @@
v-if="localFields" v-if="localFields"
ref="queryTable" ref="queryTable"
:fields="localFields" :fields="localFields"
:indexes="localIndexes"
:tab-uid="tabUid" :tab-uid="tabUid"
:conn-uid="connection.uid" :conn-uid="connection.uid"
:table="table" :table="table"
@ -178,6 +179,8 @@ export default {
localFields: [], localFields: [],
originalKeyUsage: [], originalKeyUsage: [],
localKeyUsage: [], localKeyUsage: [],
originalIndexes: [],
localIndexes: [],
localOptions: [], localOptions: [],
lastTable: null lastTable: null
}; };
@ -257,6 +260,20 @@ export default {
this.addNotification({ status: 'error', message: err.stack }); this.addNotification({ status: 'error', message: err.stack });
} }
try { // Indexes
const { status, response } = await Tables.getTableIndexes(params);
if (status === 'success') {
this.originalIndexes = response;
this.localIndexes = JSON.parse(JSON.stringify(response));
}
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
try { // Key usage (foreign keys) try { // Key usage (foreign keys)
const { status, response } = await Tables.getKeyUsage(params); const { status, response } = await Tables.getKeyUsage(params);

View File

@ -99,6 +99,7 @@
v-for="row in fields" v-for="row in fields"
:key="row._id" :key="row._id"
:row="row" :row="row"
:indexes="getIndexes(row.name)"
:data-types="dataTypes" :data-types="dataTypes"
@contextmenu="contextMenu" @contextmenu="contextMenu"
/> />
@ -122,6 +123,7 @@ export default {
}, },
props: { props: {
fields: Array, fields: Array,
indexes: Array,
tabUid: [String, Number], tabUid: [String, Number],
connUid: String, connUid: String,
table: String, table: String,
@ -195,6 +197,9 @@ export default {
}, },
removeField () { removeField () {
this.$emit('remove-field', this.selectedField); this.$emit('remove-field', this.selectedField);
},
getIndexes (field) {
return this.indexes.filter(index => index.column === field);
} }
} }
}; };

View File

@ -7,13 +7,16 @@
</div> </div>
</div> </div>
<div class="td" tabindex="0"> <div class="td" tabindex="0">
<div class="text-center">
<i <i
v-if="localRow.key" v-for="index in indexes"
:title="keyName(localRow.key)" :key="index.name"
class="mdi mdi-key column-key c-help pl-1" :title="index.type"
:class="`key-${localRow.key}`" class="d-inline-block mdi mdi-key column-key c-help"
:class="`key-${index.type}`"
/> />
</div> </div>
</div>
<div class="td"> <div class="td">
<span <span
v-if="!isInlineEditor.name" v-if="!isInlineEditor.name"
@ -279,7 +282,8 @@ export default {
}, },
props: { props: {
row: Object, row: Object,
dataTypes: Array dataTypes: Array,
indexes: Array
}, },
data () { data () {
return { return {

View File

@ -10,6 +10,10 @@ export default class {
return ipcRenderer.invoke('get-table-data', params); return ipcRenderer.invoke('get-table-data', params);
} }
static getTableIndexes (params) {
return ipcRenderer.invoke('get-table-indexes', params);
}
static getKeyUsage (params) { static getKeyUsage (params) {
return ipcRenderer.invoke('get-key-usage', params); return ipcRenderer.invoke('get-key-usage', params);
} }

View File

@ -4,15 +4,22 @@
line-height: 1.5; line-height: 1.5;
margin-right: 0.2rem; margin-right: 0.2rem;
&.key-pri { &.key-pri,
&.key-PRIMARY {
color: goldenrod; color: goldenrod;
} }
&.key-uni { &.key-uni,
&.key-UNIQUE {
color: deepskyblue; color: deepskyblue;
} }
&.key-mul { &.key-mul,
&.key-INDEX {
color: palegreen; color: palegreen;
} }
&.key-FULLTEXT {
color: mediumvioletred;
}
} }