mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-13 16:14:07 -08:00
fix(MySQL Node): Query Parameters parse string to number (#9011)
This commit is contained in:
parent
3dd70a17e2
commit
610ead9a38
|
@ -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);
|
||||||
|
|
|
@ -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 = {
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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: {
|
||||||
|
|
Loading…
Reference in a new issue