mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 17:14:05 -08:00
add new action "get many rows"
This commit is contained in:
parent
bda3edbfa9
commit
4f8be47b43
|
@ -1,7 +1,7 @@
|
|||
import type { AllEntities, Entity, PropertiesOf } from 'n8n-workflow';
|
||||
|
||||
type SeaTableMap = {
|
||||
row: 'create' | 'get' | 'search' | 'update' | 'remove' | 'lock' | 'unlock';
|
||||
row: 'create' | 'get' | 'search' | 'update' | 'remove' | 'lock' | 'unlock' | 'list';
|
||||
base: 'snapshot' | 'metadata' | 'apiCall' | 'collaborator';
|
||||
link: 'add' | 'remove';
|
||||
asset: 'upload' | 'getPublicURL';
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as create from './create';
|
||||
import * as get from './get';
|
||||
import * as list from './list';
|
||||
import * as search from './search';
|
||||
import * as update from './update';
|
||||
import * as remove from './remove';
|
||||
|
@ -7,7 +8,7 @@ import * as lock from './lock';
|
|||
import * as unlock from './unlock';
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export { create, get, search, update, remove, lock, unlock };
|
||||
export { create, get, search, update, remove, lock, unlock, list };
|
||||
|
||||
export const descriptions: INodeProperties[] = [
|
||||
{
|
||||
|
@ -33,6 +34,12 @@ export const descriptions: INodeProperties[] = [
|
|||
description: 'Get the content of a row',
|
||||
action: 'Get a row',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'list',
|
||||
description: 'Get many rows from a table of view',
|
||||
action: 'Get many rows',
|
||||
},
|
||||
{
|
||||
name: 'Search',
|
||||
value: 'search',
|
||||
|
@ -68,6 +75,7 @@ export const descriptions: INodeProperties[] = [
|
|||
},
|
||||
...create.description,
|
||||
...get.description,
|
||||
...list.description,
|
||||
...search.description,
|
||||
...update.description,
|
||||
...remove.description,
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
import type { RowProperties } from '../../Interfaces';
|
||||
|
||||
export const rowListDescription: RowProperties = [
|
||||
{
|
||||
displayName: 'Table Name',
|
||||
name: 'tableName',
|
||||
type: 'options',
|
||||
placeholder: 'Select a table',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTableNames',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
operation: ['list'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'The name of SeaTable table to access. Choose from the list, or specify a name using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'View Name or ID (optional)',
|
||||
name: 'viewName',
|
||||
type: 'options',
|
||||
required: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
operation: ['list'],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['tableName'],
|
||||
loadOptionsMethod: 'getTableViews',
|
||||
},
|
||||
default: '',
|
||||
description: 'The name of SeaTable view to access. Choose from the list, or specify ...',
|
||||
},
|
||||
{
|
||||
displayName: 'Simplify output',
|
||||
name: 'simple',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
operation: ['list'],
|
||||
},
|
||||
},
|
||||
default: true,
|
||||
description:
|
||||
'Simplified returns only the columns of your base. Non-simplified will return additional columns like _ctime (=creation time), _mtime (=modification time) etc.',
|
||||
},
|
||||
];
|
|
@ -0,0 +1,54 @@
|
|||
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
|
||||
import type { IRow } from './../../Interfaces';
|
||||
import {
|
||||
seaTableApiRequest,
|
||||
enrichColumns,
|
||||
simplify_new,
|
||||
getBaseCollaborators,
|
||||
} from '../../../GenericFunctions';
|
||||
|
||||
export async function list(this: IExecuteFunctions, index: number): Promise<INodeExecutionData[]> {
|
||||
// get parameters
|
||||
const tableName = this.getNodeParameter('tableName', index) as string;
|
||||
const viewName = this.getNodeParameter('viewName', index) as string;
|
||||
const simple = this.getNodeParameter('simple', index) as boolean;
|
||||
|
||||
// get collaborators
|
||||
const collaborators = await getBaseCollaborators.call(this);
|
||||
|
||||
// get rows
|
||||
let requestMeta = await seaTableApiRequest.call(
|
||||
this,
|
||||
{},
|
||||
'GET',
|
||||
'/dtable-server/api/v1/dtables/{{dtable_uuid}}/metadata/',
|
||||
);
|
||||
|
||||
let requestRows = await seaTableApiRequest.call(
|
||||
this,
|
||||
{},
|
||||
'GET',
|
||||
'/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/',
|
||||
{},
|
||||
{
|
||||
table_name: tableName,
|
||||
view_name: viewName,
|
||||
limit: 1000,
|
||||
},
|
||||
);
|
||||
|
||||
let metadata =
|
||||
requestMeta.metadata.tables.find((table: { name: string }) => table.name === tableName)
|
||||
?.columns ?? [];
|
||||
let rows = requestRows.rows as IRow[];
|
||||
|
||||
// hide columns like button
|
||||
rows.map((row) => enrichColumns(row, metadata, collaborators));
|
||||
|
||||
// remove columns starting with _ if simple;
|
||||
if (simple) {
|
||||
rows.map((row) => simplify_new(row));
|
||||
}
|
||||
|
||||
return this.helpers.returnJsonArray(rows as IDataObject[]);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
import { list as execute } from './execute';
|
||||
import { rowListDescription as description } from './description';
|
||||
|
||||
export { description, execute };
|
Loading…
Reference in a new issue