first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as deleteRows from './delete.operation';
|
||||
import * as rowExists from './rowExists.operation';
|
||||
import * as rowNotExists from './rowNotExists.operation';
|
||||
import * as get from './get.operation';
|
||||
import * as insert from './insert.operation';
|
||||
import * as update from './update.operation';
|
||||
import * as upsert from './upsert.operation';
|
||||
import { DATA_TABLE_RESOURCE_LOCATOR_BASE } from '../../common/fields';
|
||||
|
||||
export { insert, get, rowExists, rowNotExists, deleteRows, update, upsert };
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Delete',
|
||||
value: deleteRows.FIELD,
|
||||
description: 'Delete row(s)',
|
||||
action: 'Delete row(s)',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: get.FIELD,
|
||||
description: 'Get row(s)',
|
||||
action: 'Get row(s)',
|
||||
},
|
||||
{
|
||||
name: 'If Row Exists',
|
||||
value: rowExists.FIELD,
|
||||
description: 'Match input items that are in the data table',
|
||||
action: 'If row exists',
|
||||
},
|
||||
{
|
||||
name: 'If Row Does Not Exist',
|
||||
value: rowNotExists.FIELD,
|
||||
description: 'Match input items that are not in the data table',
|
||||
action: 'If row does not exist',
|
||||
},
|
||||
{
|
||||
name: 'Insert',
|
||||
value: insert.FIELD,
|
||||
description: 'Insert a new row',
|
||||
action: 'Insert row',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: update.FIELD,
|
||||
description: 'Update row(s) matching certain fields',
|
||||
action: 'Update row(s)',
|
||||
},
|
||||
{
|
||||
name: 'Upsert',
|
||||
value: upsert.FIELD,
|
||||
description: 'Update row(s), or insert if there is no match',
|
||||
action: 'Upsert row(s)',
|
||||
},
|
||||
],
|
||||
default: 'insert',
|
||||
},
|
||||
{
|
||||
...DATA_TABLE_RESOURCE_LOCATOR_BASE,
|
||||
modes: [
|
||||
{
|
||||
...DATA_TABLE_RESOURCE_LOCATOR_BASE.modes[0],
|
||||
typeOptions: {
|
||||
...DATA_TABLE_RESOURCE_LOCATOR_BASE.modes[0].typeOptions,
|
||||
allowNewResource: {
|
||||
label: 'resourceLocator.dataTable.createNew',
|
||||
url: '/projects/{{$projectId}}/datatables/new',
|
||||
},
|
||||
},
|
||||
},
|
||||
...DATA_TABLE_RESOURCE_LOCATOR_BASE.modes.slice(1),
|
||||
],
|
||||
displayOptions: { show: { resource: ['row'] } },
|
||||
},
|
||||
...deleteRows.description,
|
||||
...insert.description,
|
||||
...get.description,
|
||||
...rowExists.description,
|
||||
...rowNotExists.description,
|
||||
...update.description,
|
||||
...upsert.description,
|
||||
];
|
||||
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
NodeOperationError,
|
||||
type IDisplayOptions,
|
||||
type IExecuteFunctions,
|
||||
type INodeExecutionData,
|
||||
type INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { DRY_RUN } from '../../common/fields';
|
||||
import { getSelectFields, getSelectFilter } from '../../common/selectMany';
|
||||
import { getDataTableProxyExecute, getDryRunParameter } from '../../common/utils';
|
||||
|
||||
// named `deleteRows` since `delete` is a reserved keyword
|
||||
export const FIELD: string = 'deleteRows';
|
||||
|
||||
const displayOptions: IDisplayOptions = {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
operation: [FIELD],
|
||||
},
|
||||
};
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
...getSelectFields(displayOptions),
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
placeholder: 'Add option',
|
||||
options: [DRY_RUN],
|
||||
displayOptions,
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const dataTableProxy = await getDataTableProxyExecute(this, index);
|
||||
const dryRun = getDryRunParameter(this, index);
|
||||
const filter = await getSelectFilter(this, index);
|
||||
|
||||
if (filter.filters.length === 0) {
|
||||
throw new NodeOperationError(this.getNode(), 'At least one condition is required');
|
||||
}
|
||||
|
||||
const result = await dataTableProxy.deleteRows({ filter, dryRun });
|
||||
|
||||
return result.map((json) => ({ json }));
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
import type {
|
||||
IDisplayOptions,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { ROWS_LIMIT_DEFAULT } from '../../common/constants';
|
||||
import { executeSelectMany, getSelectFields } from '../../common/selectMany';
|
||||
import { getDataTableProxyExecute } from '../../common/utils';
|
||||
|
||||
export const FIELD: string = 'get';
|
||||
|
||||
const displayOptions: IDisplayOptions = {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
operation: [FIELD],
|
||||
},
|
||||
};
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
...getSelectFields(displayOptions),
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions,
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
...displayOptions,
|
||||
show: {
|
||||
...displayOptions.show,
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
default: ROWS_LIMIT_DEFAULT,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
{
|
||||
displayName: 'Order By',
|
||||
name: 'orderBy',
|
||||
type: 'boolean',
|
||||
displayOptions,
|
||||
default: false,
|
||||
description: 'Whether to sort the results by a column',
|
||||
},
|
||||
{
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
|
||||
displayName: 'Order By Column',
|
||||
name: 'orderByColumn',
|
||||
type: 'options',
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-options
|
||||
description:
|
||||
'Choose from the list, or specify using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['dataTableId.value'],
|
||||
loadOptionsMethod: 'getDataTableColumns',
|
||||
},
|
||||
displayOptions: {
|
||||
...displayOptions,
|
||||
show: {
|
||||
...displayOptions.show,
|
||||
orderBy: [true],
|
||||
},
|
||||
},
|
||||
default: 'createdAt',
|
||||
},
|
||||
{
|
||||
displayName: 'Order By Direction',
|
||||
name: 'orderByDirection',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Ascending',
|
||||
value: 'ASC',
|
||||
},
|
||||
{
|
||||
name: 'Descending',
|
||||
value: 'DESC',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
...displayOptions,
|
||||
show: {
|
||||
...displayOptions.show,
|
||||
orderBy: [true],
|
||||
},
|
||||
},
|
||||
default: 'DESC',
|
||||
description: 'Sort direction for the column',
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const dataTableProxy = await getDataTableProxyExecute(this, index);
|
||||
|
||||
// Extract sort parameters
|
||||
let sortBy: [string, 'ASC' | 'DESC'] | undefined;
|
||||
const orderBy = this.getNodeParameter('orderBy', index, false) as boolean;
|
||||
|
||||
if (orderBy) {
|
||||
const column = this.getNodeParameter('orderByColumn', index, '') as string;
|
||||
const direction = this.getNodeParameter('orderByDirection', index, 'ASC') as 'ASC' | 'DESC';
|
||||
if (column) {
|
||||
sortBy = [column, direction];
|
||||
}
|
||||
}
|
||||
|
||||
return await executeSelectMany(this, index, dataTableProxy, false, undefined, sortBy);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import type {
|
||||
IDataTableProjectService,
|
||||
IDisplayOptions,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { getAddRow, makeAddRow } from '../../common/addRow';
|
||||
import { getDataTableProxyExecute } from '../../common/utils';
|
||||
|
||||
export const FIELD: string = 'insert';
|
||||
|
||||
const displayOptions: IDisplayOptions = {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
operation: [FIELD],
|
||||
},
|
||||
};
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
makeAddRow(FIELD, displayOptions),
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Optimize Bulk',
|
||||
name: 'optimizeBulk',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
noDataExpression: true, // bulk inserts don't support expressions so this is a bit paradoxical
|
||||
description: 'Whether to improve bulk insert performance 5x by not returning inserted data',
|
||||
},
|
||||
],
|
||||
displayOptions,
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const optimizeBulkEnabled = this.getNodeParameter('options.optimizeBulk', index, false);
|
||||
const dataTableProxy = await getDataTableProxyExecute(this, index);
|
||||
|
||||
const row = getAddRow(this, index);
|
||||
|
||||
if (optimizeBulkEnabled) {
|
||||
// This function is always called by index, so we inherently cannot operate in bulk
|
||||
this.addExecutionHints({
|
||||
message: 'Unable to optimize bulk insert due to expression in Data table ID ',
|
||||
location: 'outputPane',
|
||||
});
|
||||
const json = await dataTableProxy.insertRows([row], 'count');
|
||||
return [{ json }];
|
||||
} else {
|
||||
const insertedRows = await dataTableProxy.insertRows([row], 'all');
|
||||
return insertedRows.map((json, item) => ({ json, pairedItem: { item } }));
|
||||
}
|
||||
}
|
||||
|
||||
export async function executeBulk(
|
||||
this: IExecuteFunctions,
|
||||
proxy: IDataTableProjectService,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const optimizeBulkEnabled = this.getNodeParameter('options.optimizeBulk', 0, false);
|
||||
const rows = this.getInputData().flatMap((_, i) => [getAddRow(this, i)]);
|
||||
|
||||
if (optimizeBulkEnabled) {
|
||||
const json = await proxy.insertRows(rows, 'count');
|
||||
return [{ json }];
|
||||
} else {
|
||||
const insertedRows = await proxy.insertRows(rows, 'all');
|
||||
return insertedRows.map((json, item) => ({ json, pairedItem: { item } }));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import type {
|
||||
IDisplayOptions,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { executeSelectMany, getSelectFields } from '../../common/selectMany';
|
||||
import { getDataTableProxyExecute } from '../../common/utils';
|
||||
|
||||
export const FIELD: string = 'rowExists';
|
||||
|
||||
const displayOptions: IDisplayOptions = {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
operation: [FIELD],
|
||||
},
|
||||
};
|
||||
|
||||
export const description: INodeProperties[] = [...getSelectFields(displayOptions, true, true)];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const dataTableProxy = await getDataTableProxyExecute(this, index);
|
||||
const hits = await executeSelectMany(this, index, dataTableProxy, undefined, 1);
|
||||
return hits.length > 0 ? [this.getInputData()[index]] : [];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import type {
|
||||
IDisplayOptions,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { executeSelectMany, getSelectFields } from '../../common/selectMany';
|
||||
import { getDataTableProxyExecute } from '../../common/utils';
|
||||
|
||||
export const FIELD: string = 'rowNotExists';
|
||||
|
||||
const displayOptions: IDisplayOptions = {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
operation: [FIELD],
|
||||
},
|
||||
};
|
||||
|
||||
export const description: INodeProperties[] = [...getSelectFields(displayOptions, true, true)];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const dataTableProxy = await getDataTableProxyExecute(this, index);
|
||||
const hits = await executeSelectMany(this, index, dataTableProxy, undefined, 1);
|
||||
return hits.length === 0 ? [this.getInputData()[index]] : [];
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import {
|
||||
NodeOperationError,
|
||||
type IDisplayOptions,
|
||||
type IExecuteFunctions,
|
||||
type INodeExecutionData,
|
||||
type INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { makeAddRow, getAddRow } from '../../common/addRow';
|
||||
import { DRY_RUN } from '../../common/fields';
|
||||
import { getSelectFields, getSelectFilter } from '../../common/selectMany';
|
||||
import { getDataTableProxyExecute, getDryRunParameter } from '../../common/utils';
|
||||
|
||||
export const FIELD: string = 'update';
|
||||
|
||||
const displayOptions: IDisplayOptions = {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
operation: [FIELD],
|
||||
},
|
||||
};
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
...getSelectFields(displayOptions),
|
||||
makeAddRow(FIELD, displayOptions),
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
placeholder: 'Add option',
|
||||
options: [DRY_RUN],
|
||||
displayOptions,
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const dataTableProxy = await getDataTableProxyExecute(this, index);
|
||||
const dryRun = getDryRunParameter(this, index);
|
||||
const row = getAddRow(this, index);
|
||||
const filter = await getSelectFilter(this, index);
|
||||
|
||||
if (filter.filters.length === 0) {
|
||||
throw new NodeOperationError(this.getNode(), 'At least one condition is required');
|
||||
}
|
||||
|
||||
const updatedRows = await dataTableProxy.updateRows({
|
||||
data: row,
|
||||
filter,
|
||||
dryRun,
|
||||
});
|
||||
|
||||
return updatedRows.map((json) => ({ json }));
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import {
|
||||
NodeOperationError,
|
||||
type IDisplayOptions,
|
||||
type IExecuteFunctions,
|
||||
type INodeExecutionData,
|
||||
type INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { makeAddRow, getAddRow } from '../../common/addRow';
|
||||
import { DRY_RUN } from '../../common/fields';
|
||||
import { getSelectFields, getSelectFilter } from '../../common/selectMany';
|
||||
import { getDataTableProxyExecute, getDryRunParameter } from '../../common/utils';
|
||||
|
||||
export const FIELD: string = 'upsert';
|
||||
|
||||
const displayOptions: IDisplayOptions = {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
operation: [FIELD],
|
||||
},
|
||||
};
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
...getSelectFields(displayOptions, true),
|
||||
makeAddRow(FIELD, displayOptions),
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
placeholder: 'Add option',
|
||||
options: [DRY_RUN],
|
||||
displayOptions,
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const dataTableProxy = await getDataTableProxyExecute(this, index);
|
||||
const dryRun = getDryRunParameter(this, index);
|
||||
const row = getAddRow(this, index);
|
||||
const filter = await getSelectFilter(this, index);
|
||||
|
||||
if (filter.filters.length === 0) {
|
||||
throw new NodeOperationError(this.getNode(), 'At least one condition is required');
|
||||
}
|
||||
|
||||
const result = await dataTableProxy.upsertRow({
|
||||
data: row,
|
||||
filter,
|
||||
dryRun,
|
||||
});
|
||||
|
||||
return result.map((json) => ({ json }));
|
||||
}
|
||||
Reference in New Issue
Block a user