Skip to content
This repository was archived by the owner on Aug 23, 2025. It is now read-only.

Commit 665fe9a

Browse files
Merge pull request #2 from nbtprojects/test/affectedRows
어펙티드 로우 노출 영역 추가
2 parents 6fe3732 + efa6fba commit 665fe9a

12 files changed

Lines changed: 51 additions & 7 deletions

File tree

client/src/common/QueryResultContainer.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
useStatementColumns,
55
useStatementRowCount,
66
useStatementStatus,
7+
useStatementAffectedRows,
78
} from '../stores/editor-store';
89
import { api } from '../utilities/api';
910
import ErrorBlock from './ErrorBlock';
@@ -20,6 +21,7 @@ function QueryResultContainer({ statementId }: Props) {
2021
const columns = useStatementColumns(statementId) || [];
2122
const rowCount = useStatementRowCount(statementId);
2223
const status = useStatementStatus(statementId);
24+
const affectedRows = useStatementAffectedRows(statementId);
2325
const queryError = useSessionQueryError();
2426
const { data, error } = api.useStatementResults(statementId, status);
2527
const { config } = useAppContext();
@@ -46,6 +48,8 @@ function QueryResultContainer({ statementId }: Props) {
4648
Query finished
4749
<br />
4850
No rows returned
51+
<br />
52+
{affectedRows ? `${affectedRows} rows affected` : ''}
4953
</InfoBlock>
5054
);
5155
}

client/src/queryEditor/StatementsTable.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function StatementTableRow({ statement }: { statement: Statement }) {
4141
</td>
4242
<td>{statusContent}</td>
4343
<td style={{ textAlign: 'right' }}>{statement.rowCount}</td>
44+
<td style={{ textAlign: 'right' }}>{statement.affectedRows}</td>
4445
<td style={{ textAlign: 'right' }}>
4546
{typeof statement.durationMs === 'number'
4647
? `${statement.durationMs / 1000}`
@@ -94,6 +95,7 @@ function StatementsTable({ statements }: { statements: Statement[] }) {
9495
<th className={styles.statementTextColHeader}>Statement</th>
9596
<th>Status</th>
9697
<th style={{ textAlign: 'right' }}>Rows</th>
98+
<th style={{ textAlign: 'right' }}>AffectedRows</th>
9799
<th style={{ textAlign: 'right' }}>Seconds</th>
98100
<th style={{ textAlign: 'right' }}></th>
99101
</tr>

client/src/stores/editor-store.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,15 @@ export function useStatementStatus(statementId?: string) {
407407
});
408408
}
409409

410+
export function useStatementAffectedRows(statementId?: string) {
411+
return useEditorStore((s) => {
412+
if (!statementId) {
413+
return null;
414+
}
415+
return s.statements[statementId]?.affectedRows;
416+
});
417+
}
418+
410419
export function useStatementSequence(statementId?: string) {
411420
return useEditorStore((s) => {
412421
if (!statementId) {

client/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface Statement {
4747
batchId: string;
4848
sequence: number;
4949
statementText: string;
50+
affectedRows: number;
5051
status: 'queued' | 'started' | 'finished' | 'error' | 'cancelled';
5152
executionId?: string;
5253
startTime?: string | Date;

server/drivers/mysql/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ class Client {
151151
if (rows.length >= maxRowsPlusOne) {
152152
return resolve({ rows: rows.slice(0, maxRows), incomplete: true });
153153
}
154-
return resolve({ rows, incomplete: false });
154+
return resolve({
155+
rows,
156+
incomplete: false,
157+
affectedRows: rows.affectedRows,
158+
});
155159
});
156160
});
157161
}

server/drivers/postgres/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Client {
104104
resultRows = resultRows.slice(0, maxRows);
105105
}
106106

107-
return { rows: resultRows, incomplete };
107+
return { rows: resultRows, incomplete, affectedRows: result.rowCount };
108108
}
109109
}
110110

server/lib/connection-client.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class ConnectionClient {
223223
throw error;
224224
}
225225

226-
let { rows, incomplete } = results;
226+
let { rows, incomplete, affectedRows } = results;
227227

228228
if (!Array.isArray(rows)) {
229229
appLog.warn(
@@ -238,14 +238,17 @@ class ConnectionClient {
238238
);
239239
rows = [];
240240
}
241-
241+
if (affectedRows) {
242+
// rows = [`Affected rows: ${affectedRows}`];
243+
}
242244
const columns = getColumns(rows);
243245
const stopTime = new Date();
244246
const queryRunTime = stopTime - startTime;
245247

246248
const queryResult = {
247249
rows,
248250
columns,
251+
affectedRows,
249252
incomplete: Boolean(incomplete),
250253
};
251254

@@ -254,6 +257,7 @@ class ConnectionClient {
254257
...queryContext,
255258
stopTime,
256259
queryRunTime,
260+
affectedRows,
257261
rowCount: rows.length,
258262
incomplete: Boolean(incomplete),
259263
},

server/lib/execute-batch.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,24 @@ async function executeBatch(config, models, webhooks, batchId) {
5151
await models.statements.updateStarted(statement.id, statementStartTime);
5252
queryResult = await connectionClient.runQuery(input);
5353
stopTime = new Date();
54+
55+
const affectedRows = queryResult.affectedRows || 0;
56+
5457
await models.statements.updateFinished(
5558
statement.id,
5659
queryResult,
5760
stopTime,
58-
stopTime - statementStartTime
61+
stopTime - statementStartTime,
62+
affectedRows
63+
);
64+
65+
webhooks.statementFinished(
66+
user,
67+
connection,
68+
batch,
69+
statement.id,
70+
affectedRows
5971
);
60-
webhooks.statementFinished(user, connection, batch, statement.id);
6172
} catch (error) {
6273
statementError = error;
6374
stopTime = new Date();

server/lib/webhooks.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class Webhooks {
176176
return this.send('statement_created', url, body);
177177
}
178178

179-
async statementFinished(user, connection, batch, statementId) {
179+
async statementFinished(user, connection, batch, statementId, customResults) {
180180
const url = this.hookEnabledUrl('webhookStatementFinishedUrl');
181181
if (!url) {
182182
return;
@@ -196,6 +196,7 @@ class Webhooks {
196196
user: userSummary(user),
197197
connection: connectionSummary(connection),
198198
results,
199+
customResults,
199200
};
200201

201202
return this.send('statement_finished', url, body);

server/migrations/04-00300-batch-statements.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ async function up(queryInterface, config, appLog) {
132132
incomplete: {
133133
type: Sequelize.BOOLEAN,
134134
},
135+
affected_rows: {
136+
type: Sequelize.INTEGER,
137+
},
135138
error: {
136139
type: Sequelize.JSON,
137140
},

0 commit comments

Comments
 (0)