diff --git a/src/main/ipc-handlers/connection.js b/src/main/ipc-handlers/connection.js index e6184689..dc5c5095 100644 --- a/src/main/ipc-handlers/connection.js +++ b/src/main/ipc-handlers/connection.js @@ -39,8 +39,7 @@ export default connections => { port: +conn.port, user: conn.user, password: conn.password - }, - poolSize: 3 + } }); try { diff --git a/src/main/ipc-handlers/database.js b/src/main/ipc-handlers/database.js index 82c9d967..ee3387c2 100644 --- a/src/main/ipc-handlers/database.js +++ b/src/main/ipc-handlers/database.js @@ -5,9 +5,9 @@ export default connections => { ipcMain.handle('create-database', async (event, params) => { try { const query = `CREATE DATABASE \`${params.name}\` COLLATE ${params.collation}`; - const result = await connections[params.uid].raw(query, true); + await connections[params.uid].raw(query); - return { status: 'success', response: result }; + return { status: 'success' }; } catch (err) { return { status: 'error', response: err.toString() }; @@ -47,13 +47,22 @@ export default connections => { } }); + ipcMain.handle('use-schema', async (event, { uid, schema }) => { + if (!schema) return; + + try { + await connections[uid].use(schema); + return { status: 'success' }; + } + catch (err) { + return { status: 'error', response: err.toString() }; + } + }); + ipcMain.handle('raw-query', async (event, { uid, query, schema }) => { if (!query) return; try { - if (schema) - await connections[uid].use(schema); - const result = await connections[uid].raw(query, true); return { status: 'success', response: result }; diff --git a/src/main/libs/clients/MySQLClient.js b/src/main/libs/clients/MySQLClient.js index 1e1382be..732443a6 100644 --- a/src/main/libs/clients/MySQLClient.js +++ b/src/main/libs/clients/MySQLClient.js @@ -27,8 +27,7 @@ export class MySQLClient extends AntaresCore { * @memberof MySQLClient */ use (schema) { - const sql = `USE \`${schema}\``; - return this.raw(sql); + return this.raw(`USE \`${schema}\``); } /** @@ -48,7 +47,7 @@ export class MySQLClient extends AntaresCore { return databases.map(db => { return { name: db.Database, - tables: tables.filter(table => table.TABLE_SCHEMA === db.Database) + tables: tables.filter(table => table.TABLE_SCHEMA === db.Database)// TODO: remap tables objects }; }); } diff --git a/src/renderer/ipc-api/Database.js b/src/renderer/ipc-api/Database.js index acc311de..22985909 100644 --- a/src/renderer/ipc-api/Database.js +++ b/src/renderer/ipc-api/Database.js @@ -18,6 +18,10 @@ export default class { return ipcRenderer.invoke('get-variables', uid); } + static useSchema (params) { + return ipcRenderer.invoke('use-schema', params); + } + static rawQuery (params) { return ipcRenderer.invoke('raw-query', params); } diff --git a/src/renderer/store/modules/workspaces.store.js b/src/renderer/store/modules/workspaces.store.js index 9ec3295e..66f9baea 100644 --- a/src/renderer/store/modules/workspaces.store.js +++ b/src/renderer/store/modules/workspaces.store.js @@ -3,6 +3,7 @@ import Connection from '@/ipc-api/Connection'; import Database from '@/ipc-api/Database'; import { uidGen } from 'common/libs/uidGen'; const tabIndex = []; +let lastSchema = ''; export default { namespaced: true, @@ -222,6 +223,11 @@ export default { dispatch('newTab', uid); }, changeBreadcrumbs ({ commit, getters }, payload) { + if (lastSchema !== payload.schema) { + Database.useSchema({ uid: getters.getSelected, schema: payload.schema }); + lastSchema = payload.schema; + } + commit('CHANGE_BREADCRUMBS', { uid: getters.getSelected, breadcrumbs: payload }); }, newTab ({ commit }, uid) {