mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 09:44:00 +00:00
This commit is contained in:
@@ -50,8 +50,8 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
handle_recordset(sesid, props) {
|
handle_recordset(sesid, props) {
|
||||||
const { jslid } = props;
|
const { jslid, resultIndex } = props;
|
||||||
socket.emit(`session-recordset-${sesid}`, { jslid });
|
socket.emit(`session-recordset-${sesid}`, { jslid, resultIndex });
|
||||||
},
|
},
|
||||||
|
|
||||||
handle_stats(sesid, stats) {
|
handle_stats(sesid, stats) {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ let afterConnectCallbacks = [];
|
|||||||
let currentHandlers = [];
|
let currentHandlers = [];
|
||||||
|
|
||||||
class TableWriter {
|
class TableWriter {
|
||||||
constructor(columns) {
|
constructor(columns, resultIndex) {
|
||||||
this.jslid = uuidv1();
|
this.jslid = uuidv1();
|
||||||
this.currentFile = path.join(jsldir(), `${this.jslid}.jsonl`);
|
this.currentFile = path.join(jsldir(), `${this.jslid}.jsonl`);
|
||||||
this.currentRowCount = 0;
|
this.currentRowCount = 0;
|
||||||
@@ -23,7 +23,8 @@ class TableWriter {
|
|||||||
fs.writeFileSync(this.currentFile, JSON.stringify({ columns }) + '\n');
|
fs.writeFileSync(this.currentFile, JSON.stringify({ columns }) + '\n');
|
||||||
this.currentStream = fs.createWriteStream(this.currentFile, { flags: 'a' });
|
this.currentStream = fs.createWriteStream(this.currentFile, { flags: 'a' });
|
||||||
this.writeCurrentStats(false, false);
|
this.writeCurrentStats(false, false);
|
||||||
process.send({ msgtype: 'recordset', jslid: this.jslid });
|
this.resultIndex = resultIndex;
|
||||||
|
process.send({ msgtype: 'recordset', jslid: this.jslid, resultIndex });
|
||||||
}
|
}
|
||||||
|
|
||||||
row(row) {
|
row(row) {
|
||||||
@@ -64,7 +65,7 @@ class TableWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class StreamHandler {
|
class StreamHandler {
|
||||||
constructor() {
|
constructor(resultIndex) {
|
||||||
this.recordset = this.recordset.bind(this);
|
this.recordset = this.recordset.bind(this);
|
||||||
this.row = this.row.bind(this);
|
this.row = this.row.bind(this);
|
||||||
// this.error = this.error.bind(this);
|
// this.error = this.error.bind(this);
|
||||||
@@ -73,6 +74,7 @@ class StreamHandler {
|
|||||||
// use this for cancelling
|
// use this for cancelling
|
||||||
this.stream = null;
|
this.stream = null;
|
||||||
this.plannedStats = false;
|
this.plannedStats = false;
|
||||||
|
this.resultIndex = resultIndex;
|
||||||
currentHandlers = [...currentHandlers, this];
|
currentHandlers = [...currentHandlers, this];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +87,7 @@ class StreamHandler {
|
|||||||
|
|
||||||
recordset(columns) {
|
recordset(columns) {
|
||||||
this.closeCurrentWriter();
|
this.closeCurrentWriter();
|
||||||
this.currentWriter = new TableWriter(columns);
|
this.currentWriter = new TableWriter(columns, this.resultIndex);
|
||||||
|
|
||||||
// this.writeCurrentStats();
|
// this.writeCurrentStats();
|
||||||
|
|
||||||
@@ -142,10 +144,12 @@ async function handleExecuteQuery({ sql }) {
|
|||||||
await waitConnected();
|
await waitConnected();
|
||||||
const driver = engines(storedConnection);
|
const driver = engines(storedConnection);
|
||||||
|
|
||||||
|
let resultIndex = 0;
|
||||||
for (const sqlItem of goSplit(sql)) {
|
for (const sqlItem of goSplit(sql)) {
|
||||||
const handler = new StreamHandler();
|
const handler = new StreamHandler(resultIndex);
|
||||||
const stream = await driver.stream(systemConnection, sqlItem, handler);
|
const stream = await driver.stream(systemConnection, sqlItem, handler);
|
||||||
handler.stream = stream;
|
handler.stream = stream;
|
||||||
|
resultIndex += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import _ from 'lodash';
|
||||||
import { TabPage, TabControl } from '../widgets/TabControl';
|
import { TabPage, TabControl } from '../widgets/TabControl';
|
||||||
import useSocket from '../utility/SocketProvider';
|
import useSocket from '../utility/SocketProvider';
|
||||||
import JslDataGrid from './JslDataGrid';
|
import JslDataGrid from './JslDataGrid';
|
||||||
|
|
||||||
export default function ResultTabs({ children, sessionId, executeNumber }) {
|
export default function ResultTabs({ children, sessionId, executeNumber }) {
|
||||||
const socket = useSocket();
|
const socket = useSocket();
|
||||||
const [resultIds, setResultIds] = React.useState([]);
|
const [resultInfos, setResultInfos] = React.useState([]);
|
||||||
|
|
||||||
const handleResultSet = React.useCallback((props) => {
|
const handleResultSet = React.useCallback((props) => {
|
||||||
const { jslid } = props;
|
const { jslid, resultIndex } = props;
|
||||||
setResultIds((ids) => [...ids, jslid]);
|
setResultInfos((array) => [...array, { jslid, resultIndex }]);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
setResultIds([]);
|
setResultInfos([]);
|
||||||
}, [executeNumber]);
|
}, [executeNumber]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@@ -26,11 +27,11 @@ export default function ResultTabs({ children, sessionId, executeNumber }) {
|
|||||||
}, [sessionId, socket]);
|
}, [sessionId, socket]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabControl activePageIndex={resultIds.length > 0 ? 1 : 0}>
|
<TabControl activePageIndex={resultInfos.length > 0 ? 1 : 0}>
|
||||||
{children}
|
{children}
|
||||||
{resultIds.map((jslid, index) => (
|
{_.sortBy(resultInfos, 'resultIndex').map((info) => (
|
||||||
<TabPage label={`Result ${index + 1}`} key={index}>
|
<TabPage label={`Result ${info.resultIndex + 1}`} key={info.jslid}>
|
||||||
<JslDataGrid jslid={jslid} />
|
<JslDataGrid jslid={info.jslid} key={info.jslid} />
|
||||||
</TabPage>
|
</TabPage>
|
||||||
))}
|
))}
|
||||||
</TabControl>
|
</TabControl>
|
||||||
|
|||||||
Reference in New Issue
Block a user