mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Add Schema to Postgres-Update #996
This commit is contained in:
parent
3350723bf3
commit
6f576b3da9
|
@ -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);
|
||||||
|
|
|
@ -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',
|
||||||
|
|
Loading…
Reference in a new issue