This commit is contained in:
Jan Prochazka
2020-09-24 12:49:18 +02:00
parent e9cbd72100
commit 6b04593343
3 changed files with 20 additions and 15 deletions

View File

@@ -50,8 +50,8 @@ module.exports = {
},
handle_recordset(sesid, props) {
const { jslid } = props;
socket.emit(`session-recordset-${sesid}`, { jslid });
const { jslid, resultIndex } = props;
socket.emit(`session-recordset-${sesid}`, { jslid, resultIndex });
},
handle_stats(sesid, stats) {

View File

@@ -15,7 +15,7 @@ let afterConnectCallbacks = [];
let currentHandlers = [];
class TableWriter {
constructor(columns) {
constructor(columns, resultIndex) {
this.jslid = uuidv1();
this.currentFile = path.join(jsldir(), `${this.jslid}.jsonl`);
this.currentRowCount = 0;
@@ -23,7 +23,8 @@ class TableWriter {
fs.writeFileSync(this.currentFile, JSON.stringify({ columns }) + '\n');
this.currentStream = fs.createWriteStream(this.currentFile, { flags: 'a' });
this.writeCurrentStats(false, false);
process.send({ msgtype: 'recordset', jslid: this.jslid });
this.resultIndex = resultIndex;
process.send({ msgtype: 'recordset', jslid: this.jslid, resultIndex });
}
row(row) {
@@ -64,7 +65,7 @@ class TableWriter {
}
class StreamHandler {
constructor() {
constructor(resultIndex) {
this.recordset = this.recordset.bind(this);
this.row = this.row.bind(this);
// this.error = this.error.bind(this);
@@ -73,6 +74,7 @@ class StreamHandler {
// use this for cancelling
this.stream = null;
this.plannedStats = false;
this.resultIndex = resultIndex;
currentHandlers = [...currentHandlers, this];
}
@@ -85,7 +87,7 @@ class StreamHandler {
recordset(columns) {
this.closeCurrentWriter();
this.currentWriter = new TableWriter(columns);
this.currentWriter = new TableWriter(columns, this.resultIndex);
// this.writeCurrentStats();
@@ -142,10 +144,12 @@ async function handleExecuteQuery({ sql }) {
await waitConnected();
const driver = engines(storedConnection);
let resultIndex = 0;
for (const sqlItem of goSplit(sql)) {
const handler = new StreamHandler();
const handler = new StreamHandler(resultIndex);
const stream = await driver.stream(systemConnection, sqlItem, handler);
handler.stream = stream;
resultIndex += 1;
}
}

View File

@@ -1,19 +1,20 @@
import React from 'react';
import _ from 'lodash';
import { TabPage, TabControl } from '../widgets/TabControl';
import useSocket from '../utility/SocketProvider';
import JslDataGrid from './JslDataGrid';
export default function ResultTabs({ children, sessionId, executeNumber }) {
const socket = useSocket();
const [resultIds, setResultIds] = React.useState([]);
const [resultInfos, setResultInfos] = React.useState([]);
const handleResultSet = React.useCallback((props) => {
const { jslid } = props;
setResultIds((ids) => [...ids, jslid]);
const { jslid, resultIndex } = props;
setResultInfos((array) => [...array, { jslid, resultIndex }]);
}, []);
React.useEffect(() => {
setResultIds([]);
setResultInfos([]);
}, [executeNumber]);
React.useEffect(() => {
@@ -26,11 +27,11 @@ export default function ResultTabs({ children, sessionId, executeNumber }) {
}, [sessionId, socket]);
return (
<TabControl activePageIndex={resultIds.length > 0 ? 1 : 0}>
<TabControl activePageIndex={resultInfos.length > 0 ? 1 : 0}>
{children}
{resultIds.map((jslid, index) => (
<TabPage label={`Result ${index + 1}`} key={index}>
<JslDataGrid jslid={jslid} />
{_.sortBy(resultInfos, 'resultIndex').map((info) => (
<TabPage label={`Result ${info.resultIndex + 1}`} key={info.jslid}>
<JslDataGrid jslid={info.jslid} key={info.jslid} />
</TabPage>
))}
</TabControl>