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