1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-02-15 19:20:52 +01:00

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 { try {
await connection.connect(); await connection.connect();
const { rows: structure } = await connection const structure = await connection.getStructure();
.select('*')
.schema('information_schema')
.from('TABLES')
.orderBy({ TABLE_SCHEMA: 'ASC', TABLE_NAME: 'ASC' })
.run();
connections[conn.uid] = connection; connections[conn.uid] = connection;

View File

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

View File

@ -23,7 +23,7 @@ export class MySQLClient extends AntaresCore {
/** /**
* Executes an USE query * Executes an USE query
* *
* @param {*} schema * @param {String} schema
* @memberof MySQLClient * @memberof MySQLClient
*/ */
use (schema) { use (schema) {
@ -31,15 +31,36 @@ export class MySQLClient extends AntaresCore {
return this.raw(sql); 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 * SHOW COLLATION
* *
* @returns * @returns {Array.<Object>} collations list
* @memberof MySQLClient * @memberof MySQLClient
*/ */
async getCollations () { async getCollations () {
const sql = 'SHOW COLLATION'; const results = await this.raw('SHOW COLLATION');
const results = await this.raw(sql);
return results.rows.map(row => { return results.rows.map(row => {
return { return {
@ -56,7 +77,7 @@ export class MySQLClient extends AntaresCore {
/** /**
* SHOW VARIABLES * SHOW VARIABLES
* *
* @returns * @returns {Array.<Object>} variables list
* @memberof MySQLClient * @memberof MySQLClient
*/ */
async getVariables () { async getVariables () {
@ -72,7 +93,7 @@ export class MySQLClient extends AntaresCore {
} }
/** /**
* @returns {string} SQL string * @returns {String} SQL string
* @memberof MySQLClient * @memberof MySQLClient
*/ */
getSQL () { getSQL () {

View File

@ -4,18 +4,6 @@ import Database from '@/ipc-api/Database';
import { uidGen } from 'common/libs/uidGen'; import { uidGen } from 'common/libs/uidGen';
const tabIndex = []; 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 { export default {
namespaced: true, namespaced: true,
strict: true, strict: true,
@ -155,7 +143,7 @@ export default {
if (status === 'error') if (status === 'error')
dispatch('notifications/addNotification', { status, message: response }, { root: true }); dispatch('notifications/addNotification', { status, message: response }, { root: true });
else { else {
commit('ADD_CONNECTED', { uid: connection.uid, structure: remapStructure(response) }); commit('ADD_CONNECTED', { uid: connection.uid, structure: response });
dispatch('refreshCollations', connection.uid); dispatch('refreshCollations', connection.uid);
dispatch('refreshVariables', connection.uid); dispatch('refreshVariables', connection.uid);
} }
@ -170,7 +158,7 @@ export default {
if (status === 'error') if (status === 'error')
dispatch('notifications/addNotification', { status, message: response }, { root: true }); dispatch('notifications/addNotification', { status, message: response }, { root: true });
else else
commit('REFRESH_STRUCTURE', { uid, structure: remapStructure(response) }); commit('REFRESH_STRUCTURE', { uid, structure: response });
} }
catch (err) { catch (err) {
dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true }); dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true });