mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 18:56:00 +00:00
mysql dumper POC
This commit is contained in:
@@ -6,46 +6,28 @@ import { apiCall, apiOff, apiOn } from './api';
|
||||
import { normalizeExportColumnMap } from '../impexp/createImpExpScript';
|
||||
import { getCurrentConfig } from '../stores';
|
||||
|
||||
export async function exportQuickExportFile(dataName, reader, format, columnMap = null) {
|
||||
export async function saveExportedFile(filters, defaultPath, extension, dataName, getScript: (filaPath: string) => {}) {
|
||||
const electron = getElectron();
|
||||
|
||||
let filePath;
|
||||
let pureFileName;
|
||||
if (electron) {
|
||||
const filters = [{ name: format.label, extensions: [format.extension] }];
|
||||
filePath = await electron.showSaveDialog({
|
||||
filters,
|
||||
defaultPath: `${dataName}.${format.extension}`,
|
||||
defaultPath,
|
||||
properties: ['showOverwriteConfirmation'],
|
||||
});
|
||||
} else {
|
||||
const resp = await apiCall('files/generate-uploads-file', { extension: format.extension });
|
||||
const resp = await apiCall('files/generate-uploads-file', { extension });
|
||||
filePath = resp.filePath;
|
||||
pureFileName = resp.fileName;
|
||||
}
|
||||
|
||||
if (!filePath) return;
|
||||
|
||||
const script = getCurrentConfig().allowShellScripting ? new ScriptWriter() : new ScriptWriterJson();
|
||||
const script = getScript(filePath);
|
||||
|
||||
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 colmap = normalizeExportColumnMap(columnMap);
|
||||
let colmapVar = null;
|
||||
if (colmap) {
|
||||
colmapVar = script.allocVariable();
|
||||
script.assignValue(colmapVar, colmap);
|
||||
}
|
||||
|
||||
script.copyStream(sourceVar, targetVar, colmapVar);
|
||||
script.endLine();
|
||||
|
||||
const resp = await apiCall('runners/start', { script: script.getScript() });
|
||||
const resp = await apiCall('runners/start', { script });
|
||||
const runid = resp.runid;
|
||||
let isCanceled = false;
|
||||
|
||||
@@ -77,6 +59,57 @@ export async function exportQuickExportFile(dataName, reader, format, columnMap
|
||||
apiOn(`runner-done-${runid}`, handleRunnerDone);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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 colmap = normalizeExportColumnMap(columnMap);
|
||||
let colmapVar = null;
|
||||
if (colmap) {
|
||||
colmapVar = script.allocVariable();
|
||||
script.assignValue(colmapVar, colmap);
|
||||
}
|
||||
|
||||
script.copyStream(sourceVar, targetVar, colmapVar);
|
||||
script.endLine();
|
||||
|
||||
return script.getScript();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function exportSqlDump(connection, databaseName) {
|
||||
await saveExportedFile(
|
||||
[{ name: 'SQL files', extensions: ['sql'] }],
|
||||
`${databaseName}.sql`,
|
||||
'sql',
|
||||
`${databaseName}-dump`,
|
||||
filePath => {
|
||||
const script = getCurrentConfig().allowShellScripting ? new ScriptWriter() : new ScriptWriterJson();
|
||||
|
||||
script.dumpDatabase({
|
||||
connection,
|
||||
databaseName,
|
||||
outputFile: filePath,
|
||||
});
|
||||
|
||||
return script.getScript();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function saveFileToDisk(
|
||||
filePathFunc,
|
||||
options: any = { formatLabel: 'HTML page', formatExtension: 'html' }
|
||||
|
||||
Reference in New Issue
Block a user