mirror of https://github.com/Fabio286/antares.git
refactor: enhanced automatic schema selection
This commit is contained in:
parent
96f38297c1
commit
52449e0420
|
@ -39,8 +39,7 @@ export default connections => {
|
|||
port: +conn.port,
|
||||
user: conn.user,
|
||||
password: conn.password
|
||||
},
|
||||
poolSize: 3
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue