load database list

This commit is contained in:
Jan Prochazka
2020-01-05 10:25:10 +01:00
parent 0e860e8ba3
commit c87463f45e
7 changed files with 74 additions and 14 deletions

View File

@@ -6,21 +6,25 @@ module.exports = {
opened: [],
handle_databases(id, { databases }) {
const existing = this.opened.find(x => x.connection.id == id);
const existing = this.opened.find(x => x.id == id);
if (!existing) return;
existing.databases = databases;
socket.emit(`database-list-changed-${id}`);
},
handle_error(id, { error }) {
console.log(error);
},
async ensureOpened(id) {
const existing = this.opened.find(x => x.connection.id == id);
const existing = this.opened.find(x => x.id == id);
if (existing) return existing;
const connection = await connections.get(id);
const connection = await connections.get({ id });
const subprocess = fork(`${__dirname}/../proc/serverConnectionProcess.js`);
const newOpened = {
id,
subprocess,
databases: [],
connection,
};
this.opened.push(newOpened);
subprocess.on('message', ({ msgtype, ...message }) => {

View File

@@ -6,6 +6,7 @@ const io = require('socket.io');
const useController = require('./utility/useController');
const connections = require('./controllers/connections');
const serverConnections = require('./controllers/serverConnections');
const socket = require('./utility/socket');
const app = express();
@@ -21,5 +22,6 @@ app.get('/', (req, res) => {
});
useController(app, '/connections', connections);
useController(app, '/server-connections', serverConnections);
server.listen(3000);

View File

@@ -11,9 +11,11 @@ async function handleRefreshDatabases() {
async function handleConnect(connection) {
storedConnection = connection;
const driver = require(`../engines/${storedConnection.engine}/index`);
const driver = engines(storedConnection);
systemConnection = await driver.connect(storedConnection);
setInterval(handleRefreshDatabases, 30 * 1000);
handleRefreshDatabases();
// setInterval(handleRefreshDatabases, 30 * 1000);
}
const messageHandlers = {