mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 18:56:00 +00:00
rename id=>conid, id=>tabid
This commit is contained in:
@@ -52,8 +52,8 @@ module.exports = {
|
||||
},
|
||||
|
||||
get_meta: 'get',
|
||||
async get({ id }) {
|
||||
const res = await this.datastore.find({ _id: id });
|
||||
async get({ conid }) {
|
||||
const res = await this.datastore.find({ _id: conid });
|
||||
return res[0];
|
||||
},
|
||||
};
|
||||
|
||||
@@ -10,28 +10,28 @@ module.exports = {
|
||||
opened: [],
|
||||
requests: {},
|
||||
|
||||
handle_structure(id, database, { structure }) {
|
||||
const existing = this.opened.find(x => x.id == id && x.database == database);
|
||||
handle_structure(conid, database, { structure }) {
|
||||
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
||||
if (!existing) return;
|
||||
existing.structure = structure;
|
||||
socket.emit(`database-structure-changed-${id}-${database}`);
|
||||
existing.structure = structure;conid
|
||||
socket.emit(`database-structure-changed-${conid}-${database}`);
|
||||
},
|
||||
handle_error(id, { error }) {
|
||||
handle_error(conid, { error }) {
|
||||
console.log(error);
|
||||
},
|
||||
handle_response(id, database, { msgid, ...response }) {
|
||||
handle_response(conid, database, { msgid, ...response }) {
|
||||
const [resolve, reject] = this.requests[msgid];
|
||||
resolve(response);
|
||||
delete this.requests[msgid];
|
||||
},
|
||||
|
||||
async ensureOpened(id, database) {
|
||||
const existing = this.opened.find(x => x.id == id && x.database == database);
|
||||
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({ id });
|
||||
const connection = await connections.get({ conid });
|
||||
const subprocess = fork(`${__dirname}/../proc/databaseConnectionProcess.js`);
|
||||
const newOpened = {
|
||||
id,
|
||||
conid,
|
||||
database,
|
||||
subprocess,
|
||||
structure: DatabaseAnalyser.createEmptyStructure(),
|
||||
@@ -40,7 +40,7 @@ module.exports = {
|
||||
this.opened.push(newOpened);
|
||||
// @ts-ignore
|
||||
subprocess.on('message', ({ msgtype, ...message }) => {
|
||||
this[`handle_${msgtype}`](id, database, message);
|
||||
this[`handle_${msgtype}`](conid, database, message);
|
||||
});
|
||||
subprocess.send({ msgtype: 'connect', ...connection, database });
|
||||
return newOpened;
|
||||
@@ -57,8 +57,8 @@ module.exports = {
|
||||
},
|
||||
|
||||
listObjects_meta: 'get',
|
||||
async listObjects({ id, database }) {
|
||||
const opened = await this.ensureOpened(id, database);
|
||||
async listObjects({ conid, database }) {
|
||||
const opened = await this.ensureOpened(conid, database);
|
||||
const { tables } = opened.structure;
|
||||
return {
|
||||
tables: _.sortBy(tables, x => `${x.schemaName}.${x.pureName}`),
|
||||
|
||||
@@ -6,23 +6,23 @@ const { fork } = require('child_process');
|
||||
module.exports = {
|
||||
opened: [],
|
||||
|
||||
handle_databases(id, { databases }) {
|
||||
const existing = this.opened.find(x => x.id == id);
|
||||
handle_databases(conid, { databases }) {
|
||||
const existing = this.opened.find(x => x.conid == conid);
|
||||
if (!existing) return;
|
||||
existing.databases = databases;
|
||||
socket.emit(`database-list-changed-${id}`);
|
||||
socket.emit(`database-list-changed-${conid}`);
|
||||
},
|
||||
handle_error(id, { error }) {
|
||||
handle_error(conid, { error }) {
|
||||
console.log(error);
|
||||
},
|
||||
|
||||
async ensureOpened(id) {
|
||||
const existing = this.opened.find(x => x.id == id);
|
||||
async ensureOpened(conid) {
|
||||
const existing = this.opened.find(x => x.conid == conid);
|
||||
if (existing) return existing;
|
||||
const connection = await connections.get({ id });
|
||||
const connection = await connections.get({ conid });
|
||||
const subprocess = fork(`${__dirname}/../proc/serverConnectionProcess.js`);
|
||||
const newOpened = {
|
||||
id,
|
||||
conid,
|
||||
subprocess,
|
||||
databases: [],
|
||||
connection,
|
||||
@@ -30,15 +30,15 @@ module.exports = {
|
||||
this.opened.push(newOpened);
|
||||
// @ts-ignore
|
||||
subprocess.on('message', ({ msgtype, ...message }) => {
|
||||
this[`handle_${msgtype}`](id, message);
|
||||
this[`handle_${msgtype}`](conid, message);
|
||||
});
|
||||
subprocess.send({ msgtype: 'connect', ...connection });
|
||||
return newOpened;
|
||||
},
|
||||
|
||||
listDatabases_meta: 'get',
|
||||
async listDatabases({ id }) {
|
||||
const opened = await this.ensureOpened(id);
|
||||
async listDatabases({ conid }) {
|
||||
const opened = await this.ensureOpened(conid);
|
||||
return opened.databases;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@ module.exports = {
|
||||
tableData_meta: 'get',
|
||||
async tableData({ id, database, schemaName, pureName }) {
|
||||
const opened = await databaseConnections.ensureOpened(id, database);
|
||||
const res = opened.sendRequest({ msgtype: 'tableData', schemaName, pureName });
|
||||
return res;
|
||||
// const res = opened.sendRequest({ msgtype: 'tableData', schemaName, pureName });
|
||||
// return res;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ export interface DatabaseInfo {
|
||||
}
|
||||
|
||||
export interface OpenedDatabaseConnection {
|
||||
id: string;
|
||||
conid: string;
|
||||
database: string;
|
||||
structure: DatabaseInfo;
|
||||
subprocess: ChildProcess;
|
||||
|
||||
Reference in New Issue
Block a user