mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 12:43:58 +00:00
DB ping can recover DB connection
This commit is contained in:
@@ -34,7 +34,7 @@ module.exports = {
|
|||||||
socket.emitChanged(`database-status-changed-${conid}-${database}`);
|
socket.emitChanged(`database-status-changed-${conid}-${database}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
handle_ping() { },
|
handle_ping() {},
|
||||||
|
|
||||||
async ensureOpened(conid, database) {
|
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);
|
||||||
@@ -106,10 +106,14 @@ module.exports = {
|
|||||||
|
|
||||||
ping_meta: 'post',
|
ping_meta: 'post',
|
||||||
async ping({ conid, database }) {
|
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) {
|
if (existing) {
|
||||||
existing.subprocess.send({ msgtype: 'ping' });
|
existing.subprocess.send({ msgtype: 'ping' });
|
||||||
|
} else {
|
||||||
|
existing = await this.ensureOpened(conid, database);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
connectionStatus: existing ? existing.status : null,
|
connectionStatus: existing ? existing.status : null,
|
||||||
@@ -156,14 +160,13 @@ module.exports = {
|
|||||||
sqlPreview_meta: 'post',
|
sqlPreview_meta: 'post',
|
||||||
async sqlPreview({ conid, database, objects, options }) {
|
async sqlPreview({ conid, database, objects, options }) {
|
||||||
// wait for structure
|
// wait for structure
|
||||||
await this.structure({ conid, database })
|
await this.structure({ conid, database });
|
||||||
|
|
||||||
const opened = await this.ensureOpened(conid, database);
|
const opened = await this.ensureOpened(conid, database);
|
||||||
const res = await this.sendRequest(opened, { msgtype: 'sqlPreview', objects, options });
|
const res = await this.sendRequest(opened, { msgtype: 'sqlPreview', objects, options });
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// runCommand_meta: 'post',
|
// runCommand_meta: 'post',
|
||||||
// async runCommand({ conid, database, sql }) {
|
// async runCommand({ conid, database, sql }) {
|
||||||
// console.log(`Running SQL command , conid=${conid}, database=${database}, sql=${sql}`);
|
// console.log(`Running SQL command , conid=${conid}, database=${database}, sql=${sql}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user