Add Schema to Postgres-Update #996

This commit is contained in:
Jan Oberhauser 2020-09-29 21:57:22 +02:00
parent 3350723bf3
commit 6f576b3da9
2 changed files with 17 additions and 1 deletions

View file

@ -105,11 +105,14 @@ export async function pgUpdate(
items: INodeExecutionData[], items: INodeExecutionData[],
): Promise<IDataObject[]> { ): Promise<IDataObject[]> {
const table = getNodeParam('table', 0) as string; const table = getNodeParam('table', 0) as string;
const schema = getNodeParam('schema', 0) as string;
const updateKey = getNodeParam('updateKey', 0) as string; const updateKey = getNodeParam('updateKey', 0) as string;
const columnString = getNodeParam('columns', 0) as string; const columnString = getNodeParam('columns', 0) as string;
const columns = columnString.split(',').map(column => column.trim()); const columns = columnString.split(',').map(column => column.trim());
const te = new pgp.helpers.TableName({ table, schema });
// Make sure that the updateKey does also get queried // Make sure that the updateKey does also get queried
if (!columns.includes(updateKey)) { if (!columns.includes(updateKey)) {
columns.unshift(updateKey); columns.unshift(updateKey);
@ -120,7 +123,7 @@ export async function pgUpdate(
// Generate the multi-row update query // Generate the multi-row update query
const query = const query =
pgp.helpers.update(updateItems, columns, table) + ' WHERE v.' + updateKey + ' = t.' + updateKey; pgp.helpers.update(updateItems, columns, te) + ' WHERE v.' + updateKey + ' = t.' + updateKey;
// Executing the query to update the data // Executing the query to update the data
await db.none(query); await db.none(query);

View file

@ -136,6 +136,19 @@ export class Postgres implements INodeType {
// ---------------------------------- // ----------------------------------
// update // update
// ---------------------------------- // ----------------------------------
{
displayName: 'Schema',
name: 'schema',
type: 'string',
displayOptions: {
show: {
operation: ['update'],
},
},
default: 'public',
required: true,
description: 'Name of the schema the table belongs to',
},
{ {
displayName: 'Table', displayName: 'Table',
name: 'table', name: 'table',