mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 22:46:01 +00:00
refgactor, code cleanup
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import _uniq from 'lodash/uniq';
|
import _uniq from 'lodash/uniq';
|
||||||
import { extractShellApiFunctionName, extractShellApiPlugins } from './packageTools';
|
import { extractShellApiFunctionName, extractShellApiPlugins } from './packageTools';
|
||||||
|
|
||||||
export class ScriptWriter {
|
export class ScriptWriterJavaScript {
|
||||||
s = '';
|
s = '';
|
||||||
packageNames: string[] = [];
|
packageNames: string[] = [];
|
||||||
varCount = 0;
|
varCount = 0;
|
||||||
@@ -169,7 +169,7 @@ export class ScriptWriterJson {
|
|||||||
|
|
||||||
export function jsonScriptToJavascript(json) {
|
export function jsonScriptToJavascript(json) {
|
||||||
const { schedule, commands, packageNames } = json;
|
const { schedule, commands, packageNames } = json;
|
||||||
const script = new ScriptWriter();
|
const script = new ScriptWriterJavaScript();
|
||||||
for (const packageName of packageNames) {
|
for (const packageName of packageNames) {
|
||||||
if (!/^dbgate-plugin-.*$/.test(packageName)) {
|
if (!/^dbgate-plugin-.*$/.test(packageName)) {
|
||||||
throw new Error('Unallowed package name:' + packageName);
|
throw new Error('Unallowed package name:' + packageName);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { ScriptWriter, ScriptWriterJson } from 'dbgate-tools';
|
import { ScriptWriterJavaScript, ScriptWriterJson } from 'dbgate-tools';
|
||||||
import getAsArray from '../utility/getAsArray';
|
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';
|
||||||
@@ -207,7 +207,7 @@ export default async function createImpExpScript(extensions, values, forceScript
|
|||||||
const config = getCurrentConfig();
|
const config = getCurrentConfig();
|
||||||
const script =
|
const script =
|
||||||
config.allowShellScripting || forceScript
|
config.allowShellScripting || forceScript
|
||||||
? new ScriptWriter(values.startVariableIndex || 0)
|
? new ScriptWriterJavaScript(values.startVariableIndex || 0)
|
||||||
: new ScriptWriterJson(values.startVariableIndex || 0);
|
: new ScriptWriterJson(values.startVariableIndex || 0);
|
||||||
|
|
||||||
const [sourceConnection, sourceDriver] = await getConnection(
|
const [sourceConnection, sourceDriver] = await getConnection(
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ScriptWriter, ScriptWriterJson } from 'dbgate-tools';
|
import { ScriptWriterJavaScript, ScriptWriterJson } from 'dbgate-tools';
|
||||||
import getElectron from './getElectron';
|
import getElectron from './getElectron';
|
||||||
import {
|
import {
|
||||||
showSnackbar,
|
showSnackbar,
|
||||||
@@ -11,49 +11,47 @@ 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 { getCurrentConfig } from '../stores';
|
import { getCurrentConfig } from '../stores';
|
||||||
import { showModal } from '../modals/modalTools';
|
|
||||||
import RunScriptModal from '../modals/RunScriptModal.svelte';
|
|
||||||
import { QuickExportDefinition } from 'dbgate-types';
|
import { QuickExportDefinition } from 'dbgate-types';
|
||||||
|
|
||||||
export async function importSqlDump(inputFile, connection) {
|
// export async function importSqlDump(inputFile, connection) {
|
||||||
const script = getCurrentConfig().allowShellScripting ? new ScriptWriter() : new ScriptWriterJson();
|
// const script = getCurrentConfig().allowShellScripting ? new ScriptWriterJavaScript() : new ScriptWriterJson();
|
||||||
|
|
||||||
script.importDatabase({
|
// script.importDatabase({
|
||||||
inputFile,
|
// inputFile,
|
||||||
connection,
|
// connection,
|
||||||
});
|
// });
|
||||||
|
|
||||||
showModal(RunScriptModal, { script: script.getScript(), header: 'Importing database' });
|
// showModal(RunScriptModal, { script: script.getScript(), header: 'Importing database' });
|
||||||
|
|
||||||
// await runImportExportScript({
|
// // await runImportExportScript({
|
||||||
// script: script.getScript(),
|
// // script: script.getScript(),
|
||||||
// runningMessage: 'Importing database',
|
// // runningMessage: 'Importing database',
|
||||||
// canceledMessage: 'Database import canceled',
|
// // canceledMessage: 'Database import canceled',
|
||||||
// finishedMessage: 'Database import finished',
|
// // finishedMessage: 'Database import finished',
|
||||||
// });
|
// // });
|
||||||
}
|
// }
|
||||||
|
|
||||||
export async function exportSqlDump(outputFile, connection, databaseName, pureFileName) {
|
// export async function exportSqlDump(outputFile, connection, databaseName, pureFileName) {
|
||||||
const script = getCurrentConfig().allowShellScripting ? new ScriptWriter() : new ScriptWriterJson();
|
// const script = getCurrentConfig().allowShellScripting ? new ScriptWriterJavaScript() : new ScriptWriterJson();
|
||||||
|
|
||||||
script.dumpDatabase({
|
// script.dumpDatabase({
|
||||||
connection,
|
// connection,
|
||||||
databaseName,
|
// databaseName,
|
||||||
outputFile,
|
// outputFile,
|
||||||
});
|
// });
|
||||||
|
|
||||||
showModal(RunScriptModal, {
|
// showModal(RunScriptModal, {
|
||||||
script: script.getScript(),
|
// script: script.getScript(),
|
||||||
header: 'Exporting database',
|
// header: 'Exporting database',
|
||||||
onOpenResult:
|
// onOpenResult:
|
||||||
pureFileName && !getElectron()
|
// pureFileName && !getElectron()
|
||||||
? () => {
|
// ? () => {
|
||||||
downloadFromApi(`uploads/get?file=${pureFileName}`, 'file.sql');
|
// downloadFromApi(`uploads/get?file=${pureFileName}`, 'file.sql');
|
||||||
}
|
// }
|
||||||
: null,
|
// : null,
|
||||||
openResultLabel: 'Download SQL file',
|
// openResultLabel: 'Download SQL file',
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
async function runImportExportScript({ script, runningMessage, canceledMessage, finishedMessage, afterFinish = null }) {
|
async function runImportExportScript({ script, runningMessage, canceledMessage, finishedMessage, afterFinish = null }) {
|
||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
@@ -140,7 +138,7 @@ function generateQuickExportScript(
|
|||||||
dataName: string,
|
dataName: string,
|
||||||
columnMap
|
columnMap
|
||||||
) {
|
) {
|
||||||
const script = getCurrentConfig().allowShellScripting ? new ScriptWriter() : new ScriptWriterJson();
|
const script = getCurrentConfig().allowShellScripting ? new ScriptWriterJavaScript() : new ScriptWriterJson();
|
||||||
|
|
||||||
const sourceVar = script.allocVariable();
|
const sourceVar = script.allocVariable();
|
||||||
script.assign(sourceVar, reader.functionName, reader.props);
|
script.assign(sourceVar, reader.functionName, reader.props);
|
||||||
|
|||||||
Reference in New Issue
Block a user