mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
feat(Data Table Node): Add Data Table Node (no-changelog) (#18556)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import type {
|
||||
IDisplayOptions,
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { COLUMNS } from '../../common/fields';
|
||||
import { dataObjectToApiInput, getDataTableProxyExecute } from '../../common/utils';
|
||||
|
||||
export const FIELD: string = 'insert';
|
||||
|
||||
const displayOptions: IDisplayOptions = {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
operation: [FIELD],
|
||||
},
|
||||
};
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
...COLUMNS,
|
||||
displayOptions,
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const items = this.getInputData();
|
||||
|
||||
const dataStoreProxy = await getDataTableProxyExecute(this, index);
|
||||
const dataMode = this.getNodeParameter('columns.mappingMode', index) as string;
|
||||
|
||||
let data: IDataObject;
|
||||
|
||||
if (dataMode === 'autoMapInputData') {
|
||||
data = items[index].json;
|
||||
} else {
|
||||
const fields = this.getNodeParameter('columns.value', index, {}) as IDataObject;
|
||||
|
||||
data = fields;
|
||||
}
|
||||
|
||||
const rows = dataObjectToApiInput(data, this.getNode(), index);
|
||||
|
||||
const insertedRowIds = await dataStoreProxy.insertRows([rows]);
|
||||
return insertedRowIds.map((x) => ({ json: { id: x } }));
|
||||
}
|
||||
Reference in New Issue
Block a user