introduced yarn workspace

This commit is contained in:
Jan Prochazka
2020-02-03 19:43:11 +01:00
parent 56e6777044
commit acf6a1ce74
151 changed files with 1515 additions and 8576 deletions

View File

@@ -0,0 +1,69 @@
const _ = require('lodash');
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');
module.exports = {
/** @type {import('dbgate').OpenedDatabaseConnection[]} */
opened: [],
requests: {},
handle_structure(conid, database, { structure }) {
const existing = this.opened.find(x => x.conid == conid && x.database == database);
if (!existing) return;
existing.structure = structure;
conid;
socket.emit(`database-structure-changed-${conid}-${database}`);
},
handle_error(conid, database, props) {
const { error } = props;
console.log(`Error in database connection ${conid}, database ${database}: ${error}`);
},
handle_response(conid, database, { msgid, ...response }) {
const [resolve, reject] = this.requests[msgid];
resolve(response);
delete this.requests[msgid];
},
async ensureOpened(conid, 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(`${__dirname}/../proc/databaseConnectionProcess.js`);
const newOpened = {
conid,
database,
subprocess,
structure: DatabaseAnalyser.createEmptyStructure(),
connection,
};
this.opened.push(newOpened);
// @ts-ignore
subprocess.on('message', ({ msgtype, ...message }) => {
this[`handle_${msgtype}`](conid, database, message);
});
subprocess.send({ msgtype: 'connect', ...connection, database });
return newOpened;
},
/** @param {import('dbgate').OpenedDatabaseConnection} conn */
async sendRequest(conn, message) {
const msgid = uuidv1();
const promise = new Promise((resolve, reject) => {
this.requests[msgid] = [resolve, reject];
conn.subprocess.send({ msgid, ...message });
});
return promise;
},
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']));
},
};