mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(Merge Node): Option in combineBySql operation to return either confirmation of succes or empty result (#15509)
This commit is contained in:
@@ -17,6 +17,10 @@ import { getResolvables, updateDisplayOptions } from '@utils/utilities';
|
||||
import { numberInputsProperty } from '../../helpers/descriptions';
|
||||
import { modifySelectQuery, rowToExecutionData } from '../../helpers/utils';
|
||||
|
||||
type OperationOptions = {
|
||||
emptyQueryResult: 'success' | 'empty';
|
||||
};
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
numberInputsProperty,
|
||||
{
|
||||
@@ -33,6 +37,37 @@ export const properties: INodeProperties[] = [
|
||||
editor: 'sqlEditor',
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Empty Query Result',
|
||||
name: 'emptyQueryResult',
|
||||
type: 'options',
|
||||
description: 'What to return if the query executed successfully but returned no results',
|
||||
options: [
|
||||
{
|
||||
name: 'Success',
|
||||
value: 'success',
|
||||
},
|
||||
{
|
||||
name: 'Empty Result',
|
||||
value: 'empty',
|
||||
},
|
||||
],
|
||||
default: 'empty',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
'@version': [3.2],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
@@ -61,6 +96,7 @@ async function executeSelectWithMappedPairedItems(
|
||||
node: INode,
|
||||
inputsData: INodeExecutionData[][],
|
||||
query: string,
|
||||
returnSuccessItemIfEmpty: boolean,
|
||||
): Promise<INodeExecutionData[][]> {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
@@ -95,7 +131,7 @@ async function executeSelectWithMappedPairedItems(
|
||||
}
|
||||
}
|
||||
|
||||
if (!returnData.length) {
|
||||
if (!returnData.length && returnSuccessItemIfEmpty) {
|
||||
returnData.push({ json: { success: true } });
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -114,6 +150,7 @@ export async function execute(
|
||||
const node = this.getNode();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
const pairedItem: IPairedItemData[] = [];
|
||||
const options = this.getNodeParameter('options', 0, {}) as OperationOptions;
|
||||
|
||||
let query = this.getNodeParameter('query', 0) as string;
|
||||
|
||||
@@ -122,10 +159,17 @@ export async function execute(
|
||||
}
|
||||
|
||||
const isSelectQuery = node.typeVersion >= 3.1 ? query.toLowerCase().startsWith('select') : false;
|
||||
const returnSuccessItemIfEmpty =
|
||||
node.typeVersion <= 3.1 ? true : options.emptyQueryResult === 'success';
|
||||
|
||||
if (isSelectQuery) {
|
||||
try {
|
||||
return await executeSelectWithMappedPairedItems(node, inputsData, query);
|
||||
return await executeSelectWithMappedPairedItems(
|
||||
node,
|
||||
inputsData,
|
||||
query,
|
||||
returnSuccessItemIfEmpty,
|
||||
);
|
||||
} catch (error) {
|
||||
Container.get(ErrorReporter).error(error, {
|
||||
extra: {
|
||||
@@ -199,7 +243,7 @@ export async function execute(
|
||||
}
|
||||
}
|
||||
|
||||
if (!returnData.length) {
|
||||
if (!returnData.length && returnSuccessItemIfEmpty) {
|
||||
returnData.push({ json: { success: true }, pairedItem });
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -9,7 +9,7 @@ export const versionDescription: INodeTypeDescription = {
|
||||
name: 'merge',
|
||||
group: ['transform'],
|
||||
description: 'Merges data of multiple streams once data from both is available',
|
||||
version: [3, 3.1],
|
||||
version: [3, 3.1, 3.2],
|
||||
defaults: {
|
||||
name: 'Merge',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user