mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 20:00:02 +00:00
feat(Data Table Node): Add Update, Upsert operations (no-changelog) (#18820)
This commit is contained in:
55
packages/nodes-base/nodes/DataTable/common/addRow.ts
Normal file
55
packages/nodes-base/nodes/DataTable/common/addRow.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
IDisplayOptions,
|
||||
IExecuteFunctions,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { DATA_TABLE_ID_FIELD } from './fields';
|
||||
import { dataObjectToApiInput } from './utils';
|
||||
|
||||
export function makeAddRow(operation: string, displayOptions: IDisplayOptions) {
|
||||
return {
|
||||
displayName: 'Columns',
|
||||
name: 'columns',
|
||||
type: 'resourceMapper',
|
||||
default: {
|
||||
mappingMode: 'defineBelow',
|
||||
value: null,
|
||||
},
|
||||
noDataExpression: true,
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: [`${DATA_TABLE_ID_FIELD}.value`],
|
||||
resourceMapper: {
|
||||
valuesLabel: `Columns to ${operation}`,
|
||||
resourceMapperMethod: 'getDataTables',
|
||||
mode: 'add',
|
||||
fieldWords: {
|
||||
singular: 'column',
|
||||
plural: 'columns',
|
||||
},
|
||||
addAllFields: true,
|
||||
multiKeyMatch: true,
|
||||
},
|
||||
},
|
||||
displayOptions,
|
||||
} satisfies INodeProperties;
|
||||
}
|
||||
|
||||
export function getAddRow(ctx: IExecuteFunctions, index: number) {
|
||||
const items = ctx.getInputData();
|
||||
const dataMode = ctx.getNodeParameter('columns.mappingMode', index) as string;
|
||||
|
||||
let data: IDataObject;
|
||||
|
||||
if (dataMode === 'autoMapInputData') {
|
||||
data = items[index].json;
|
||||
} else {
|
||||
const fields = ctx.getNodeParameter('columns.value', index, {}) as IDataObject;
|
||||
|
||||
data = fields;
|
||||
}
|
||||
|
||||
return dataObjectToApiInput(data, ctx.getNode(), index);
|
||||
}
|
||||
@@ -2,36 +2,11 @@ import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const DATA_TABLE_ID_FIELD = 'dataTableId';
|
||||
|
||||
export const COLUMNS = {
|
||||
displayName: 'Columns',
|
||||
name: 'columns',
|
||||
type: 'resourceMapper',
|
||||
default: {
|
||||
mappingMode: 'defineBelow',
|
||||
value: null,
|
||||
},
|
||||
noDataExpression: true,
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: [`${DATA_TABLE_ID_FIELD}.value`],
|
||||
resourceMapper: {
|
||||
resourceMapperMethod: 'getDataTables',
|
||||
mode: 'add',
|
||||
fieldWords: {
|
||||
singular: 'column',
|
||||
plural: 'columns',
|
||||
},
|
||||
addAllFields: true,
|
||||
multiKeyMatch: true,
|
||||
},
|
||||
},
|
||||
} satisfies INodeProperties;
|
||||
|
||||
export const DRY_RUN = {
|
||||
displayName: 'Dry Run',
|
||||
name: 'dryRun',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether the delete operation should only be simulated, returning the rows that would have been deleted',
|
||||
'Whether the operation should only be simulated, returning the rows that would have been affected',
|
||||
} satisfies INodeProperties;
|
||||
|
||||
@@ -11,7 +11,10 @@ import type { FilterType } from './constants';
|
||||
import { DATA_TABLE_ID_FIELD } from './fields';
|
||||
import { buildGetManyFilter, isFieldArray, isMatchType } from './utils';
|
||||
|
||||
export function getSelectFields(displayOptions: IDisplayOptions): INodeProperties[] {
|
||||
export function getSelectFields(
|
||||
displayOptions: IDisplayOptions,
|
||||
requireCondition = false,
|
||||
): INodeProperties[] {
|
||||
return [
|
||||
{
|
||||
displayName: 'Must Match',
|
||||
@@ -36,6 +39,7 @@ export function getSelectFields(displayOptions: IDisplayOptions): INodePropertie
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
minRequiredFields: requireCondition ? 1 : 0,
|
||||
},
|
||||
displayOptions,
|
||||
default: {},
|
||||
@@ -105,9 +109,14 @@ export async function executeSelectMany(
|
||||
ctx: IExecuteFunctions,
|
||||
index: number,
|
||||
dataStoreProxy: IDataStoreProjectService,
|
||||
rejectEmpty = false,
|
||||
): Promise<Array<{ json: DataStoreRowReturn }>> {
|
||||
const filter = getSelectFilter(ctx, index);
|
||||
|
||||
if (rejectEmpty && filter.filters.length === 0) {
|
||||
throw new NodeOperationError(ctx.getNode(), 'At least one condition is required');
|
||||
}
|
||||
|
||||
let take = 1000;
|
||||
const result: Array<{ json: DataStoreRowReturn }> = [];
|
||||
let totalCount = undefined;
|
||||
|
||||
Reference in New Issue
Block a user