Fixed return values from CrateDB update function

This commit is contained in:
Rupenieks 2020-08-02 20:23:53 +01:00
parent 7f43faceb0
commit 6a8d22d2fa
2 changed files with 8 additions and 6 deletions

View file

@ -3,7 +3,7 @@ import { IDataObject, INodeExecutionData, INodeType, INodeTypeDescription } from
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 {
description: INodeTypeDescription = {
@ -233,6 +233,7 @@ export class CrateDb implements INodeType {
const updateKey = this.getNodeParameter('updateKey', 0) as string;
const queries : string[] = [];
const updatedKeys : string[] = [];
let updateKeyValue : string | number;
let columns : string[] = [];
@ -255,15 +256,16 @@ export class CrateDb implements INodeType {
throw new Error('No value found for update key!');
}
updatedKeys.push(updateKeyValue as string);
const query = `UPDATE "${tableName}" SET ${setOperations.join(',')} WHERE ${updateKey} = ${updateKeyValue};`;
queries.push(query);
});
await db.any(pgp.helpers.concat(queries));
const returnedItems = await db.any(`SELECT ${columns.join(',')} from ${tableName}`);
returnItems = this.helpers.returnJsonArray(returnedItems as IDataObject[]);
returnItems = this.helpers.returnJsonArray(getItemCopy(items, columns) as IDataObject[]);
} else {
await pgp.end();
throw new Error(`The operation "${operation}" is not supported!`);

View file

@ -10,7 +10,7 @@ import pg = require('pg-promise/typescript/pg-subset');
* @param {string[]} properties The properties it should include
* @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
let newItem: IDataObject;
return items.map(item => {