mirror of
https://github.com/Fabio286/antares.git
synced 2025-04-19 04:27:26 +02:00
feat: drop and truncate tables
This commit is contained in:
parent
e6602d1bfa
commit
a4122b4eaa
@ -184,4 +184,24 @@ export default (connections) => {
|
|||||||
return { status: 'error', response: err.toString() };
|
return { status: 'error', response: err.toString() };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('truncate-table', async (event, params) => {
|
||||||
|
try {
|
||||||
|
await connections[params.uid].truncateTable(params);
|
||||||
|
return { status: 'success' };
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return { status: 'error', response: err.toString() };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('drop-table', async (event, params) => {
|
||||||
|
try {
|
||||||
|
await connections[params.uid].dropTable(params);
|
||||||
|
return { status: 'success' };
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return { status: 'error', response: err.toString() };
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@ -448,6 +448,28 @@ export class MySQLClient extends AntaresCore {
|
|||||||
return await this.raw(sql);
|
return await this.raw(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TRUNCATE TABLE
|
||||||
|
*
|
||||||
|
* @returns {Array.<Object>} parameters
|
||||||
|
* @memberof MySQLClient
|
||||||
|
*/
|
||||||
|
async truncateTable (params) {
|
||||||
|
const sql = `TRUNCATE TABLE \`${params.table}\``;
|
||||||
|
return await this.raw(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DROP TABLE
|
||||||
|
*
|
||||||
|
* @returns {Array.<Object>} parameters
|
||||||
|
* @memberof MySQLClient
|
||||||
|
*/
|
||||||
|
async dropTable (params) {
|
||||||
|
const sql = `DROP TABLE \`${params.table}\``;
|
||||||
|
return await this.raw(sql);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {String} SQL string
|
* @returns {String} SQL string
|
||||||
* @memberof MySQLClient
|
* @memberof MySQLClient
|
||||||
|
@ -62,6 +62,13 @@
|
|||||||
@show-create-table-modal="showCreateTableModal"
|
@show-create-table-modal="showCreateTableModal"
|
||||||
@reload="refresh"
|
@reload="refresh"
|
||||||
/>
|
/>
|
||||||
|
<TableContext
|
||||||
|
v-if="isTableContext"
|
||||||
|
:selected-table="selectedTable"
|
||||||
|
:context-event="tableContextEvent"
|
||||||
|
@close-context="closeTableContext"
|
||||||
|
@reload="refresh"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -72,6 +79,7 @@ import Tables from '@/ipc-api/Tables';
|
|||||||
import WorkspaceConnectPanel from '@/components/WorkspaceConnectPanel';
|
import WorkspaceConnectPanel from '@/components/WorkspaceConnectPanel';
|
||||||
import WorkspaceExploreBarDatabase from '@/components/WorkspaceExploreBarDatabase';
|
import WorkspaceExploreBarDatabase from '@/components/WorkspaceExploreBarDatabase';
|
||||||
import DatabaseContext from '@/components/WorkspaceExploreBarDatabaseContext';
|
import DatabaseContext from '@/components/WorkspaceExploreBarDatabaseContext';
|
||||||
|
import TableContext from '@/components/WorkspaceExploreBarTableContext';
|
||||||
import ModalNewDatabase from '@/components/ModalNewDatabase';
|
import ModalNewDatabase from '@/components/ModalNewDatabase';
|
||||||
import ModalNewTable from '@/components/ModalNewTable';
|
import ModalNewTable from '@/components/ModalNewTable';
|
||||||
|
|
||||||
@ -81,6 +89,7 @@ export default {
|
|||||||
WorkspaceConnectPanel,
|
WorkspaceConnectPanel,
|
||||||
WorkspaceExploreBarDatabase,
|
WorkspaceExploreBarDatabase,
|
||||||
DatabaseContext,
|
DatabaseContext,
|
||||||
|
TableContext,
|
||||||
ModalNewDatabase,
|
ModalNewDatabase,
|
||||||
ModalNewTable
|
ModalNewTable
|
||||||
},
|
},
|
||||||
@ -205,7 +214,7 @@ export default {
|
|||||||
this.isTableContext = true;
|
this.isTableContext = true;
|
||||||
},
|
},
|
||||||
closeTableContext () {
|
closeTableContext () {
|
||||||
this.isDatabaseContext = false;
|
this.isTableContext = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="context-element" @click="showEditModal">
|
<div class="context-element" @click="showEditModal">
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-pencil text-light pr-1" /> {{ $t('word.edit') }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-database-edit text-light pr-1" /> {{ $t('word.edit') }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="context-element" @click="showDeleteModal">
|
<div class="context-element" @click="showDeleteModal">
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-delete text-light pr-1" /> {{ $t('word.delete') }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-database-remove text-light pr-1" /> {{ $t('word.delete') }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ConfirmModal
|
<ConfirmModal
|
||||||
@ -69,12 +69,17 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({
|
...mapGetters({
|
||||||
selectedWorkspace: 'workspaces/getSelected'
|
selectedWorkspace: 'workspaces/getSelected',
|
||||||
})
|
getWorkspace: 'workspaces/getWorkspace'
|
||||||
|
}),
|
||||||
|
workspace () {
|
||||||
|
return this.getWorkspace(this.selectedWorkspace);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions({
|
...mapActions({
|
||||||
addNotification: 'notifications/addNotification'
|
addNotification: 'notifications/addNotification',
|
||||||
|
changeBreadcrumbs: 'workspaces/changeBreadcrumbs'
|
||||||
}),
|
}),
|
||||||
showCreateTableModal () {
|
showCreateTableModal () {
|
||||||
this.$emit('show-create-table-modal');
|
this.$emit('show-create-table-modal');
|
||||||
@ -103,6 +108,9 @@ export default {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (status === 'success') {
|
if (status === 'success') {
|
||||||
|
if (this.selectedDatabase === this.workspace.breadcrumbs.schema)
|
||||||
|
this.changeBreadcrumbs({ schema: null });
|
||||||
|
|
||||||
this.closeContext();
|
this.closeContext();
|
||||||
this.$emit('reload');
|
this.$emit('reload');
|
||||||
}
|
}
|
||||||
|
@ -3,43 +3,45 @@
|
|||||||
:context-event="contextEvent"
|
:context-event="contextEvent"
|
||||||
@close-context="closeContext"
|
@close-context="closeContext"
|
||||||
>
|
>
|
||||||
<div class="context-element">
|
<div class="context-element" @click="showEmptyModal">
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-plus text-light pr-1" /> {{ $t('word.add') }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-table-off text-light pr-1" /> {{ $t('message.emptyTable') }}</span>
|
||||||
<i class="mdi mdi-18px mdi-chevron-right text-light pl-1" />
|
|
||||||
<div class="context-submenu">
|
|
||||||
<div class="context-element" @click="showCreateTableModal">
|
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-table text-light pr-1" /> {{ $t('word.table') }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="context-element" @click="showEditModal">
|
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-pencil text-light pr-1" /> {{ $t('word.edit') }}</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="context-element" @click="showDeleteModal">
|
<div class="context-element" @click="showDeleteModal">
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-delete text-light pr-1" /> {{ $t('word.delete') }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-table-remove text-light pr-1" /> {{ $t('word.delete') }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ConfirmModal
|
<ConfirmModal
|
||||||
v-if="isDeleteModal"
|
v-if="isEmptyModal"
|
||||||
@confirm="deleteDatabase"
|
@confirm="emptyTable"
|
||||||
@hide="hideDeleteModal"
|
@hide="hideEmptyModal"
|
||||||
>
|
>
|
||||||
<template slot="header">
|
<template slot="header">
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<i class="mdi mdi-24px mdi-database-remove mr-1" /> {{ $t('message.deleteDatabase') }}
|
<i class="mdi mdi-24px mdi-table-off mr-1" /> {{ $t('message.emptyTable') }}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div slot="body">
|
<div slot="body">
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
{{ $t('message.deleteCorfirm') }} "<b>{{ selectedDatabase }}</b>"?
|
{{ $t('message.emptyCorfirm') }} "<b>{{ selectedTable }}</b>"?
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ConfirmModal>
|
||||||
|
<ConfirmModal
|
||||||
|
v-if="isDeleteModal"
|
||||||
|
@confirm="deleteTable"
|
||||||
|
@hide="hideDeleteModal"
|
||||||
|
>
|
||||||
|
<template slot="header">
|
||||||
|
<div class="d-flex">
|
||||||
|
<i class="mdi mdi-24px mdi-table-remove mr-1" /> {{ $t('message.deleteTable') }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<div slot="body">
|
||||||
|
<div class="mb-2">
|
||||||
|
{{ $t('message.deleteCorfirm') }} "<b>{{ selectedTable }}</b>"?
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ConfirmModal>
|
</ConfirmModal>
|
||||||
<ModalEditDatabase
|
|
||||||
v-if="isEditModal"
|
|
||||||
:selected-database="selectedDatabase"
|
|
||||||
@close="hideEditModal"
|
|
||||||
/>
|
|
||||||
</BaseContextMenu>
|
</BaseContextMenu>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -61,17 +63,23 @@ export default {
|
|||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
isDeleteModal: false
|
isDeleteModal: false,
|
||||||
|
isEmptyModal: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({
|
...mapGetters({
|
||||||
selectedWorkspace: 'workspaces/getSelected'
|
selectedWorkspace: 'workspaces/getSelected',
|
||||||
})
|
getWorkspace: 'workspaces/getWorkspace'
|
||||||
|
}),
|
||||||
|
workspace () {
|
||||||
|
return this.getWorkspace(this.selectedWorkspace);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions({
|
...mapActions({
|
||||||
addNotification: 'notifications/addNotification'
|
addNotification: 'notifications/addNotification',
|
||||||
|
changeBreadcrumbs: 'workspaces/changeBreadcrumbs'
|
||||||
}),
|
}),
|
||||||
showCreateTableModal () {
|
showCreateTableModal () {
|
||||||
this.$emit('show-create-table-modal');
|
this.$emit('show-create-table-modal');
|
||||||
@ -82,24 +90,47 @@ export default {
|
|||||||
hideDeleteModal () {
|
hideDeleteModal () {
|
||||||
this.isDeleteModal = false;
|
this.isDeleteModal = false;
|
||||||
},
|
},
|
||||||
showEditModal () {
|
showEmptyModal () {
|
||||||
this.isEditModal = true;
|
this.isEmptyModal = true;
|
||||||
},
|
},
|
||||||
hideEditModal () {
|
hideEmptyModal () {
|
||||||
this.isEditModal = false;
|
this.isEmptyModal = false;
|
||||||
this.closeContext();
|
|
||||||
},
|
},
|
||||||
closeContext () {
|
closeContext () {
|
||||||
this.$emit('close-context');
|
this.$emit('close-context');
|
||||||
},
|
},
|
||||||
async deleteDatabase () {
|
async emptyTable () {
|
||||||
try {
|
try {
|
||||||
const { status, response } = await Database.deleteDatabase({
|
const { status, response } = await Tables.truncateTable({
|
||||||
uid: this.selectedWorkspace,
|
uid: this.selectedWorkspace,
|
||||||
database: this.selectedDatabase
|
table: this.selectedTable
|
||||||
});
|
});
|
||||||
|
|
||||||
if (status === 'success') {
|
if (status === 'success') {
|
||||||
|
if (this.selectedTable === this.workspace.breadcrumbs.table)
|
||||||
|
this.changeBreadcrumbs({ table: null });
|
||||||
|
|
||||||
|
this.closeContext();
|
||||||
|
this.$emit('reload');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this.addNotification({ status: 'error', message: response });
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
this.addNotification({ status: 'error', message: err.stack });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async deleteTable () {
|
||||||
|
try {
|
||||||
|
const { status, response } = await Tables.dropTable({
|
||||||
|
uid: this.selectedWorkspace,
|
||||||
|
table: this.selectedTable
|
||||||
|
});
|
||||||
|
|
||||||
|
if (status === 'success') {
|
||||||
|
if (this.selectedTable === this.workspace.breadcrumbs.table)
|
||||||
|
this.changeBreadcrumbs({ table: null });
|
||||||
|
|
||||||
this.closeContext();
|
this.closeContext();
|
||||||
this.$emit('reload');
|
this.$emit('reload');
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="context-element">
|
<div v-if="indexes.length" class="context-element">
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-key-arrow-right text-light pr-1" /> {{ $t('message.addToIndex') }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-key-arrow-right text-light pr-1" /> {{ $t('message.addToIndex') }}</span>
|
||||||
<i class="mdi mdi-18px mdi-chevron-right text-light pl-1" />
|
<i class="mdi mdi-18px mdi-chevron-right text-light pl-1" />
|
||||||
<div class="context-submenu">
|
<div class="context-submenu">
|
||||||
|
@ -122,7 +122,12 @@ export default {
|
|||||||
return this.results.length ? this.results[0].keys : [];
|
return this.results.length ? this.results[0].keys : [];
|
||||||
},
|
},
|
||||||
tableInfo () {
|
tableInfo () {
|
||||||
return this.workspace.structure.find(db => db.name === this.schema).tables.find(table => table.name === this.table);
|
try {
|
||||||
|
return this.workspace.structure.find(db => db.name === this.schema).tables.find(table => table.name === this.table);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return { rows: 0 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -109,7 +109,9 @@ module.exports = {
|
|||||||
createNewIndex: 'Create new index',
|
createNewIndex: 'Create new index',
|
||||||
addToIndex: 'Add to index',
|
addToIndex: 'Add to index',
|
||||||
createNewTable: 'Create new table',
|
createNewTable: 'Create new table',
|
||||||
emptyTable: 'Empty table'
|
emptyTable: 'Empty table',
|
||||||
|
deleteTable: 'Delete table',
|
||||||
|
emptyCorfirm: 'Do you confirm to empty'
|
||||||
},
|
},
|
||||||
// Date and Time
|
// Date and Time
|
||||||
short: {
|
short: {
|
||||||
|
@ -41,4 +41,12 @@ export default class {
|
|||||||
static alterTable (params) {
|
static alterTable (params) {
|
||||||
return ipcRenderer.invoke('alter-table', params);
|
return ipcRenderer.invoke('alter-table', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static truncateTable (params) {
|
||||||
|
return ipcRenderer.invoke('truncate-table', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
static dropTable (params) {
|
||||||
|
return ipcRenderer.invoke('drop-table', params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user