query - result tabs

This commit is contained in:
Jan Prochazka
2020-04-07 21:37:00 +02:00
parent 72375ec635
commit 949985769c
15 changed files with 316 additions and 48 deletions

View File

@@ -1,10 +1,55 @@
const engines = require('@dbgate/engines');
const uuidv1 = require('uuid/v1');
const path = require('path');
const fs = require('fs');
const driverConnect = require('../utility/driverConnect');
const { jsldir } = require('../utility/directories');
let systemConnection;
let storedConnection;
let afterConnectCallbacks = [];
class StreamHandler {
constructor() {
this.recordset = this.recordset.bind(this);
this.row = this.row.bind(this);
this.error = this.error.bind(this);
this.done = this.done.bind(this);
this.info = this.info.bind(this);
}
closeCurrentStream() {
if (this.currentStream) {
this.currentStream.end();
this.currentStream = null;
}
}
recordset(columns) {
this.closeCurrentStream();
this.jslid = uuidv1();
this.currentFile = path.join(jsldir(), `${this.jslid}.jsonl`);
this.currentStream = fs.createWriteStream(this.currentFile);
fs.writeFileSync(`${this.currentFile}.info`, JSON.stringify(columns));
process.send({ msgtype: 'recordset', jslid: this.jslid });
}
row(row) {
// console.log('ACCEPT ROW', row);
this.currentStream.write(JSON.stringify(row) + '\n');
}
error(error) {
process.send({ msgtype: 'error', error });
}
done(result) {
this.closeCurrentStream();
process.send({ msgtype: 'done', result });
}
info(info) {
process.send({ msgtype: 'info', info });
}
}
async function handleConnect(connection) {
storedConnection = connection;
@@ -27,23 +72,8 @@ async function handleExecuteQuery({ sql }) {
await waitConnected();
const driver = engines(storedConnection);
await driver.stream(systemConnection, sql, {
recordset: (columns) => {
process.send({ msgtype: 'recordset', columns });
},
row: (row) => {
process.send({ msgtype: 'row', row });
},
error: (error) => {
process.send({ msgtype: 'error', error });
},
done: (result) => {
process.send({ msgtype: 'done', result });
},
info: (info) => {
process.send({ msgtype: 'info', info });
},
});
const handler = new StreamHandler();
await driver.stream(systemConnection, sql, handler);
}
const messageHandlers = {