mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 08:43:57 +00:00
generate script fixes
This commit is contained in:
@@ -5,3 +5,4 @@ export * from "./ViewGridDisplay";
|
|||||||
export * from "./JslGridDisplay";
|
export * from "./JslGridDisplay";
|
||||||
export * from "./ChangeSet";
|
export * from "./ChangeSet";
|
||||||
export * from "./filterName";
|
export * from "./filterName";
|
||||||
|
export * from "./nameTools";
|
||||||
|
|||||||
25
packages/datalib/src/nameTools.ts
Normal file
25
packages/datalib/src/nameTools.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
export function fullNameFromString(name) {
|
||||||
|
const m = name.match(/\[([^\]]+)\]\.\[([^\]]+)\]/);
|
||||||
|
if (m) {
|
||||||
|
return {
|
||||||
|
schemaName: m[1],
|
||||||
|
pureName: m[2],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
schemaName: null,
|
||||||
|
pureName: name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fullNameToString({ schemaName, pureName }) {
|
||||||
|
if (schemaName) {
|
||||||
|
return `[${schemaName}].[${pureName}]`;
|
||||||
|
}
|
||||||
|
return pureName;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function quoteFullName(dialect, { schemaName, pureName }) {
|
||||||
|
if (schemaName) return `${dialect.quoteIdentifier(schemaName)}.${dialect.quoteIdentifier(pureName)}`;
|
||||||
|
return `${dialect.quoteIdentifier(pureName)}`;
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ import {
|
|||||||
deleteChangeSetRows,
|
deleteChangeSetRows,
|
||||||
batchUpdateChangeSet,
|
batchUpdateChangeSet,
|
||||||
setChangeSetValue,
|
setChangeSetValue,
|
||||||
|
fullNameToString,
|
||||||
} from '@dbgate/datalib';
|
} from '@dbgate/datalib';
|
||||||
import { scriptToSql } from '@dbgate/sqltree';
|
import { scriptToSql } from '@dbgate/sqltree';
|
||||||
import { copyTextToClipboard } from '../utility/clipboard';
|
import { copyTextToClipboard } from '../utility/clipboard';
|
||||||
@@ -603,9 +604,7 @@ export default function DataGridCore(props) {
|
|||||||
sourceStorageType: 'database',
|
sourceStorageType: 'database',
|
||||||
sourceConnectionId: conid,
|
sourceConnectionId: conid,
|
||||||
sourceDatabaseName: database,
|
sourceDatabaseName: database,
|
||||||
sourceTables: [
|
sourceTables: display.baseTable ? [fullNameToString(display.baseTable)] : [],
|
||||||
`${display.baseTable && display.baseTable.schemaName}.${display.baseTable && display.baseTable.pureName}`,
|
|
||||||
],
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -2,25 +2,26 @@ export default class ScriptWriter {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.s = '';
|
this.s = '';
|
||||||
this.put('const dbgateApi = require("@dbgate/api");');
|
this.put('const dbgateApi = require("@dbgate/api");');
|
||||||
|
this.put();
|
||||||
this.put('async function run() {');
|
this.put('async function run() {');
|
||||||
}
|
}
|
||||||
|
|
||||||
put(s) {
|
put(s = '') {
|
||||||
this.s += s;
|
this.s += s;
|
||||||
this.s += '\n';
|
this.s += '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
finish() {
|
finish() {
|
||||||
this.put('await dbgateApi.copyStream(queryReader, csvWriter);');
|
|
||||||
this.put('dbgateApi.runScript(run);');
|
|
||||||
this.put('}');
|
this.put('}');
|
||||||
|
this.put();
|
||||||
|
this.put('dbgateApi.runScript(run);');
|
||||||
}
|
}
|
||||||
|
|
||||||
assign(variableName, functionName, props) {
|
assign(variableName, functionName, props) {
|
||||||
this.put(`const ${variableName} = await dbgateApi.${functionName}(${JSON.stringify(props)});`);
|
this.put(` const ${variableName} = await dbgateApi.${functionName}(${JSON.stringify(props)});`);
|
||||||
}
|
}
|
||||||
|
|
||||||
copyStream(sourceVar, targetVar) {
|
copyStream(sourceVar, targetVar) {
|
||||||
this.put(`await dbgateApi.copyStream(${sourceVar}, ${targetVar});`);
|
this.put(` await dbgateApi.copyStream(${sourceVar}, ${targetVar});`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,9 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
import ScriptCreator from './ScriptCreator';
|
import ScriptCreator from './ScriptCreator';
|
||||||
import getAsArray from '../utility/getAsArray';
|
import getAsArray from '../utility/getAsArray';
|
||||||
import { getConnectionInfo } from '../utility/metadataLoaders';
|
import { getConnectionInfo } from '../utility/metadataLoaders';
|
||||||
import engines from '@dbgate/engines';
|
import engines from '@dbgate/engines';
|
||||||
|
import { quoteFullName, fullNameFromString } from '@dbgate/datalib';
|
||||||
function splitFullName(name) {
|
|
||||||
const i = name.indexOf('.');
|
|
||||||
if (i >= 0)
|
|
||||||
return {
|
|
||||||
schemaName: name.substr(0, i),
|
|
||||||
pureName: name.substr(i + 1),
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
schemaName: null,
|
|
||||||
pureName: name,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
function quoteFullName(dialect, { schemaName, pureName }) {
|
|
||||||
if (schemaName) return `${dialect.quoteIdentifier(schemaName)}.${dialect.quoteIdentifier(pureName)}`;
|
|
||||||
return `${dialect.quoteIdentifier(pureName)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async function createImpExpScript(values) {
|
export default async function createImpExpScript(values) {
|
||||||
const script = new ScriptCreator();
|
const script = new ScriptCreator();
|
||||||
@@ -29,10 +14,10 @@ export default async function createImpExpScript(values) {
|
|||||||
const connection = await getConnectionInfo({ conid: values.sourceConnectionId });
|
const connection = await getConnectionInfo({ conid: values.sourceConnectionId });
|
||||||
const driver = engines(connection);
|
const driver = engines(connection);
|
||||||
|
|
||||||
const fullName = splitFullName(table);
|
const fullName = fullNameFromString(table);
|
||||||
script.assign(sourceVar, 'queryReader', {
|
script.assign(sourceVar, 'queryReader', {
|
||||||
connection: {
|
connection: {
|
||||||
...connection,
|
..._.pick(connection, ['server', 'engine', 'user', 'password', 'port']),
|
||||||
database: values.sourceDatabaseName,
|
database: values.sourceDatabaseName,
|
||||||
},
|
},
|
||||||
sql: `select * from ${quoteFullName(driver.dialect, fullName)}`,
|
sql: `select * from ${quoteFullName(driver.dialect, fullName)}`,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import FormStyledButton from '../widgets/FormStyledButton';
|
|||||||
import { useConnectionList, useDatabaseList, useDatabaseInfo } from './metadataLoaders';
|
import { useConnectionList, useDatabaseList, useDatabaseInfo } from './metadataLoaders';
|
||||||
import useSocket from './SocketProvider';
|
import useSocket from './SocketProvider';
|
||||||
import getAsArray from './getAsArray';
|
import getAsArray from './getAsArray';
|
||||||
|
import { fullNameToString } from '@dbgate/datalib';
|
||||||
|
|
||||||
export const FormRow = styled.div`
|
export const FormRow = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -143,7 +144,7 @@ export function FormTablesSelect({ conidName, databaseName, name }) {
|
|||||||
const tablesOptions = React.useMemo(
|
const tablesOptions = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
[...((dbinfo && dbinfo.tables) || []), ...((dbinfo && dbinfo.views) || [])].map((x) => ({
|
[...((dbinfo && dbinfo.tables) || []), ...((dbinfo && dbinfo.views) || [])].map((x) => ({
|
||||||
value: `${x.schemaName}.${x.pureName}`,
|
value: fullNameToString(x),
|
||||||
label: x.pureName,
|
label: x.pureName,
|
||||||
})),
|
})),
|
||||||
[dbinfo]
|
[dbinfo]
|
||||||
|
|||||||
Reference in New Issue
Block a user