fix(Postgres Node): Remove reusable connections (no-changelog) (#6259)

This commit is contained in:
Michael Kret
2023-05-19 16:42:24 +03:00
committed by GitHub
parent 4b5cbe7750
commit be5d3264ad
7 changed files with 64 additions and 61 deletions

View File

@@ -1,5 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { IDataObject, INodeExecutionData, INodeProperties } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { updateDisplayOptions } from '../../../../../utils/utilities';
@@ -181,6 +182,13 @@ export async function execute(
valueToMatchOn = this.getNodeParameter('valueToMatchOn', i) as string;
}
if (!item[columnToMatchOn] && dataMode === 'autoMapInputData') {
throw new NodeOperationError(
this.getNode(),
"Column to match on not found in input item. Add a column to match on or set the 'Data Mode' to 'Define Below' to define the value to match on.",
);
}
const tableSchema = await getTableSchema(db, schema, table);
item = checkItemAgainstSchema(this.getNode(), item, tableSchema, i);
@@ -195,6 +203,13 @@ export async function execute(
const updateColumns = Object.keys(item).filter((column) => column !== columnToMatchOn);
if (!Object.keys(updateColumns).length) {
throw new NodeOperationError(
this.getNode(),
"Add values to update to the input item or set the 'Data Mode' to 'Define Below' to define the values to update.",
);
}
const updates: string[] = [];
for (const column of updateColumns) {

View File

@@ -1,5 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { IDataObject, INodeExecutionData, INodeProperties } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { updateDisplayOptions } from '../../../../../utils/utilities';
@@ -179,6 +180,20 @@ export async function execute(
item[columnToMatchOn] = this.getNodeParameter('valueToMatchOn', i) as string;
}
if (!item[columnToMatchOn]) {
throw new NodeOperationError(
this.getNode(),
"Column to match on not found in input item. Add a column to match on or set the 'Data Mode' to 'Define Below' to define the value to match on.",
);
}
if (item[columnToMatchOn] && Object.keys(item).length === 1) {
throw new NodeOperationError(
this.getNode(),
"Add values to update or insert to the input item or set the 'Data Mode' to 'Define Below' to define the values to insert or update.",
);
}
const tableSchema = await getTableSchema(db, schema, table);
item = checkItemAgainstSchema(this.getNode(), item, tableSchema, i);

View File

@@ -4,9 +4,8 @@ import { NodeOperationError } from 'n8n-workflow';
import type { PostgresType } from './node.type';
import * as database from './database/Database.resource';
import { Connections } from '../transport';
import { configurePostgres } from '../transport';
import { configureQueryRunner } from '../helpers/utils';
import type { ConnectionsData } from '../helpers/interfaces';
export async function router(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
let returnData: INodeExecutionData[] = [];
@@ -19,11 +18,7 @@ export async function router(this: IExecuteFunctions): Promise<INodeExecutionDat
const options = this.getNodeParameter('options', 0, {});
options.nodeVersion = this.getNode().typeVersion;
const { db, pgp, sshClient } = (await Connections.getInstance(
credentials,
options,
true,
)) as ConnectionsData;
const { db, pgp, sshClient } = await configurePostgres(credentials, options);
const runQueries = configureQueryRunner(
this.getNode(),