1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-06-05 21:59:22 +02:00

feat: export table content as SQL INSERT

This commit is contained in:
2022-07-25 12:19:58 +02:00
parent d4b6d2e9d1
commit f3b5de38c4
12 changed files with 218 additions and 139 deletions

View File

@ -136,7 +136,7 @@
<script setup lang="ts">
import { Component, computed, onBeforeUnmount, onMounted, onUpdated, Prop, Ref, ref } from 'vue';
import { ConnectionParams } from 'common/interfaces/antares';
import { arrayToFile } from '../libs/arrayToFile';
import { exportRows } from '../libs/exportRows';
import { useNotificationsStore } from '@/stores/notifications';
import { useFocusTrap } from '@/composables/useFocusTrap';
import Schema from '@/ipc-api/Schema';
@ -312,7 +312,7 @@ const closeModal = () => emit('close');
const downloadTable = (format: 'csv' | 'json') => {
if (!sortedResults.value) return;
arrayToFile({
exportRows({
type: format,
content: sortedResults.value,
filename: 'processes'

View File

@ -112,6 +112,9 @@
<li class="menu-item">
<a class="c-hand" @click="downloadTable('csv')">CSV</a>
</li>
<li class="menu-item">
<a class="c-hand" @click="downloadTable('sql')">SQL INSERT</a>
</li>
</ul>
</div>
<div class="input-group pr-2" :title="t('message.commitMode')">
@ -446,7 +449,7 @@ const clear = () => {
clearTabData();
};
const downloadTable = (format: 'csv' | 'json') => {
const downloadTable = (format: 'csv' | 'json' | 'sql') => {
queryTable.value.downloadTable(format, `${props.tab.type}-${props.tab.index}`);
};

View File

@ -121,7 +121,7 @@ import { uidGen } from 'common/libs/uidGen';
import { useSettingsStore } from '@/stores/settings';
import { useWorkspacesStore } from '@/stores/workspaces';
import { useConsoleStore } from '@/stores/console';
import { arrayToFile } from '../libs/arrayToFile';
import { exportRows } from '../libs/exportRows';
import { TEXT, LONG_TEXT, BLOB } from 'common/fieldTypes';
import BaseVirtualScroll from '@/components/BaseVirtualScroll.vue';
import WorkspaceTabQueryTableRow from '@/components/WorkspaceTabQueryTableRow.vue';
@ -177,6 +177,7 @@ const selectedField = ref(null);
const isEditingRow = ref(false);
const workspaceSchema = computed(() => getWorkspace(props.connUid).breadcrumbs.schema);
const workspaceClient = computed(() => getWorkspace(props.connUid).client);
const primaryField = computed(() => {
const primaryFields = fields.value.filter(field => field.key === 'pri');
@ -534,7 +535,7 @@ const selectResultset = (index: number) => {
resultsetIndex.value = index;
};
const downloadTable = (format: 'csv' | 'json', filename: string) => {
const downloadTable = (format: 'csv' | 'json' | 'sql', table: string) => {
if (!sortedResults.value) return;
const rows = JSON.parse(JSON.stringify(sortedResults.value)).map((row: any) => {
@ -542,10 +543,14 @@ const downloadTable = (format: 'csv' | 'json', filename: string) => {
return row;
});
arrayToFile({
exportRows({
type: format,
content: rows,
filename
fields: fieldsObj.value as {
[key: string]: {type: string; datePrecision: number};
},
client: workspaceClient.value,
table
});
};

View File

@ -105,6 +105,9 @@
<li class="menu-item">
<a class="c-hand" @click="downloadTable('csv')">CSV</a>
</li>
<li class="menu-item">
<a class="c-hand" @click="downloadTable('sql')">SQL INSERT</a>
</li>
</ul>
</div>
</div>
@ -375,7 +378,7 @@ const setRefreshInterval = () => {
}
};
const downloadTable = (format: 'csv' | 'json') => {
const downloadTable = (format: 'csv' | 'json' | 'sql') => {
queryTable.value.downloadTable(format, props.table);
};

View File

@ -97,7 +97,9 @@ const removeRow = (i: number) => {
};
const doFilter = () => {
const clausoles = rows.value.filter(el => el.active).map(el => createClausole(el));
const clausoles = rows.value
.filter(el => el.active)
.map(el => createClausole(el));
emit('filter', clausoles);
};