mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 16:35:59 +00:00
quick export respect shown columns
This commit is contained in:
@@ -209,7 +209,8 @@
|
||||
sql: getExportQuery(),
|
||||
},
|
||||
},
|
||||
fmt
|
||||
fmt,
|
||||
display.getExportColumnMap()
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -116,7 +116,8 @@
|
||||
fileName: archiveMatch[2],
|
||||
},
|
||||
},
|
||||
fmt
|
||||
fmt,
|
||||
display.getExportColumnMap()
|
||||
);
|
||||
} else {
|
||||
exportQuickExportFile(
|
||||
@@ -127,7 +128,8 @@
|
||||
jslid,
|
||||
},
|
||||
},
|
||||
fmt
|
||||
fmt,
|
||||
display.getExportColumnMap()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -194,7 +194,8 @@
|
||||
sql: display.getExportQuery(),
|
||||
},
|
||||
},
|
||||
fmt
|
||||
fmt,
|
||||
display.getExportColumnMap()
|
||||
);
|
||||
};
|
||||
registerQuickExportHandler(quickExportHandler);
|
||||
|
||||
@@ -33,7 +33,7 @@ export default class ScriptWriter {
|
||||
this.packageNames.push(packageName);
|
||||
}
|
||||
|
||||
copyStream(sourceVar, targetVar, colmapVar) {
|
||||
copyStream(sourceVar, targetVar, colmapVar = null) {
|
||||
if (colmapVar) {
|
||||
this.put(`await dbgateApi.copyStream(${sourceVar}, ${targetVar}, {columns: ${colmapVar}});`);
|
||||
} else {
|
||||
|
||||
@@ -160,6 +160,21 @@ function getTargetExpr(extensions, sourceName, values, targetConnection, targetD
|
||||
throw new Error(`Unknown target storage type: ${targetStorageType}`);
|
||||
}
|
||||
|
||||
export function normalizeExportColumnMap(colmap) {
|
||||
if (!colmap) {
|
||||
return null;
|
||||
}
|
||||
if (!colmap.find(x => !x.ignore)) {
|
||||
// all values are ignored, ignore column map
|
||||
return null;
|
||||
}
|
||||
colmap = colmap.filter(x => !x.skip);
|
||||
if (colmap.length > 0) {
|
||||
return colmap.map(x => _.omit(x, ['ignore']));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export default async function createImpExpScript(extensions, values, addEditorInfo = true) {
|
||||
const script = new ScriptWriter(values.startVariableIndex || 0);
|
||||
|
||||
@@ -186,16 +201,11 @@ export default async function createImpExpScript(extensions, values, addEditorIn
|
||||
// @ts-ignore
|
||||
script.assign(targetVar, ...getTargetExpr(extensions, sourceName, values, targetConnection, targetDriver));
|
||||
|
||||
let colmap = values[`columns_${sourceName}`] || [];
|
||||
if (!colmap.find(x => !x.ignore)) {
|
||||
// all values are ignored, ignore column map
|
||||
colmap = [];
|
||||
}
|
||||
colmap = colmap.filter(x => !x.skip);
|
||||
const colmap = normalizeExportColumnMap(values[`columns_${sourceName}`] );
|
||||
|
||||
let colmapVar = null;
|
||||
if (colmap.length > 0) {
|
||||
if (colmap) {
|
||||
colmapVar = script.allocVariable();
|
||||
colmap = colmap.map(x => _.omit(x, ['ignore']));
|
||||
script.assignValue(colmapVar, colmap);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ import getElectron from './getElectron';
|
||||
import { showSnackbar, showSnackbarInfo, showSnackbarError, closeSnackbar } from '../utility/snackbar';
|
||||
import resolveApi from './resolveApi';
|
||||
import { apiCall, apiOff, apiOn } from './api';
|
||||
import { normalizeExportColumnMap } from '../impexp/createImpExpScript';
|
||||
|
||||
export async function exportQuickExportFile(dataName, reader, format) {
|
||||
export async function exportQuickExportFile(dataName, reader, format, columnMap = null) {
|
||||
const electron = getElectron();
|
||||
|
||||
let filePath;
|
||||
@@ -31,7 +32,14 @@ export async function exportQuickExportFile(dataName, reader, format) {
|
||||
const writer = format.createWriter(filePath, dataName);
|
||||
script.assign(targetVar, writer.functionName, writer.props);
|
||||
|
||||
script.copyStream(sourceVar, targetVar);
|
||||
const colmap = normalizeExportColumnMap(columnMap);
|
||||
let colmapVar = null;
|
||||
if (colmap) {
|
||||
colmapVar = script.allocVariable();
|
||||
script.assignValue(colmapVar, colmap);
|
||||
}
|
||||
|
||||
script.copyStream(sourceVar, targetVar, colmapVar);
|
||||
script.put();
|
||||
|
||||
const resp = await apiCall('runners/start', { script: script.getScript() });
|
||||
|
||||
Reference in New Issue
Block a user