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