mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 12:35:59 +00:00
load views, procedures, functions
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
const _ = require('lodash');
|
||||
const fp = require('lodash/fp');
|
||||
const uuidv1 = require('uuid/v1');
|
||||
const connections = require('./connections');
|
||||
const socket = require('../utility/socket');
|
||||
const { fork } = require('child_process');
|
||||
const DatabaseAnalyser = require('@dbgate/engines/default/DatabaseAnalyser');
|
||||
|
||||
function pickObjectNames(array) {
|
||||
return _.sortBy(array, (x) => `${x.schemaName}.${x.pureName}`).map(fp.pick(['pureName', 'schemaName']));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
/** @type {import('@dbgate/types').OpenedDatabaseConnection[]} */
|
||||
opened: [],
|
||||
requests: {},
|
||||
|
||||
handle_structure(conid, database, { structure }) {
|
||||
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
||||
const existing = this.opened.find((x) => x.conid == conid && x.database == database);
|
||||
if (!existing) return;
|
||||
existing.structure = structure;
|
||||
socket.emit(`database-structure-changed-${conid}-${database}`);
|
||||
@@ -27,7 +32,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
async ensureOpened(conid, database) {
|
||||
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
||||
const existing = this.opened.find((x) => x.conid == conid && x.database == database);
|
||||
if (existing) return existing;
|
||||
const connection = await connections.get({ conid });
|
||||
const subprocess = fork(process.argv[1], ['databaseConnectionProcess']);
|
||||
@@ -60,10 +65,14 @@ module.exports = {
|
||||
listObjects_meta: 'get',
|
||||
async listObjects({ conid, database }) {
|
||||
const opened = await this.ensureOpened(conid, database);
|
||||
const { tables } = opened.structure;
|
||||
return {
|
||||
tables: _.sortBy(tables, x => `${x.schemaName}.${x.pureName}`),
|
||||
}; // .map(fp.pick(['tableName', 'schemaName']));
|
||||
const types = ['tables', 'views', 'procedures', 'functions', 'triggers'];
|
||||
return types.reduce(
|
||||
(res, type) => ({
|
||||
...res,
|
||||
[type]: pickObjectNames(opened.structure[type]),
|
||||
}),
|
||||
{}
|
||||
);
|
||||
},
|
||||
|
||||
queryData_meta: 'post',
|
||||
|
||||
Reference in New Issue
Block a user