Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(/^=+/, '')
ShireenMissi marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading