mirror of
https://github.com/Fabio286/antares.git
synced 2025-03-09 16:00:17 +01:00
feat: contextual option to duplicate tables
This commit is contained in:
parent
61a42d51f5
commit
08d5b1b329
@ -424,6 +424,16 @@ export default (connections) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('duplicate-table', async (event, params) => {
|
||||||
|
try {
|
||||||
|
await connections[params.uid].duplicateTable(params);
|
||||||
|
return { status: 'success' };
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return { status: 'error', response: err.toString() };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ipcMain.handle('truncate-table', async (event, params) => {
|
ipcMain.handle('truncate-table', async (event, params) => {
|
||||||
try {
|
try {
|
||||||
await connections[params.uid].truncateTable(params);
|
await connections[params.uid].truncateTable(params);
|
||||||
|
@ -1243,6 +1243,17 @@ export class MySQLClient extends AntaresCore {
|
|||||||
return await this.raw(sql);
|
return await this.raw(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DUPLICATE TABLE
|
||||||
|
*
|
||||||
|
* @returns {Array.<Object>} parameters
|
||||||
|
* @memberof MySQLClient
|
||||||
|
*/
|
||||||
|
async duplicateTable (params) {
|
||||||
|
const sql = `CREATE TABLE \`${this._schema}\`.\`${params.table}_copy\` LIKE \`${this._schema}\`.\`${params.table}\``;
|
||||||
|
return await this.raw(sql);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TRUNCATE TABLE
|
* TRUNCATE TABLE
|
||||||
*
|
*
|
||||||
|
@ -1126,6 +1126,17 @@ export class PostgreSQLClient extends AntaresCore {
|
|||||||
return await this.raw(sql);
|
return await this.raw(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DUPLICATE TABLE
|
||||||
|
*
|
||||||
|
* @returns {Array.<Object>} parameters
|
||||||
|
* @memberof PostgreSQLClient
|
||||||
|
*/
|
||||||
|
async duplicateTable (params) {
|
||||||
|
const sql = `CREATE TABLE ${this._schema}.${params.table}_copy (LIKE ${this._schema}.${params.table} INCLUDING ALL)`;
|
||||||
|
return await this.raw(sql);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TRUNCATE TABLE
|
* TRUNCATE TABLE
|
||||||
*
|
*
|
||||||
|
@ -187,8 +187,15 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
isSelected () {
|
isSelected () {
|
||||||
if (this.isSelected)
|
if (this.isSelected) {
|
||||||
this.lastSchema = this.schema;
|
this.lastSchema = this.schema;
|
||||||
|
this.editor.resize();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
height () {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.editor.resize();
|
||||||
|
}, 20);
|
||||||
},
|
},
|
||||||
lastSchema () {
|
lastSchema () {
|
||||||
if (this.editor) {
|
if (this.editor) {
|
||||||
|
@ -3,6 +3,13 @@
|
|||||||
:context-event="contextEvent"
|
:context-event="contextEvent"
|
||||||
@close-context="closeContext"
|
@close-context="closeContext"
|
||||||
>
|
>
|
||||||
|
<div
|
||||||
|
v-if="selectedTable.type === 'table'"
|
||||||
|
class="context-element"
|
||||||
|
@click="duplicateTable"
|
||||||
|
>
|
||||||
|
<span class="d-flex"><i class="mdi mdi-18px mdi-table-multiple text-light pr-1" /> {{ $t('message.duplicateTable') }}</span>
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="selectedTable.type === 'table'"
|
v-if="selectedTable.type === 'table'"
|
||||||
class="context-element"
|
class="context-element"
|
||||||
@ -105,6 +112,24 @@ export default {
|
|||||||
closeContext () {
|
closeContext () {
|
||||||
this.$emit('close-context');
|
this.$emit('close-context');
|
||||||
},
|
},
|
||||||
|
async duplicateTable () {
|
||||||
|
try {
|
||||||
|
const { status, response } = await Tables.duplicateTable({
|
||||||
|
uid: this.selectedWorkspace,
|
||||||
|
table: this.selectedTable.name
|
||||||
|
});
|
||||||
|
|
||||||
|
if (status === 'success') {
|
||||||
|
this.closeContext();
|
||||||
|
this.$emit('reload');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this.addNotification({ status: 'error', message: response });
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
this.addNotification({ status: 'error', message: err.stack });
|
||||||
|
}
|
||||||
|
},
|
||||||
async emptyTable () {
|
async emptyTable () {
|
||||||
try {
|
try {
|
||||||
const { status, response } = await Tables.truncateTable({
|
const { status, response } = await Tables.truncateTable({
|
||||||
|
@ -219,7 +219,8 @@ module.exports = {
|
|||||||
markdownSupported: 'Markdown supported',
|
markdownSupported: 'Markdown supported',
|
||||||
plantATree: 'Plant a Tree',
|
plantATree: 'Plant a Tree',
|
||||||
dataTabPageSize: 'DATA tab page size',
|
dataTabPageSize: 'DATA tab page size',
|
||||||
pageNumber: 'Page number'
|
pageNumber: 'Page number',
|
||||||
|
duplicateTable: 'Duplicate table'
|
||||||
},
|
},
|
||||||
faker: {
|
faker: {
|
||||||
address: 'Address',
|
address: 'Address',
|
||||||
|
@ -46,6 +46,10 @@ export default class {
|
|||||||
return ipcRenderer.invoke('alter-table', params);
|
return ipcRenderer.invoke('alter-table', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static duplicateTable (params) {
|
||||||
|
return ipcRenderer.invoke('duplicate-table', params);
|
||||||
|
}
|
||||||
|
|
||||||
static truncateTable (params) {
|
static truncateTable (params) {
|
||||||
return ipcRenderer.invoke('truncate-table', params);
|
return ipcRenderer.invoke('truncate-table', params);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user