mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 21:37:32 -08:00
fix(Postgres Node): Fix for tables containing field named json
This commit is contained in:
parent
f58573dba3
commit
5d74a2f89a
|
@ -71,6 +71,15 @@ export function generateReturning(pgp: pgPromise.IMain<{}, pg.IClient>, returnin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function wrapData(data: IDataObject[]): INodeExecutionData[] {
|
||||||
|
if (!Array.isArray(data)) {
|
||||||
|
return [{ json: data }];
|
||||||
|
}
|
||||||
|
return data.map((item) => ({
|
||||||
|
json: item,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the given SQL query on the database.
|
* Executes the given SQL query on the database.
|
||||||
*
|
*
|
||||||
|
@ -185,7 +194,7 @@ export async function pgQueryV2(
|
||||||
if (mode === 'multiple') {
|
if (mode === 'multiple') {
|
||||||
return (await db.multi(pgp.helpers.concat(allQueries)))
|
return (await db.multi(pgp.helpers.concat(allQueries)))
|
||||||
.map((result, i) => {
|
.map((result, i) => {
|
||||||
return this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(result), {
|
return this.helpers.constructExecutionMetaData(wrapData(result), {
|
||||||
itemData: { item: i },
|
itemData: { item: i },
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -197,7 +206,7 @@ export async function pgQueryV2(
|
||||||
try {
|
try {
|
||||||
const transactionResult = await t.any(allQueries[i].query, allQueries[i].values);
|
const transactionResult = await t.any(allQueries[i].query, allQueries[i].values);
|
||||||
const executionData = this.helpers.constructExecutionMetaData(
|
const executionData = this.helpers.constructExecutionMetaData(
|
||||||
this.helpers.returnJsonArray(transactionResult),
|
wrapData(transactionResult),
|
||||||
{ itemData: { item: i } },
|
{ itemData: { item: i } },
|
||||||
);
|
);
|
||||||
result.push(...executionData);
|
result.push(...executionData);
|
||||||
|
@ -221,7 +230,7 @@ export async function pgQueryV2(
|
||||||
try {
|
try {
|
||||||
const transactionResult = await t.any(allQueries[i].query, allQueries[i].values);
|
const transactionResult = await t.any(allQueries[i].query, allQueries[i].values);
|
||||||
const executionData = this.helpers.constructExecutionMetaData(
|
const executionData = this.helpers.constructExecutionMetaData(
|
||||||
this.helpers.returnJsonArray(transactionResult),
|
wrapData(transactionResult),
|
||||||
{ itemData: { item: i } },
|
{ itemData: { item: i } },
|
||||||
);
|
);
|
||||||
result.push(...executionData);
|
result.push(...executionData);
|
||||||
|
@ -373,7 +382,7 @@ export async function pgInsertV2(
|
||||||
const queryResult = await db.any(query);
|
const queryResult = await db.any(query);
|
||||||
return queryResult
|
return queryResult
|
||||||
.map((result, i) => {
|
.map((result, i) => {
|
||||||
return this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(result), {
|
return this.helpers.constructExecutionMetaData(wrapData(result), {
|
||||||
itemData: { item: i },
|
itemData: { item: i },
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -386,7 +395,7 @@ export async function pgInsertV2(
|
||||||
try {
|
try {
|
||||||
const insertResult = await t.one(pgp.helpers.insert(itemCopy, cs) + returning);
|
const insertResult = await t.one(pgp.helpers.insert(itemCopy, cs) + returning);
|
||||||
result.push(
|
result.push(
|
||||||
...this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(insertResult), {
|
...this.helpers.constructExecutionMetaData(wrapData(insertResult), {
|
||||||
itemData: { item: i },
|
itemData: { item: i },
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -411,10 +420,9 @@ export async function pgInsertV2(
|
||||||
try {
|
try {
|
||||||
const insertResult = await t.oneOrNone(pgp.helpers.insert(itemCopy, cs) + returning);
|
const insertResult = await t.oneOrNone(pgp.helpers.insert(itemCopy, cs) + returning);
|
||||||
if (insertResult !== null) {
|
if (insertResult !== null) {
|
||||||
const executionData = this.helpers.constructExecutionMetaData(
|
const executionData = this.helpers.constructExecutionMetaData(wrapData(insertResult), {
|
||||||
this.helpers.returnJsonArray(insertResult),
|
itemData: { item: i },
|
||||||
{ itemData: { item: i } },
|
});
|
||||||
);
|
|
||||||
result.push(...executionData);
|
result.push(...executionData);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -644,7 +652,7 @@ export async function pgUpdateV2(
|
||||||
returning,
|
returning,
|
||||||
);
|
);
|
||||||
const executionData = this.helpers.constructExecutionMetaData(
|
const executionData = this.helpers.constructExecutionMetaData(
|
||||||
this.helpers.returnJsonArray(transactionResult),
|
wrapData(transactionResult),
|
||||||
{ itemData: { item: i } },
|
{ itemData: { item: i } },
|
||||||
);
|
);
|
||||||
result.push(...executionData);
|
result.push(...executionData);
|
||||||
|
@ -672,7 +680,7 @@ export async function pgUpdateV2(
|
||||||
returning,
|
returning,
|
||||||
);
|
);
|
||||||
const executionData = this.helpers.constructExecutionMetaData(
|
const executionData = this.helpers.constructExecutionMetaData(
|
||||||
this.helpers.returnJsonArray(independentResult),
|
wrapData(independentResult),
|
||||||
{ itemData: { item: i } },
|
{ itemData: { item: i } },
|
||||||
);
|
);
|
||||||
result.push(...executionData);
|
result.push(...executionData);
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { NodeOperationError } from 'n8n-workflow';
|
||||||
|
|
||||||
import pgPromise from 'pg-promise';
|
import pgPromise from 'pg-promise';
|
||||||
|
|
||||||
import { pgInsertV2, pgQueryV2, pgUpdate } from './Postgres.node.functions';
|
import { pgInsertV2, pgQueryV2, pgUpdate, wrapData } from './Postgres.node.functions';
|
||||||
|
|
||||||
export class Postgres implements INodeType {
|
export class Postgres implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -389,7 +389,7 @@ export class Postgres implements INodeType {
|
||||||
this.continueOnFail(),
|
this.continueOnFail(),
|
||||||
);
|
);
|
||||||
|
|
||||||
returnItems = this.helpers.returnJsonArray(updateItems);
|
returnItems = wrapData(updateItems);
|
||||||
} else {
|
} else {
|
||||||
pgp.end();
|
pgp.end();
|
||||||
throw new NodeOperationError(
|
throw new NodeOperationError(
|
||||||
|
|
Loading…
Reference in a new issue