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

This commit is contained in:
Iván Ovejero 2024-03-21 12:17:43 +01:00 committed by GitHub
parent 34b79333fc
commit 89df277b80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 2 deletions

View file

@ -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 };

View file

@ -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);