Skip to content

Commit

Permalink
fix(Postgres Node): Expressions in query parameters for Postgres exec…
Browse files Browse the repository at this point in the history
…uteQuery operation (#10217)
  • Loading branch information
ShireenMissi committed Jul 31, 2024
1 parent 7e64358 commit 519fc4d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/nodes-base/nodes/Postgres/Postgres.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
IExecuteFunctions,
INodeExecutionData,
INodeProperties,
NodeParameterValueType,
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';

Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 519fc4d

Please sign in to comment.