Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MySQL Node): Set paired items correctly in single query batch mode #8940

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/nodes-base/nodes/MySql/test/v2/runQueries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@ describe('Test MySql V2, runQueries', () => {
jest.clearAllMocks();
});

describe('in single query batch mode', () => {
it('should set paired items correctly', async () => {
const nodeOptions = { queryBatching: BATCH_MODE.SINGLE, nodeVersion: 2 };
const pool = createFakePool(fakeConnection);
const mockExecuteFns = createMockExecuteFunction({}, mySqlMockNode);

pool.query = jest.fn(async () => [
[[{ finishedAt: '2023-12-30' }], [{ finishedAt: '2023-12-31' }]],
]);

const result = await configureQueryRunner.call(
mockExecuteFns,
nodeOptions,
pool,
)([
{ query: 'SELECT finishedAt FROM my_table WHERE id = ?', values: [123] },
{ query: 'SELECT finishedAt FROM my_table WHERE id = ?', values: [456] },
]);

expect(result).toEqual([
{
json: { finishedAt: '2023-12-30' },
pairedItem: { item: 0 },
},
{
json: { finishedAt: '2023-12-31' },
pairedItem: { item: 1 },
},
]);
});
});

it('should execute in "Single" mode, should return success true', async () => {
const nodeOptions: IDataObject = { queryBatching: BATCH_MODE.SINGLE, nodeVersion: 2 };

Expand Down
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/MySql/v2/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ export function prepareOutput(
} else {
response
.filter((entry) => Array.isArray(entry))
.forEach((entry) => {
.forEach((entry, index) => {
const executionData = constructExecutionHelper(wrapData(entry), {
itemData,
itemData: Array.isArray(itemData) ? itemData[index] : itemData,
});

returnData.push(...executionData);
Expand Down
Loading