rename id=>conid, id=>tabid

This commit is contained in:
Jan Prochazka
2020-01-25 13:57:56 +01:00
parent 8646221b41
commit 2a40b05ae0
8 changed files with 44 additions and 44 deletions

View File

@@ -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];
},
};

View File

@@ -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}`),

View File

@@ -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;
},
};

View File

@@ -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;
},
};

View File

@@ -22,7 +22,7 @@ export interface DatabaseInfo {
}
export interface OpenedDatabaseConnection {
id: string;
conid: string;
database: string;
structure: DatabaseInfo;
subprocess: ChildProcess;