mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
fix(Postgres Node): Expressions in query parameters for Postgres executeQuery operation (#10217)
This commit is contained in:
parent
7e643589c6
commit
519fc4d753
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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: {
|
||||
|
|
Loading…
Reference in a new issue