model transform

This commit is contained in:
SPRINX0\prochazka 2024-11-01 16:57:48 +01:00
parent 4927c13e55
commit 967587c8e4
2 changed files with 6 additions and 4 deletions

View File

@ -31,6 +31,7 @@ const { testConnectionPermission } = require('../utility/hasPermission');
const { MissingCredentialsError } = require('../utility/exceptions');
const pipeForkLogs = require('../utility/pipeForkLogs');
const crypto = require('crypto');
const loadModelTransform = require('../utility/loadModelTransform');
const logger = getLogger('databaseConnections');
@ -392,11 +393,12 @@ module.exports = {
},
structure_meta: true,
async structure({ conid, database }, req) {
async structure({ conid, database, modelTransFile }, req) {
testConnectionPermission(conid, req);
if (conid == '__model') {
const model = await importDbModel(database);
return model;
const trans = await loadModelTransform(modelTransFile);
return trans ? trans(model) : model;
}
const opened = await this.ensureOpened(conid, database);

View File

@ -6,9 +6,9 @@ import { extendDatabaseInfo } from 'dbgate-tools';
import { setLocalStorage } from '../utility/storageCache';
import { apiCall, apiOff, apiOn } from './api';
const databaseInfoLoader = ({ conid, database }) => ({
const databaseInfoLoader = ({ conid, database, modelTransFile }) => ({
url: 'database-connections/structure',
params: { conid, database },
params: { conid, database, modelTransFile },
reloadTrigger: { key: `database-structure-changed`, conid, database },
transform: extendDatabaseInfo,
});