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,63 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as create from './create.operation';
|
||||
import * as deleteTable from './delete.operation';
|
||||
import * as list from './list.operation';
|
||||
import * as update from './update.operation';
|
||||
import { DATA_TABLE_RESOURCE_LOCATOR_BASE } from '../../common/fields';
|
||||
|
||||
export { create, deleteTable, list, update };
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['table'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: create.FIELD,
|
||||
description: 'Create a new data table',
|
||||
action: 'Create a data table',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: deleteTable.FIELD,
|
||||
description: 'Delete a data table',
|
||||
action: 'Delete a data table',
|
||||
},
|
||||
{
|
||||
name: 'List',
|
||||
value: list.FIELD,
|
||||
description: 'List all data tables',
|
||||
action: 'List data tables',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: update.FIELD,
|
||||
description: 'Update a data table name',
|
||||
action: 'Update a data table',
|
||||
},
|
||||
],
|
||||
default: 'list',
|
||||
},
|
||||
{
|
||||
...DATA_TABLE_RESOURCE_LOCATOR_BASE,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['table'],
|
||||
operation: [deleteTable.FIELD, update.FIELD],
|
||||
},
|
||||
},
|
||||
},
|
||||
...create.description,
|
||||
...deleteTable.description,
|
||||
...list.description,
|
||||
...update.description,
|
||||
];
|
||||
@@ -0,0 +1,131 @@
|
||||
import type {
|
||||
CreateDataTableColumnOptions,
|
||||
IDisplayOptions,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { getDataTableAggregateProxy } from '../../common/utils';
|
||||
|
||||
export const FIELD = 'create';
|
||||
|
||||
const displayOptions: IDisplayOptions = {
|
||||
show: {
|
||||
resource: ['table'],
|
||||
operation: [FIELD],
|
||||
},
|
||||
};
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'tableName',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
placeholder: 'e.g. My Data Table',
|
||||
description: 'The name of the data table to create',
|
||||
displayOptions,
|
||||
},
|
||||
{
|
||||
displayName: 'Columns',
|
||||
name: 'columns',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
placeholder: 'Add Column',
|
||||
description: 'The columns to create in the data table',
|
||||
displayOptions,
|
||||
options: [
|
||||
{
|
||||
name: 'column',
|
||||
displayName: 'Column',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
description: 'The name of the column',
|
||||
},
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'type',
|
||||
type: 'options',
|
||||
default: 'string',
|
||||
options: [
|
||||
{ name: 'Boolean', value: 'boolean' },
|
||||
{ name: 'Date', value: 'date' },
|
||||
{ name: 'Number', value: 'number' },
|
||||
{ name: 'String', value: 'string' },
|
||||
],
|
||||
description: 'The type of the column',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
displayOptions,
|
||||
options: [
|
||||
{
|
||||
displayName: 'Reuse Existing Tables',
|
||||
name: 'createIfNotExists',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description:
|
||||
'Whether to return existing table if one exists with the same name without throwing an error',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const tableName = this.getNodeParameter('tableName', index) as string;
|
||||
const columnsData = this.getNodeParameter('columns.column', index, []) as Array<
|
||||
Pick<CreateDataTableColumnOptions, 'name' | 'type'>
|
||||
>;
|
||||
const options = this.getNodeParameter('options', index, {}) as {
|
||||
createIfNotExists?: boolean;
|
||||
};
|
||||
|
||||
const aggregateProxy = await getDataTableAggregateProxy(this);
|
||||
|
||||
// If "Create If Not Exists" is enabled, check if table already exists
|
||||
if (options.createIfNotExists) {
|
||||
const existingTables = await aggregateProxy.getManyAndCount({
|
||||
filter: { name: tableName },
|
||||
take: 1,
|
||||
});
|
||||
|
||||
// If a table with exact name match exists, return it
|
||||
if (existingTables.data.length > 0 && existingTables.data[0].name === tableName) {
|
||||
return [{ json: existingTables.data[0] }];
|
||||
}
|
||||
}
|
||||
|
||||
const columns: CreateDataTableColumnOptions[] = columnsData.map((col, idx) => ({
|
||||
name: col.name,
|
||||
type: col.type,
|
||||
index: idx,
|
||||
}));
|
||||
|
||||
const result = await aggregateProxy.createDataTable({
|
||||
name: tableName,
|
||||
columns,
|
||||
});
|
||||
|
||||
return [{ json: result }];
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import type {
|
||||
IDisplayOptions,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { DATA_TABLE_ID_FIELD } from '../../common/fields';
|
||||
import { getDataTableProxyExecute } from '../../common/utils';
|
||||
|
||||
export const FIELD = 'delete';
|
||||
|
||||
const displayOptions: IDisplayOptions = {
|
||||
show: {
|
||||
resource: ['table'],
|
||||
operation: [FIELD],
|
||||
},
|
||||
};
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName:
|
||||
'This will permanently delete the data table and all its data. This action cannot be undone.',
|
||||
name: 'deleteWarning',
|
||||
type: 'notice',
|
||||
default: '',
|
||||
displayOptions,
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const dataTableId = this.getNodeParameter(DATA_TABLE_ID_FIELD, index, undefined, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
const dataTableProxy = await getDataTableProxyExecute(this, index);
|
||||
|
||||
const success = await dataTableProxy.deleteDataTable();
|
||||
|
||||
return [{ json: { success, deletedTableId: dataTableId } }];
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
import type {
|
||||
IDisplayOptions,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
ListDataTableOptions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { ROWS_LIMIT_DEFAULT } from '../../common/constants';
|
||||
import { getDataTableAggregateProxy } from '../../common/utils';
|
||||
|
||||
export const FIELD = 'list';
|
||||
|
||||
const displayOptions: IDisplayOptions = {
|
||||
show: {
|
||||
resource: ['table'],
|
||||
operation: [FIELD],
|
||||
},
|
||||
};
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
displayOptions,
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
default: ROWS_LIMIT_DEFAULT,
|
||||
description: 'Max number of results to return',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
...displayOptions.show,
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
displayOptions,
|
||||
options: [
|
||||
{
|
||||
displayName: 'Filter by Name',
|
||||
name: 'filterName',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Filter data tables by name (case-insensitive)',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort Field',
|
||||
name: 'sortField',
|
||||
type: 'options',
|
||||
default: 'name',
|
||||
options: [
|
||||
{ name: 'Created', value: 'createdAt' },
|
||||
{ name: 'Name', value: 'name' },
|
||||
{ name: 'Updated', value: 'updatedAt' },
|
||||
],
|
||||
description: 'Field to sort by',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort Direction',
|
||||
name: 'sortDirection',
|
||||
type: 'options',
|
||||
default: 'asc',
|
||||
options: [
|
||||
{ name: 'Ascending', value: 'asc' },
|
||||
{ name: 'Descending', value: 'desc' },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const returnAll = this.getNodeParameter('returnAll', index) as boolean;
|
||||
const limit = this.getNodeParameter('limit', index, ROWS_LIMIT_DEFAULT) as number;
|
||||
const options = this.getNodeParameter('options', index, {}) as {
|
||||
filterName?: string;
|
||||
sortField?: string;
|
||||
sortDirection?: 'asc' | 'desc';
|
||||
};
|
||||
|
||||
const aggregateProxy = await getDataTableAggregateProxy(this);
|
||||
|
||||
const queryOptions: ListDataTableOptions = {};
|
||||
|
||||
if (options.sortField && options.sortDirection) {
|
||||
queryOptions.sortBy =
|
||||
`${options.sortField}:${options.sortDirection}` as ListDataTableOptions['sortBy'];
|
||||
}
|
||||
|
||||
if (options.filterName) {
|
||||
queryOptions.filter = { name: options.filterName.toLowerCase() };
|
||||
}
|
||||
|
||||
const results: INodeExecutionData[] = [];
|
||||
|
||||
if (returnAll) {
|
||||
let skip = 0;
|
||||
const take = 100;
|
||||
let hasMore = true;
|
||||
|
||||
while (hasMore) {
|
||||
const response = await aggregateProxy.getManyAndCount({
|
||||
...queryOptions,
|
||||
skip,
|
||||
take,
|
||||
});
|
||||
|
||||
for (const table of response.data) {
|
||||
results.push({ json: table });
|
||||
}
|
||||
|
||||
skip += take;
|
||||
hasMore = response.data.length === take && results.length < response.count;
|
||||
}
|
||||
} else {
|
||||
const response = await aggregateProxy.getManyAndCount({
|
||||
...queryOptions,
|
||||
skip: 0,
|
||||
take: limit,
|
||||
});
|
||||
|
||||
for (const table of response.data) {
|
||||
results.push({ json: table });
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import type {
|
||||
IDisplayOptions,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { getDataTableProxyExecute } from '../../common/utils';
|
||||
|
||||
export const FIELD = 'update';
|
||||
|
||||
const displayOptions: IDisplayOptions = {
|
||||
show: {
|
||||
resource: ['table'],
|
||||
operation: [FIELD],
|
||||
},
|
||||
};
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'New Name',
|
||||
name: 'newName',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
placeholder: 'e.g. Renamed Data Table',
|
||||
description: 'The new name for the data table',
|
||||
displayOptions,
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const newName = this.getNodeParameter('newName', index) as string;
|
||||
|
||||
const dataTableProxy = await getDataTableProxyExecute(this, index);
|
||||
|
||||
const success = await dataTableProxy.updateDataTable({ name: newName });
|
||||
|
||||
return [{ json: { success, name: newName } }];
|
||||
}
|
||||
Reference in New Issue
Block a user