mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 14:46:01 +00:00
quick export - works for DuckDB
This commit is contained in:
@@ -893,9 +893,10 @@
|
||||
{
|
||||
functionName: menu.functionName,
|
||||
props: {
|
||||
connection: extractShellConnection(coninfo, data.database),
|
||||
...extractShellConnectionHostable(coninfo, data.database),
|
||||
..._.pick(data, ['pureName', 'schemaName']),
|
||||
},
|
||||
hostConnection: extractShellHostConnection(coninfo, data.database),
|
||||
},
|
||||
fmt
|
||||
);
|
||||
@@ -1031,7 +1032,7 @@
|
||||
import { alterDatabaseDialog, renameDatabaseObjectDialog } from '../utility/alterDatabaseTools';
|
||||
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
||||
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||
import { extractShellConnection } from '../impexp/createImpExpScript';
|
||||
import { extractShellConnectionHostable, extractShellHostConnection } from '../impexp/createImpExpScript';
|
||||
import { format as dateFormat } from 'date-fns';
|
||||
import { getDefaultFileFormat } from '../plugins/fileformats';
|
||||
import hasPermission from '../utility/hasPermission';
|
||||
|
||||
@@ -121,7 +121,7 @@
|
||||
import _ from 'lodash';
|
||||
import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.svelte';
|
||||
import registerCommand from '../commands/registerCommand';
|
||||
import { extractShellConnection } from '../impexp/createImpExpScript';
|
||||
import { extractShellConnection, extractShellConnectionHostable, extractShellHostConnection } from '../impexp/createImpExpScript';
|
||||
import { apiCall } from '../utility/api';
|
||||
|
||||
import { registerMenu } from '../utility/contextMenu';
|
||||
@@ -235,10 +235,11 @@
|
||||
{
|
||||
functionName: 'queryReader',
|
||||
props: {
|
||||
connection: extractShellConnection(coninfo, database),
|
||||
...extractShellConnectionHostable(coninfo, database),
|
||||
queryType: coninfo.isReadOnly ? 'json' : 'native',
|
||||
query: coninfo.isReadOnly ? getExportQueryJson() : getExportQuery(),
|
||||
},
|
||||
hostConnection: extractShellHostConnection(coninfo, database),
|
||||
},
|
||||
fmt,
|
||||
display.getExportColumnMap()
|
||||
|
||||
@@ -68,7 +68,11 @@
|
||||
import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.svelte';
|
||||
|
||||
import registerCommand from '../commands/registerCommand';
|
||||
import { extractShellConnection } from '../impexp/createImpExpScript';
|
||||
import {
|
||||
extractShellConnection,
|
||||
extractShellConnectionHostable,
|
||||
extractShellHostConnection,
|
||||
} from '../impexp/createImpExpScript';
|
||||
import { apiCall } from '../utility/api';
|
||||
|
||||
import { registerMenu } from '../utility/contextMenu';
|
||||
@@ -215,10 +219,11 @@
|
||||
{
|
||||
functionName: 'queryReader',
|
||||
props: {
|
||||
connection: extractShellConnection(coninfo, database),
|
||||
...extractShellConnectionHostable(coninfo, database),
|
||||
queryType: coninfo.isReadOnly ? 'json' : 'native',
|
||||
query: coninfo.isReadOnly ? display.getExportQueryJson() : display.getExportQuery(),
|
||||
},
|
||||
hostConnection: extractShellHostConnection(coninfo, database),
|
||||
},
|
||||
fmt,
|
||||
display.getExportColumnMap()
|
||||
|
||||
@@ -5,7 +5,7 @@ import getAsArray from '../utility/getAsArray';
|
||||
import { getConnectionInfo } from '../utility/metadataLoaders';
|
||||
import { findEngineDriver, findObjectLike } from 'dbgate-tools';
|
||||
import { findFileFormat } from '../plugins/fileformats';
|
||||
import { getCurrentConfig } from '../stores';
|
||||
import { getCurrentConfig, getExtensions } from '../stores';
|
||||
|
||||
export function getTargetName(extensions, source, values) {
|
||||
const key = `targetName_${source}`;
|
||||
@@ -53,6 +53,32 @@ export function extractShellConnection(connection, database) {
|
||||
};
|
||||
}
|
||||
|
||||
export function extractShellConnectionHostable(connection, database) {
|
||||
const driver = findEngineDriver(connection, getExtensions());
|
||||
if (driver?.singleConnectionOnly) {
|
||||
return {
|
||||
systemConnection: { $hostConnection: true },
|
||||
connection: driver.engine,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
connection: extractShellConnection(connection, database),
|
||||
};
|
||||
}
|
||||
|
||||
export function extractShellHostConnection(connection, database) {
|
||||
const driver = findEngineDriver(connection, getExtensions());
|
||||
if (driver?.singleConnectionOnly) {
|
||||
return {
|
||||
conid: connection._id,
|
||||
database,
|
||||
};
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function getConnection(extensions, storageType, conid, database) {
|
||||
if (storageType == 'database' || storageType == 'query') {
|
||||
const conn = await getConnectionInfo({ conid });
|
||||
|
||||
@@ -11,6 +11,7 @@ import resolveApi, { resolveApiHeaders } from './resolveApi';
|
||||
import { apiCall, apiOff, apiOn } from './api';
|
||||
import { normalizeExportColumnMap } from '../impexp/createImpExpScript';
|
||||
import { QuickExportDefinition } from 'dbgate-types';
|
||||
import uuidv1 from 'uuid/v1';
|
||||
|
||||
// export async function importSqlDump(inputFile, connection) {
|
||||
// const script = getCurrentConfig().allowShellScripting ? new ScriptWriterJavaScript() : new ScriptWriterJson();
|
||||
@@ -52,13 +53,32 @@ import { QuickExportDefinition } from 'dbgate-types';
|
||||
// });
|
||||
// }
|
||||
|
||||
async function runImportExportScript({ script, runningMessage, canceledMessage, finishedMessage, afterFinish = null }) {
|
||||
async function runImportExportScript({
|
||||
script,
|
||||
runningMessage,
|
||||
canceledMessage,
|
||||
finishedMessage,
|
||||
afterFinish = null,
|
||||
hostConnection = null,
|
||||
}) {
|
||||
const electron = getElectron();
|
||||
|
||||
const resp = await apiCall('runners/start', { script });
|
||||
const runid = resp.runid;
|
||||
let runid;
|
||||
let isCanceled = false;
|
||||
|
||||
if (hostConnection) {
|
||||
runid = uuidv1();
|
||||
await apiCall('database-connections/eval-json-script', {
|
||||
runid,
|
||||
conid: hostConnection.conid,
|
||||
database: hostConnection.database,
|
||||
script,
|
||||
});
|
||||
} else {
|
||||
const resp = await apiCall('runners/start', { script });
|
||||
runid = resp.runid;
|
||||
}
|
||||
|
||||
const snackId = showSnackbar({
|
||||
message: runningMessage,
|
||||
icon: 'icon loading',
|
||||
@@ -96,7 +116,14 @@ async function runImportExportScript({ script, runningMessage, canceledMessage,
|
||||
apiOn(`runner-progress-${runid}`, handleRunnerProgress);
|
||||
}
|
||||
|
||||
export async function saveExportedFile(filters, defaultPath, extension, dataName, getScript: (filaPath: string) => {}) {
|
||||
export async function saveExportedFile(
|
||||
filters,
|
||||
defaultPath,
|
||||
extension,
|
||||
dataName,
|
||||
getScript: (filaPath: string) => {},
|
||||
hostConnection = null
|
||||
) {
|
||||
const electron = getElectron();
|
||||
|
||||
let filePath;
|
||||
@@ -127,6 +154,7 @@ export async function saveExportedFile(filters, defaultPath, extension, dataName
|
||||
downloadFromApi(`uploads/get?file=${pureFileName}`, defaultPath);
|
||||
}
|
||||
},
|
||||
hostConnection,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -167,6 +195,7 @@ export async function exportQuickExportFile(dataName, reader, format: QuickExpor
|
||||
runningMessage: `Exporting ${dataName}`,
|
||||
canceledMessage: `Export ${dataName} canceled`,
|
||||
finishedMessage: `Export ${dataName} finished`,
|
||||
hostConnection: reader.hostConnection,
|
||||
});
|
||||
} else {
|
||||
await saveExportedFile(
|
||||
@@ -174,7 +203,8 @@ export async function exportQuickExportFile(dataName, reader, format: QuickExpor
|
||||
`${dataName}.${format.extension}`,
|
||||
format.extension,
|
||||
dataName,
|
||||
filePath => generateQuickExportScript(reader, format, filePath, dataName, columnMap)
|
||||
filePath => generateQuickExportScript(reader, format, filePath, dataName, columnMap),
|
||||
reader.hostConnection
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user