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',
|
name: 'postgres',
|
||||||
icon: 'file:postgres.svg',
|
icon: 'file:postgres.svg',
|
||||||
group: ['input'],
|
group: ['input'],
|
||||||
defaultVersion: 2.4,
|
defaultVersion: 2.5,
|
||||||
description: 'Get, add and update data in Postgres',
|
description: 'Get, add and update data in Postgres',
|
||||||
parameterPane: 'wide',
|
parameterPane: 'wide',
|
||||||
};
|
};
|
||||||
|
@ -23,6 +23,7 @@ export class Postgres extends VersionedNodeType {
|
||||||
2.2: new PostgresV2(baseDescription),
|
2.2: new PostgresV2(baseDescription),
|
||||||
2.3: new PostgresV2(baseDescription),
|
2.3: new PostgresV2(baseDescription),
|
||||||
2.4: new PostgresV2(baseDescription),
|
2.4: new PostgresV2(baseDescription),
|
||||||
|
2.5: new PostgresV2(baseDescription),
|
||||||
};
|
};
|
||||||
|
|
||||||
super(nodeVersions, baseDescription);
|
super(nodeVersions, baseDescription);
|
||||||
|
|
|
@ -3,6 +3,7 @@ import type {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
|
NodeParameterValueType,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { NodeOperationError } 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;
|
const rawReplacements = (node.parameters.options as IDataObject)?.queryReplacement as string;
|
||||||
|
|
||||||
if (rawReplacements) {
|
const stringToArray = (str: NodeParameterValueType | undefined) => {
|
||||||
const rawValues = rawReplacements
|
if (!str) return [];
|
||||||
.replace(/^=+/, '')
|
return String(str)
|
||||||
.split(',')
|
.split(',')
|
||||||
.filter((entry) => entry)
|
.filter((entry) => entry)
|
||||||
.map((entry) => entry.trim());
|
.map((entry) => entry.trim());
|
||||||
|
};
|
||||||
|
|
||||||
for (const rawValue of rawValues) {
|
if (rawReplacements) {
|
||||||
const resolvables = getResolvables(rawValue);
|
const nodeVersion = nodeOptions.nodeVersion as number;
|
||||||
|
|
||||||
|
if (nodeVersion >= 2.5) {
|
||||||
|
const rawValues = rawReplacements.replace(/^=+/, '');
|
||||||
|
const resolvables = getResolvables(rawValues);
|
||||||
if (resolvables.length) {
|
if (resolvables.length) {
|
||||||
for (const resolvable of resolvables) {
|
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 {
|
} 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',
|
name: 'postgres',
|
||||||
icon: 'file:postgres.svg',
|
icon: 'file:postgres.svg',
|
||||||
group: ['input'],
|
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"] }}',
|
subtitle: '={{ $parameter["operation"] }}',
|
||||||
description: 'Get, add and update data in Postgres',
|
description: 'Get, add and update data in Postgres',
|
||||||
defaults: {
|
defaults: {
|
||||||
|
|
Loading…
Reference in a new issue