Small improvement to Postgres-Node

This commit is contained in:
Jan Oberhauser 2020-03-18 09:26:40 +01:00
parent d2a280d7b2
commit 0d5723f50a

View file

@ -269,7 +269,7 @@ export class Postgres implements INodeType {
const table = this.getNodeParameter('table', 0) as string;
const schema = this.getNodeParameter('schema', 0) as string;
const returnFields = (this.getNodeParameter('returnFields', 0) as string).split(',') as string[];
let returnFields = (this.getNodeParameter('returnFields', 0) as string).split(',') as string[];
const columnString = this.getNodeParameter('columns', 0) as string;
const columns = columnString.split(',').map(column => column.trim());
@ -281,7 +281,8 @@ export class Postgres implements INodeType {
const insertItems = getItemCopy(items, columns);
// Generate the multi-row insert query and return the id of new row
const query = pgp.helpers.insert(insertItems, cs, te) + ((returnFields[0] !== '') ? ` RETURNING ${returnFields.join(',')}` : '');
returnFields = returnFields.map(value => value.trim()).filter(value => !!value);
const query = pgp.helpers.insert(insertItems, cs, te) + (returnFields.length ? ` RETURNING ${returnFields.join(',')}` : '');
// Executing the query to insert the data
const insertData = await db.manyOrNone(query);