Skip to content

Commit

Permalink
fix(MySQL Node): Query Parameters parse string to number (#9011)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency authored Apr 9, 2024
1 parent 3dd70a1 commit 610ead9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/nodes-base/nodes/MySql/MySql.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class MySql extends VersionedNodeType {
name: 'mySql',
icon: 'file:mysql.svg',
group: ['input'],
defaultVersion: 2.2,
defaultVersion: 2.3,
description: 'Get, add and update data in MySQL',
parameterPane: 'wide',
};
Expand All @@ -21,6 +21,7 @@ export class MySql extends VersionedNodeType {
2: new MySqlV2(baseDescription),
2.1: new MySqlV2(baseDescription),
2.2: new MySqlV2(baseDescription),
2.3: new MySqlV2(baseDescription),
};

super(nodeVersions, baseDescription);
Expand Down
41 changes: 41 additions & 0 deletions packages/nodes-base/nodes/MySql/test/v2/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,47 @@ describe('Test MySql V2, operations', () => {
);
expect(connectionQuerySpy).toBeCalledWith('select * from `test_table`');
});
it('executeQuery, should parse numbers', async () => {
const nodeParameters: IDataObject = {
operation: 'executeQuery',
query: 'SELECT * FROM users LIMIT $1, $2',
options: {
queryBatching: 'independently',
queryReplacement: '2, 5',
nodeVersion: 2.3,
},
};

const nodeOptions = nodeParameters.options as IDataObject;

const fakeConnectionCopy = { ...fakeConnection };

fakeConnectionCopy.query = jest.fn(async (query?: string) => {
return [{ query }];
});
const pool = createFakePool(fakeConnectionCopy);

const connectionQuerySpy = jest.spyOn(fakeConnectionCopy, 'query');

const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, mySqlMockNode);

const runQueries: QueryRunner = configureQueryRunner.call(
fakeExecuteFunction,
nodeOptions,
pool,
);

const result = await executeQuery.execute.call(
fakeExecuteFunction,
emptyInputItems,
runQueries,
nodeOptions,
);

expect(result).toBeDefined();

expect(connectionQuerySpy).toBeCalledWith('SELECT * FROM users LIMIT 2, 5');
});

it('select, should call runQueries with', async () => {
const nodeParameters: IDataObject = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ export async function execute(

const preparedQuery = prepareQueryAndReplacements(rawQuery, values);

if ((nodeOptions.nodeVersion as number) >= 2.3) {
const parsedNumbers = preparedQuery.values.map((value) => {
return Number(value) ? Number(value) : value;
});
preparedQuery.values = parsedNumbers;
}

queries.push(preparedQuery);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const versionDescription: INodeTypeDescription = {
name: 'mySql',
icon: 'file:mysql.svg',
group: ['input'],
version: [2, 2.1, 2.2],
version: [2, 2.1, 2.2, 2.3],
subtitle: '={{ $parameter["operation"] }}',
description: 'Get, add and update data in MySQL',
defaults: {
Expand Down

0 comments on commit 610ead9

Please sign in to comment.