fix(Postgres Node): Expressions in query parameters for Postgres executeQuery operation (#10217)

This commit is contained in:
Shireen Missi 2024-07-31 08:39:37 +01:00 committed by GitHub
parent 7e643589c6
commit 519fc4d753
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 9 deletions

View file

@ -11,7 +11,7 @@ export class Postgres extends VersionedNodeType {
name: 'postgres',
icon: 'file:postgres.svg',
group: ['input'],
defaultVersion: 2.4,
defaultVersion: 2.5,
description: 'Get, add and update data in Postgres',
parameterPane: 'wide',
};
@ -23,6 +23,7 @@ export class Postgres extends VersionedNodeType {
2.2: new PostgresV2(baseDescription),
2.3: new PostgresV2(baseDescription),
2.4: new PostgresV2(baseDescription),
2.5: new PostgresV2(baseDescription),
};
super(nodeVersions, baseDescription);

View file

@ -3,6 +3,7 @@ import type {
IExecuteFunctions,
INodeExecutionData,
INodeProperties,
NodeParameterValueType,
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
@ -78,22 +79,45 @@ export async function execute(
const rawReplacements = (node.parameters.options as IDataObject)?.queryReplacement as string;
if (rawReplacements) {
const rawValues = rawReplacements
.replace(/^=+/, '')
const stringToArray = (str: NodeParameterValueType | undefined) => {
if (!str) return [];
return String(str)
.split(',')
.filter((entry) => entry)
.map((entry) => entry.trim());
};
for (const rawValue of rawValues) {
const resolvables = getResolvables(rawValue);
if (rawReplacements) {
const nodeVersion = nodeOptions.nodeVersion as number;
if (nodeVersion >= 2.5) {
const rawValues = rawReplacements.replace(/^=+/, '');
const resolvables = getResolvables(rawValues);
if (resolvables.length) {
for (const resolvable of resolvables) {
values.push(this.evaluateExpression(`${resolvable}`, i) as IDataObject);
const evaluatedValues = stringToArray(this.evaluateExpression(`${resolvable}`, i));
if (evaluatedValues.length) values.push(...evaluatedValues);
}
} else {
values.push(rawValue);
values.push(...stringToArray(rawValues));
}
} else {
const rawValues = rawReplacements
.replace(/^=+/, '')
.split(',')
.filter((entry) => entry)
.map((entry) => entry.trim());
for (const rawValue of rawValues) {
const resolvables = getResolvables(rawValue);
if (resolvables.length) {
for (const resolvable of resolvables) {
values.push(this.evaluateExpression(`${resolvable}`, i) as IDataObject);
}
} else {
values.push(rawValue);
}
}
}
}

View file

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