DB ping can recover DB connection

This commit is contained in:
Jan Prochazka
2021-04-01 10:48:42 +02:00
parent a3762c6caa
commit 2a980a7892

View File

@@ -34,7 +34,7 @@ module.exports = {
socket.emitChanged(`database-status-changed-${conid}-${database}`);
},
handle_ping() { },
handle_ping() {},
async ensureOpened(conid, database) {
const existing = this.opened.find(x => x.conid == conid && x.database == database);
@@ -106,10 +106,14 @@ module.exports = {
ping_meta: 'post',
async ping({ conid, database }) {
const existing = this.opened.find(x => x.conid == conid && x.database == database);
let existing = this.opened.find(x => x.conid == conid && x.database == database);
if (existing) {
existing.subprocess.send({ msgtype: 'ping' });
} else {
existing = await this.ensureOpened(conid, database);
}
return {
status: 'ok',
connectionStatus: existing ? existing.status : null,
@@ -156,14 +160,13 @@ module.exports = {
sqlPreview_meta: 'post',
async sqlPreview({ conid, database, objects, options }) {
// wait for structure
await this.structure({ conid, database })
await this.structure({ conid, database });
const opened = await this.ensureOpened(conid, database);
const res = await this.sendRequest(opened, { msgtype: 'sqlPreview', objects, options });
return res;
},
// runCommand_meta: 'post',
// async runCommand({ conid, database, sql }) {
// console.log(`Running SQL command , conid=${conid}, database=${database}, sql=${sql}`);