mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 19:36:00 +00:00
38 lines
979 B
JavaScript
38 lines
979 B
JavaScript
const engines = require('../engines');
|
|
|
|
let systemConnection;
|
|
let storedConnection;
|
|
|
|
async function handleFullRefresh() {
|
|
const driver = engines(storedConnection);
|
|
const structure = await driver.analyseFull(systemConnection);
|
|
console.log('SENDING STRUCTURE', structure);
|
|
process.send({ msgtype: 'structure', structure });
|
|
}
|
|
|
|
async function handleConnect(connection, database) {
|
|
storedConnection = connection;
|
|
|
|
const driver = engines(storedConnection);
|
|
systemConnection = await driver.connect({ ...storedConnection, database });
|
|
handleFullRefresh();
|
|
setInterval(handleFullRefresh, 30 * 1000);
|
|
}
|
|
|
|
const messageHandlers = {
|
|
connect: handleConnect,
|
|
};
|
|
|
|
async function handleMessage({ msgtype, database, ...other }) {
|
|
const handler = messageHandlers[msgtype];
|
|
await handler(other, database);
|
|
}
|
|
|
|
process.on('message', async message => {
|
|
try {
|
|
await handleMessage(message);
|
|
} catch (e) {
|
|
process.send({ msgtype: 'error', error: e.message });
|
|
}
|
|
});
|