fix(MySQL Node): Query Parameters parse string to number (#9011)

This commit is contained in:
Michael Kret 2024-04-09 04:48:17 +03:00 committed by GitHub
parent 3dd70a17e2
commit 610ead9a38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 51 additions and 2 deletions

View file

@ -11,7 +11,7 @@ export class MySql extends VersionedNodeType {
name: 'mySql', name: 'mySql',
icon: 'file:mysql.svg', icon: 'file:mysql.svg',
group: ['input'], group: ['input'],
defaultVersion: 2.2, defaultVersion: 2.3,
description: 'Get, add and update data in MySQL', description: 'Get, add and update data in MySQL',
parameterPane: 'wide', parameterPane: 'wide',
}; };
@ -21,6 +21,7 @@ export class MySql extends VersionedNodeType {
2: new MySqlV2(baseDescription), 2: new MySqlV2(baseDescription),
2.1: new MySqlV2(baseDescription), 2.1: new MySqlV2(baseDescription),
2.2: new MySqlV2(baseDescription), 2.2: new MySqlV2(baseDescription),
2.3: new MySqlV2(baseDescription),
}; };
super(nodeVersions, baseDescription); super(nodeVersions, baseDescription);

View file

@ -254,6 +254,47 @@ describe('Test MySql V2, operations', () => {
); );
expect(connectionQuerySpy).toBeCalledWith('select * from `test_table`'); 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 () => { it('select, should call runQueries with', async () => {
const nodeParameters: IDataObject = { const nodeParameters: IDataObject = {

View file

@ -81,6 +81,13 @@ export async function execute(
const preparedQuery = prepareQueryAndReplacements(rawQuery, values); 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); queries.push(preparedQuery);
} }

View file

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