mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
⚡ Fixed return values from CrateDB update function
This commit is contained in:
parent
7f43faceb0
commit
6a8d22d2fa
|
@ -3,7 +3,7 @@ import { IDataObject, INodeExecutionData, INodeType, INodeTypeDescription } from
|
||||||
|
|
||||||
import * as pgPromise from 'pg-promise';
|
import * as pgPromise from 'pg-promise';
|
||||||
|
|
||||||
import { pgInsert, pgQuery, pgUpdate } from '../Postgres/Postgres.node.functions';
|
import { pgInsert, pgQuery, pgUpdate, getItemCopy } from '../Postgres/Postgres.node.functions';
|
||||||
|
|
||||||
export class CrateDb implements INodeType {
|
export class CrateDb implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -233,6 +233,7 @@ export class CrateDb implements INodeType {
|
||||||
const updateKey = this.getNodeParameter('updateKey', 0) as string;
|
const updateKey = this.getNodeParameter('updateKey', 0) as string;
|
||||||
|
|
||||||
const queries : string[] = [];
|
const queries : string[] = [];
|
||||||
|
const updatedKeys : string[] = [];
|
||||||
let updateKeyValue : string | number;
|
let updateKeyValue : string | number;
|
||||||
let columns : string[] = [];
|
let columns : string[] = [];
|
||||||
|
|
||||||
|
@ -255,15 +256,16 @@ export class CrateDb implements INodeType {
|
||||||
throw new Error('No value found for update key!');
|
throw new Error('No value found for update key!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatedKeys.push(updateKeyValue as string);
|
||||||
|
|
||||||
const query = `UPDATE "${tableName}" SET ${setOperations.join(',')} WHERE ${updateKey} = ${updateKeyValue};`;
|
const query = `UPDATE "${tableName}" SET ${setOperations.join(',')} WHERE ${updateKey} = ${updateKeyValue};`;
|
||||||
queries.push(query);
|
queries.push(query);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
await db.any(pgp.helpers.concat(queries));
|
await db.any(pgp.helpers.concat(queries));
|
||||||
|
|
||||||
const returnedItems = await db.any(`SELECT ${columns.join(',')} from ${tableName}`);
|
returnItems = this.helpers.returnJsonArray(getItemCopy(items, columns) as IDataObject[]);
|
||||||
|
|
||||||
returnItems = this.helpers.returnJsonArray(returnedItems as IDataObject[]);
|
|
||||||
} else {
|
} else {
|
||||||
await pgp.end();
|
await pgp.end();
|
||||||
throw new Error(`The operation "${operation}" is not supported!`);
|
throw new Error(`The operation "${operation}" is not supported!`);
|
||||||
|
|
|
@ -10,7 +10,7 @@ import pg = require('pg-promise/typescript/pg-subset');
|
||||||
* @param {string[]} properties The properties it should include
|
* @param {string[]} properties The properties it should include
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function getItemCopy(items: INodeExecutionData[], properties: string[]): IDataObject[] {
|
export function getItemCopy(items: INodeExecutionData[], properties: string[]): IDataObject[] {
|
||||||
// Prepare the data to insert and copy it to be returned
|
// Prepare the data to insert and copy it to be returned
|
||||||
let newItem: IDataObject;
|
let newItem: IDataObject;
|
||||||
return items.map(item => {
|
return items.map(item => {
|
||||||
|
|
Loading…
Reference in a new issue