load views, procedures, functions

This commit is contained in:
Jan Prochazka
2020-04-12 12:24:40 +02:00
parent 241d8ea647
commit ea6c31187b
11 changed files with 217 additions and 35 deletions

View File

@@ -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',