mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 18:26:00 +00:00
SYNC: fixed connection for scripts
This commit is contained in:
committed by
Diflow
parent
a648f1ee67
commit
edf1632cab
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
import { filterName, getConnectionLabel } from 'dbgate-tools';
|
import { filterName, getConnectionLabel, getSqlFrontMatter } from 'dbgate-tools';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
|
|
||||||
interface FileTypeHandler {
|
interface FileTypeHandler {
|
||||||
icon: string;
|
icon: string;
|
||||||
@@ -9,6 +10,7 @@
|
|||||||
currentConnection: boolean;
|
currentConnection: boolean;
|
||||||
extension: string;
|
extension: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
switchDatabaseOnOpen?: (data: any) => Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sql: FileTypeHandler = {
|
const sql: FileTypeHandler = {
|
||||||
@@ -19,6 +21,21 @@
|
|||||||
currentConnection: true,
|
currentConnection: true,
|
||||||
extension: 'sql',
|
extension: 'sql',
|
||||||
label: 'SQL file',
|
label: 'SQL file',
|
||||||
|
switchDatabaseOnOpen: async data => {
|
||||||
|
const frontMatter = getSqlFrontMatter(data, yaml);
|
||||||
|
if (frontMatter?.connectionId) {
|
||||||
|
const connection = await getConnectionInfo({ conid: frontMatter.connectionId });
|
||||||
|
// console.log('Switching database to', frontMatter.databaseName, 'on connection', connection);
|
||||||
|
if (connection && frontMatter.databaseName) {
|
||||||
|
currentDatabase.set({
|
||||||
|
connection,
|
||||||
|
name: frontMatter.databaseName,
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const shell: FileTypeHandler = {
|
const shell: FileTypeHandler = {
|
||||||
@@ -161,6 +178,7 @@
|
|||||||
import AppObjectCore from './AppObjectCore.svelte';
|
import AppObjectCore from './AppObjectCore.svelte';
|
||||||
import { isProApp } from '../utility/proTools';
|
import { isProApp } from '../utility/proTools';
|
||||||
import { saveFileToDisk } from '../utility/exportFileTools';
|
import { saveFileToDisk } from '../utility/exportFileTools';
|
||||||
|
import { getConnectionInfo } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
@@ -281,6 +299,10 @@
|
|||||||
let tooltip = undefined;
|
let tooltip = undefined;
|
||||||
const connProps: any = {};
|
const connProps: any = {};
|
||||||
|
|
||||||
|
if (handler.switchDatabaseOnOpen) {
|
||||||
|
await handler.switchDatabaseOnOpen(dataContent);
|
||||||
|
}
|
||||||
|
|
||||||
if (handler.currentConnection) {
|
if (handler.currentConnection) {
|
||||||
const connection = _.get($currentDatabase, 'connection') || {};
|
const connection = _.get($currentDatabase, 'connection') || {};
|
||||||
const database = _.get($currentDatabase, 'name');
|
const database = _.get($currentDatabase, 'name');
|
||||||
|
|||||||
@@ -616,16 +616,13 @@
|
|||||||
|
|
||||||
export function toggleFixedConnection() {
|
export function toggleFixedConnection() {
|
||||||
const frontMatter = getSqlFrontMatter($editorValue, yaml);
|
const frontMatter = getSqlFrontMatter($editorValue, yaml);
|
||||||
const currentDatabase = getCurrentDatabase();
|
|
||||||
setEditorData(
|
setEditorData(
|
||||||
setSqlFrontMatter(
|
setSqlFrontMatter(
|
||||||
$editorValue,
|
$editorValue,
|
||||||
frontMatter?.connectionId &&
|
frontMatter?.connectionId && frontMatter?.connectionId == conid && frontMatter?.databaseName == database
|
||||||
frontMatter?.connectionId == currentDatabase?.connection?._id &&
|
|
||||||
frontMatter?.databaseName == currentDatabase?.name
|
|
||||||
? { ...frontMatter, connectionId: undefined, databaseName: undefined }
|
? { ...frontMatter, connectionId: undefined, databaseName: undefined }
|
||||||
: currentDatabase?.connection?._id
|
: conid
|
||||||
? { ...frontMatter, connectionId: currentDatabase.connection._id, databaseName: currentDatabase.name }
|
? { ...frontMatter, connectionId: conid, databaseName: database }
|
||||||
: { ...frontMatter, connectionId: undefined, databaseName: undefined },
|
: { ...frontMatter, connectionId: undefined, databaseName: undefined },
|
||||||
yaml
|
yaml
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user