fix: empty databases not shown in explore bar

This commit is contained in:
Fabio 2020-09-27 19:06:13 +02:00
parent 3d0a83f2cf
commit 3e737cba62
4 changed files with 31 additions and 32 deletions

View File

@ -46,12 +46,7 @@ export default connections => {
try {
await connection.connect();
const { rows: structure } = await connection
.select('*')
.schema('information_schema')
.from('TABLES')
.orderBy({ TABLE_SCHEMA: 'ASC', TABLE_NAME: 'ASC' })
.run();
const structure = await connection.getStructure();
connections[conn.uid] = connection;

View File

@ -16,12 +16,7 @@ export default connections => {
ipcMain.handle('get-structure', async (event, uid) => {
try {
const { rows: structure } = await connections[uid]
.select('*')
.schema('information_schema')
.from('TABLES')
.orderBy({ TABLE_SCHEMA: 'ASC', TABLE_NAME: 'ASC' })
.run();
const structure = await connections[uid].getStructure();
return { status: 'success', response: structure };
}

View File

@ -23,7 +23,7 @@ export class MySQLClient extends AntaresCore {
/**
* Executes an USE query
*
* @param {*} schema
* @param {String} schema
* @memberof MySQLClient
*/
use (schema) {
@ -31,15 +31,36 @@ export class MySQLClient extends AntaresCore {
return this.raw(sql);
}
/**
* @returns {Array.<Object>} databases scructure
* @memberof MySQLClient
*/
async getStructure () {
const { rows: databases } = await this.raw('SHOW DATABASES');
const { rows: tables } = await this
.select('*')
.schema('information_schema')
.from('TABLES')
.orderBy({ TABLE_SCHEMA: 'ASC', TABLE_NAME: 'ASC' })
.run();
return databases.map(db => {
return {
name: db.Database,
tables: tables.filter(table => table.TABLE_SCHEMA === db.Database)
};
});
}
/**
* SHOW COLLATION
*
* @returns
* @returns {Array.<Object>} collations list
* @memberof MySQLClient
*/
async getCollations () {
const sql = 'SHOW COLLATION';
const results = await this.raw(sql);
const results = await this.raw('SHOW COLLATION');
return results.rows.map(row => {
return {
@ -56,7 +77,7 @@ export class MySQLClient extends AntaresCore {
/**
* SHOW VARIABLES
*
* @returns
* @returns {Array.<Object>} variables list
* @memberof MySQLClient
*/
async getVariables () {
@ -72,7 +93,7 @@ export class MySQLClient extends AntaresCore {
}
/**
* @returns {string} SQL string
* @returns {String} SQL string
* @memberof MySQLClient
*/
getSQL () {

View File

@ -4,18 +4,6 @@ import Database from '@/ipc-api/Database';
import { uidGen } from 'common/libs/uidGen';
const tabIndex = [];
function remapStructure (structure) { // TODO: move to main process and add fields (for autocomplete purpose), also add empty database
const databases = structure.map(table => table.TABLE_SCHEMA)
.filter((value, index, self) => self.indexOf(value) === index);
return databases.map(db => {
return {
name: db,
tables: structure.filter(table => table.TABLE_SCHEMA === db)
};
});
}
export default {
namespaced: true,
strict: true,
@ -155,7 +143,7 @@ export default {
if (status === 'error')
dispatch('notifications/addNotification', { status, message: response }, { root: true });
else {
commit('ADD_CONNECTED', { uid: connection.uid, structure: remapStructure(response) });
commit('ADD_CONNECTED', { uid: connection.uid, structure: response });
dispatch('refreshCollations', connection.uid);
dispatch('refreshVariables', connection.uid);
}
@ -170,7 +158,7 @@ export default {
if (status === 'error')
dispatch('notifications/addNotification', { status, message: response }, { root: true });
else
commit('REFRESH_STRUCTURE', { uid, structure: remapStructure(response) });
commit('REFRESH_STRUCTURE', { uid, structure: response });
}
catch (err) {
dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true });