diff --git a/packages/nodes-base/nodes/MySql/test/v2/runQueries.test.ts b/packages/nodes-base/nodes/MySql/test/v2/runQueries.test.ts index cdcf00fd07..9dc3f8d451 100644 --- a/packages/nodes-base/nodes/MySql/test/v2/runQueries.test.ts +++ b/packages/nodes-base/nodes/MySql/test/v2/runQueries.test.ts @@ -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 }; diff --git a/packages/nodes-base/nodes/MySql/v2/helpers/utils.ts b/packages/nodes-base/nodes/MySql/v2/helpers/utils.ts index 4ac1f9b3d5..be48ed42e6 100644 --- a/packages/nodes-base/nodes/MySql/v2/helpers/utils.ts +++ b/packages/nodes-base/nodes/MySql/v2/helpers/utils.ts @@ -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);