mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +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">
|
||||
import { filterName, getConnectionLabel } from 'dbgate-tools';
|
||||
import { filterName, getConnectionLabel, getSqlFrontMatter } from 'dbgate-tools';
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
interface FileTypeHandler {
|
||||
icon: string;
|
||||
@@ -9,6 +10,7 @@
|
||||
currentConnection: boolean;
|
||||
extension: string;
|
||||
label: string;
|
||||
switchDatabaseOnOpen?: (data: any) => Promise<boolean>;
|
||||
}
|
||||
|
||||
const sql: FileTypeHandler = {
|
||||
@@ -19,6 +21,21 @@
|
||||
currentConnection: true,
|
||||
extension: 'sql',
|
||||
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 = {
|
||||
@@ -161,6 +178,7 @@
|
||||
import AppObjectCore from './AppObjectCore.svelte';
|
||||
import { isProApp } from '../utility/proTools';
|
||||
import { saveFileToDisk } from '../utility/exportFileTools';
|
||||
import { getConnectionInfo } from '../utility/metadataLoaders';
|
||||
|
||||
export let data;
|
||||
|
||||
@@ -281,6 +299,10 @@
|
||||
let tooltip = undefined;
|
||||
const connProps: any = {};
|
||||
|
||||
if (handler.switchDatabaseOnOpen) {
|
||||
await handler.switchDatabaseOnOpen(dataContent);
|
||||
}
|
||||
|
||||
if (handler.currentConnection) {
|
||||
const connection = _.get($currentDatabase, 'connection') || {};
|
||||
const database = _.get($currentDatabase, 'name');
|
||||
|
||||
@@ -616,16 +616,13 @@
|
||||
|
||||
export function toggleFixedConnection() {
|
||||
const frontMatter = getSqlFrontMatter($editorValue, yaml);
|
||||
const currentDatabase = getCurrentDatabase();
|
||||
setEditorData(
|
||||
setSqlFrontMatter(
|
||||
$editorValue,
|
||||
frontMatter?.connectionId &&
|
||||
frontMatter?.connectionId == currentDatabase?.connection?._id &&
|
||||
frontMatter?.databaseName == currentDatabase?.name
|
||||
frontMatter?.connectionId && frontMatter?.connectionId == conid && frontMatter?.databaseName == database
|
||||
? { ...frontMatter, connectionId: undefined, databaseName: undefined }
|
||||
: currentDatabase?.connection?._id
|
||||
? { ...frontMatter, connectionId: currentDatabase.connection._id, databaseName: currentDatabase.name }
|
||||
: conid
|
||||
? { ...frontMatter, connectionId: conid, databaseName: database }
|
||||
: { ...frontMatter, connectionId: undefined, databaseName: undefined },
|
||||
yaml
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user