mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
feat: views deletion
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
export const TEXT = ['CHAR', 'VARCHAR'];
|
export const TEXT = ['CHAR', 'VARCHAR'];
|
||||||
export const LONG_TEXT = ['TEXT', 'MEDIUMTEXT', 'longtext'];
|
export const LONG_TEXT = ['TEXT', 'MEDIUMTEXT', 'LONGTEXT'];
|
||||||
|
|
||||||
export const NUMBER = ['INT', 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'BIGINT', 'FLOAT', 'DOUBLE', 'DECIMAL', 'BOOL'];
|
export const NUMBER = ['INT', 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'BIGINT', 'FLOAT', 'DOUBLE', 'DECIMAL', 'BOOL'];
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import connection from './connection';
|
import connection from './connection';
|
||||||
import tables from './tables';
|
import tables from './tables';
|
||||||
|
import views from './views';
|
||||||
import updates from './updates';
|
import updates from './updates';
|
||||||
import application from './application';
|
import application from './application';
|
||||||
import database from './database';
|
import database from './database';
|
||||||
@ -9,6 +10,7 @@ const connections = {};
|
|||||||
export default () => {
|
export default () => {
|
||||||
connection(connections);
|
connection(connections);
|
||||||
tables(connections);
|
tables(connections);
|
||||||
|
views(connections);
|
||||||
database(connections);
|
database(connections);
|
||||||
updates();
|
updates();
|
||||||
application();
|
application();
|
||||||
|
23
src/main/ipc-handlers/views.js
Normal file
23
src/main/ipc-handlers/views.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { ipcMain } from 'electron';
|
||||||
|
|
||||||
|
export default (connections) => {
|
||||||
|
ipcMain.handle('get-view-informations', async (event, params) => {
|
||||||
|
try {
|
||||||
|
const result = await connections[params.uid].getViewInformations(params);
|
||||||
|
return { status: 'success', response: result };
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return { status: 'error', response: err.toString() };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('drop-view', async (event, params) => {
|
||||||
|
try {
|
||||||
|
await connections[params.uid].dropView(params);
|
||||||
|
return { status: 'success' };
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return { status: 'error', response: err.toString() };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
@ -262,6 +262,39 @@ export class MySQLClient extends AntaresCore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SHOW CREATE VIEW
|
||||||
|
*
|
||||||
|
* @returns {Array.<Object>} view informations
|
||||||
|
* @memberof MySQLClient
|
||||||
|
*/
|
||||||
|
async getViewInformations ({ schema, view }) {
|
||||||
|
const sql = `SHOW CREATE VIEW \`${schema}\`.\`${view}\``;
|
||||||
|
const results = await this.raw(sql);
|
||||||
|
|
||||||
|
return results.rows.map(row => {
|
||||||
|
return {
|
||||||
|
algorithm: row['Create View'].match(/(?<=CREATE ALGORITHM=).*?(?=\s)/gs)[0],
|
||||||
|
definer: row['Create View'].match(/(?<=DEFINER=).*?(?=\s)/gs)[0],
|
||||||
|
security: row['Create View'].match(/(?<=SQL SECURITY ).*?(?=\s)/gs)[0],
|
||||||
|
updateOption: row['Create View'].match(/(?<=WITH ).*?(?=\s)/gs) ? row['Create View'].match(/(?<=WITH ).*?(?=\s)/gs)[0] : '',
|
||||||
|
sql: row['Create View'].match(/(?<=AS ).*?$/gs)[0],
|
||||||
|
name: row.View
|
||||||
|
};
|
||||||
|
})[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DROP VIEW
|
||||||
|
*
|
||||||
|
* @returns {Array.<Object>} parameters
|
||||||
|
* @memberof MySQLClient
|
||||||
|
*/
|
||||||
|
async dropView (params) {
|
||||||
|
const sql = `DROP VIEW \`${params.view}\``;// TODO: schema
|
||||||
|
return await this.raw(sql);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SHOW COLLATION
|
* SHOW COLLATION
|
||||||
*
|
*
|
||||||
@ -493,7 +526,7 @@ export class MySQLClient extends AntaresCore {
|
|||||||
* @memberof MySQLClient
|
* @memberof MySQLClient
|
||||||
*/
|
*/
|
||||||
async dropTable (params) {
|
async dropTable (params) {
|
||||||
const sql = `DROP TABLE \`${params.table}\``;
|
const sql = `DROP TABLE \`${params.table}\``;// TODO: schema
|
||||||
return await this.raw(sql);
|
return await this.raw(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ export default {
|
|||||||
databaseContextEvent: null,
|
databaseContextEvent: null,
|
||||||
tableContextEvent: null,
|
tableContextEvent: null,
|
||||||
selectedDatabase: '',
|
selectedDatabase: '',
|
||||||
selectedTable: ''
|
selectedTable: null
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
v-for="table of database.tables"
|
v-for="table of database.tables"
|
||||||
:key="table.name"
|
:key="table.name"
|
||||||
class="menu-item"
|
class="menu-item"
|
||||||
:class="{'text-bold': breadcrumbs.schema === database.name && breadcrumbs.table === table.name}"
|
:class="{'text-bold': breadcrumbs.schema === database.name && [breadcrumbs.table, breadcrumbs.view].includes(table.name)}"
|
||||||
@click="setBreadcrumbs({schema: database.name, table: table.name})"
|
@click="setBreadcrumbs({schema: database.name, [table.type]: table.name})"
|
||||||
@contextmenu.prevent="showTableContext($event, table.name)"
|
@contextmenu.prevent="showTableContext($event, table)"
|
||||||
>
|
>
|
||||||
<a class="table-name">
|
<a class="table-name">
|
||||||
<i class="table-icon mdi mdi-18px mr-1" :class="table.type === 'view' ? 'mdi-table-eye' : 'mdi-table'" />
|
<i class="table-icon mdi mdi-18px mr-1" :class="table.type === 'view' ? 'mdi-table-eye' : 'mdi-table'" />
|
||||||
|
@ -3,7 +3,11 @@
|
|||||||
:context-event="contextEvent"
|
:context-event="contextEvent"
|
||||||
@close-context="closeContext"
|
@close-context="closeContext"
|
||||||
>
|
>
|
||||||
<div class="context-element" @click="showEmptyModal">
|
<div
|
||||||
|
v-if="selectedTable.type === 'table'"
|
||||||
|
class="context-element"
|
||||||
|
@click="showEmptyModal"
|
||||||
|
>
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-table-off text-light pr-1" /> {{ $t('message.emptyTable') }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-table-off text-light pr-1" /> {{ $t('message.emptyTable') }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="context-element" @click="showDeleteModal">
|
<div class="context-element" @click="showDeleteModal">
|
||||||
@ -22,7 +26,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<div slot="body">
|
<div slot="body">
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
{{ $t('message.emptyCorfirm') }} "<b>{{ selectedTable }}</b>"?
|
{{ $t('message.emptyCorfirm') }} "<b>{{ selectedTable.name }}</b>"?
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ConfirmModal>
|
</ConfirmModal>
|
||||||
@ -33,12 +37,12 @@
|
|||||||
>
|
>
|
||||||
<template slot="header">
|
<template slot="header">
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<i class="mdi mdi-24px mdi-table-remove mr-1" /> {{ $t('message.deleteTable') }}
|
<i class="mdi mdi-24px mdi-table-remove mr-1" /> {{ selectedTable.type === 'table' ? $t('message.deleteTable') : $t('message.deleteView') }}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div slot="body">
|
<div slot="body">
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
{{ $t('message.deleteCorfirm') }} "<b>{{ selectedTable }}</b>"?
|
{{ $t('message.deleteCorfirm') }} "<b>{{ selectedTable.name }}</b>"?
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ConfirmModal>
|
</ConfirmModal>
|
||||||
@ -50,6 +54,7 @@ import { mapGetters, mapActions } from 'vuex';
|
|||||||
import BaseContextMenu from '@/components/BaseContextMenu';
|
import BaseContextMenu from '@/components/BaseContextMenu';
|
||||||
import ConfirmModal from '@/components/BaseConfirmModal';
|
import ConfirmModal from '@/components/BaseConfirmModal';
|
||||||
import Tables from '@/ipc-api/Tables';
|
import Tables from '@/ipc-api/Tables';
|
||||||
|
import Views from '@/ipc-api/Views';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'WorkspaceExploreBarTableContext',
|
name: 'WorkspaceExploreBarTableContext',
|
||||||
@ -59,7 +64,7 @@ export default {
|
|||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
contextEvent: MouseEvent,
|
contextEvent: MouseEvent,
|
||||||
selectedTable: String
|
selectedTable: Object
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
@ -103,11 +108,11 @@ export default {
|
|||||||
try {
|
try {
|
||||||
const { status, response } = await Tables.truncateTable({
|
const { status, response } = await Tables.truncateTable({
|
||||||
uid: this.selectedWorkspace,
|
uid: this.selectedWorkspace,
|
||||||
table: this.selectedTable
|
table: this.selectedTable.name
|
||||||
});
|
});
|
||||||
|
|
||||||
if (status === 'success') {
|
if (status === 'success') {
|
||||||
if (this.selectedTable === this.workspace.breadcrumbs.table)
|
if (this.selectedTable.name === this.workspace.breadcrumbs.table)
|
||||||
this.changeBreadcrumbs({ table: null });
|
this.changeBreadcrumbs({ table: null });
|
||||||
|
|
||||||
this.closeContext();
|
this.closeContext();
|
||||||
@ -122,13 +127,25 @@ export default {
|
|||||||
},
|
},
|
||||||
async deleteTable () {
|
async deleteTable () {
|
||||||
try {
|
try {
|
||||||
const { status, response } = await Tables.dropTable({
|
let res;
|
||||||
uid: this.selectedWorkspace,
|
|
||||||
table: this.selectedTable
|
if (this.selectedTable.type === 'table') {
|
||||||
});
|
res = await Tables.dropTable({
|
||||||
|
uid: this.selectedWorkspace,
|
||||||
|
table: this.selectedTable.name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (this.selectedTable.type === 'view') {
|
||||||
|
res = await Views.dropView({
|
||||||
|
uid: this.selectedWorkspace,
|
||||||
|
view: this.selectedTable.name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const { status, response } = res;
|
||||||
|
|
||||||
if (status === 'success') {
|
if (status === 'success') {
|
||||||
if (this.selectedTable === this.workspace.breadcrumbs.table)
|
if (this.selectedTable.name === this.workspace.breadcrumbs.table)
|
||||||
this.changeBreadcrumbs({ table: null });
|
this.changeBreadcrumbs({ table: null });
|
||||||
|
|
||||||
this.closeContext();
|
this.closeContext();
|
||||||
|
@ -171,7 +171,7 @@ export default {
|
|||||||
const params = {
|
const params = {
|
||||||
uid: this.connection.uid,
|
uid: this.connection.uid,
|
||||||
schema: this.schema,
|
schema: this.schema,
|
||||||
table: this.workspace.breadcrumbs.table,
|
table: this.workspace.breadcrumbs.table || this.workspace.breadcrumbs.view,
|
||||||
sortParams
|
sortParams
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,7 +68,12 @@ module.exports = {
|
|||||||
autoCompletion: 'Auto Completion',
|
autoCompletion: 'Auto Completion',
|
||||||
application: 'Application',
|
application: 'Application',
|
||||||
editor: 'Editor',
|
editor: 'Editor',
|
||||||
view: 'View'
|
view: 'View',
|
||||||
|
definer: 'Definer',
|
||||||
|
algorithm: 'Algorithm',
|
||||||
|
trigger: 'Trigger',
|
||||||
|
storedRoutine: 'Stored routine',
|
||||||
|
scheduler: 'Scheduler'
|
||||||
},
|
},
|
||||||
message: {
|
message: {
|
||||||
appWelcome: 'Welcome to Antares SQL Client!',
|
appWelcome: 'Welcome to Antares SQL Client!',
|
||||||
@ -133,7 +138,11 @@ module.exports = {
|
|||||||
onDelete: 'On delete',
|
onDelete: 'On delete',
|
||||||
applicationTheme: 'Application Theme',
|
applicationTheme: 'Application Theme',
|
||||||
editorTheme: 'Editor Theme',
|
editorTheme: 'Editor Theme',
|
||||||
wrapLongLines: 'Wrap long lines'
|
wrapLongLines: 'Wrap long lines',
|
||||||
|
selectStatement: 'Select statement',
|
||||||
|
sqlSecurity: 'SQL security',
|
||||||
|
updateOption: 'Update option',
|
||||||
|
deleteView: 'Delete view'
|
||||||
},
|
},
|
||||||
// Date and Time
|
// Date and Time
|
||||||
short: {
|
short: {
|
||||||
|
12
src/renderer/ipc-api/Views.js
Normal file
12
src/renderer/ipc-api/Views.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
'use strict';
|
||||||
|
import { ipcRenderer } from 'electron';
|
||||||
|
|
||||||
|
export default class {
|
||||||
|
static getViewInformations (params) {
|
||||||
|
return ipcRenderer.invoke('get-view-informations', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
static dropView (params) {
|
||||||
|
return ipcRenderer.invoke('drop-view', params);
|
||||||
|
}
|
||||||
|
}
|
@ -322,7 +322,8 @@ export default {
|
|||||||
table: null,
|
table: null,
|
||||||
trigger: null,
|
trigger: null,
|
||||||
procedure: null,
|
procedure: null,
|
||||||
scheduler: null
|
scheduler: null,
|
||||||
|
view: null
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasLastChildren = Object.keys(lastBreadcrumbs).filter(b => b !== 'schema').some(b => lastBreadcrumbs[b]);
|
const hasLastChildren = Object.keys(lastBreadcrumbs).filter(b => b !== 'schema').some(b => lastBreadcrumbs[b]);
|
||||||
|
Reference in New Issue
Block a user