mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 22:36:01 +00:00
quick export - current archive
This commit is contained in:
3
packages/types/extensions.d.ts
vendored
3
packages/types/extensions.d.ts
vendored
@@ -37,8 +37,9 @@ export interface PluginDefinition {
|
||||
|
||||
export interface QuickExportDefinition {
|
||||
label: string;
|
||||
createWriter: (fileName: string) => { functionName: string; props: any };
|
||||
createWriter: (fileName: string, dataName?: string) => { functionName: string; props: any };
|
||||
extension: string;
|
||||
noFilenameDependency?: boolean;
|
||||
}
|
||||
|
||||
export interface ExtensionsDirectory {
|
||||
|
||||
@@ -251,3 +251,9 @@ export function subscribeApiDependendStores() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let currentArchiveValue = null;
|
||||
currentArchive.subscribe(value => {
|
||||
currentArchiveValue = value;
|
||||
});
|
||||
export const getCurrentArchive = () => currentArchiveValue;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { QuickExportDefinition } from 'dbgate-types';
|
||||
import { getExtensions } from '../stores';
|
||||
import { currentArchive, getCurrentArchive, getExtensions } from '../stores';
|
||||
|
||||
export function createQuickExportMenuItems(handler: (fmt: QuickExportDefinition) => Function, advancedExportMenuItem) {
|
||||
const extensions = getExtensions();
|
||||
@@ -9,6 +9,22 @@ export function createQuickExportMenuItems(handler: (fmt: QuickExportDefinition)
|
||||
onClick: handler(fmt),
|
||||
})),
|
||||
{ divider: true },
|
||||
{
|
||||
text: 'Current archive',
|
||||
onClick: handler({
|
||||
extension: 'jsonl',
|
||||
label: 'Current archive',
|
||||
noFilenameDependency: true,
|
||||
createWriter: (fileName, dataName) => ({
|
||||
functionName: 'archiveWriter',
|
||||
props: {
|
||||
fileName: dataName,
|
||||
folderName: getCurrentArchive(),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
},
|
||||
{ divider: true },
|
||||
{
|
||||
text: 'More...',
|
||||
...advancedExportMenuItem,
|
||||
|
||||
@@ -7,6 +7,7 @@ import { normalizeExportColumnMap } from '../impexp/createImpExpScript';
|
||||
import { getCurrentConfig } from '../stores';
|
||||
import { showModal } from '../modals/modalTools';
|
||||
import RunScriptModal from '../modals/RunScriptModal.svelte';
|
||||
import { QuickExportDefinition } from 'dbgate-types';
|
||||
|
||||
export async function importSqlDump(inputFile, connection) {
|
||||
const script = getCurrentConfig().allowShellScripting ? new ScriptWriter() : new ScriptWriterJson();
|
||||
@@ -117,35 +118,53 @@ export async function saveExportedFile(filters, defaultPath, extension, dataName
|
||||
});
|
||||
}
|
||||
|
||||
export async function exportQuickExportFile(dataName, reader, format, columnMap = null) {
|
||||
await saveExportedFile(
|
||||
[{ name: format.label, extensions: [format.extension] }],
|
||||
`${dataName}.${format.extension}`,
|
||||
format.extension,
|
||||
dataName,
|
||||
filePath => {
|
||||
const script = getCurrentConfig().allowShellScripting ? new ScriptWriter() : new ScriptWriterJson();
|
||||
function generateQuickExportScript(
|
||||
reader,
|
||||
format: QuickExportDefinition,
|
||||
filePath: string,
|
||||
dataName: string,
|
||||
columnMap
|
||||
) {
|
||||
const script = getCurrentConfig().allowShellScripting ? new ScriptWriter() : new ScriptWriterJson();
|
||||
|
||||
const sourceVar = script.allocVariable();
|
||||
script.assign(sourceVar, reader.functionName, reader.props);
|
||||
const sourceVar = script.allocVariable();
|
||||
script.assign(sourceVar, reader.functionName, reader.props);
|
||||
|
||||
const targetVar = script.allocVariable();
|
||||
const writer = format.createWriter(filePath, dataName);
|
||||
script.assign(targetVar, writer.functionName, writer.props);
|
||||
const targetVar = script.allocVariable();
|
||||
const writer = format.createWriter(filePath, dataName);
|
||||
script.assign(targetVar, writer.functionName, writer.props);
|
||||
|
||||
const colmap = normalizeExportColumnMap(columnMap);
|
||||
let colmapVar = null;
|
||||
if (colmap) {
|
||||
colmapVar = script.allocVariable();
|
||||
script.assignValue(colmapVar, colmap);
|
||||
}
|
||||
const colmap = normalizeExportColumnMap(columnMap);
|
||||
let colmapVar = null;
|
||||
if (colmap) {
|
||||
colmapVar = script.allocVariable();
|
||||
script.assignValue(colmapVar, colmap);
|
||||
}
|
||||
|
||||
script.copyStream(sourceVar, targetVar, colmapVar);
|
||||
script.endLine();
|
||||
script.copyStream(sourceVar, targetVar, colmapVar);
|
||||
script.endLine();
|
||||
|
||||
return script.getScript();
|
||||
}
|
||||
);
|
||||
return script.getScript();
|
||||
}
|
||||
|
||||
export async function exportQuickExportFile(dataName, reader, format: QuickExportDefinition, columnMap = null) {
|
||||
if (format.noFilenameDependency) {
|
||||
const script = generateQuickExportScript(reader, format, null, dataName, columnMap);
|
||||
runImportExportScript({
|
||||
script,
|
||||
runningMessage: `Exporting ${dataName}`,
|
||||
canceledMessage: `Export ${dataName} canceled`,
|
||||
finishedMessage: `Export ${dataName} finished`,
|
||||
});
|
||||
} else {
|
||||
await saveExportedFile(
|
||||
[{ name: format.label, extensions: [format.extension] }],
|
||||
`${dataName}.${format.extension}`,
|
||||
format.extension,
|
||||
dataName,
|
||||
filePath => generateQuickExportScript(reader, format, filePath, dataName, columnMap)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// export async function exportSqlDump(connection, databaseName) {
|
||||
|
||||
Reference in New Issue
Block a user