add to baserow node the batch insert
I asked openai tò add the batch insert to baserow node
Anyone can push this?
Sì, è possibile aggiungere la funzionalità di inserimento in batch al nodo Baserow di n8n.
Attualmente, il nodo originale inserisce singolarmente ogni record, ma l’API di Baserow supporta già inserimenti multipli tramite una singola chiamata.
Ecco come puoi modificare il nodo per aggiungere il supporto batch-insert:
1. Modifica il file Baserow.node.ts
Aggiungi un’operazione “Insert Many” con il supporto batch-insert, come segue:
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
default: 'create',
options: [
{
name: 'Create',
value: 'create',
description: 'Create a single row',
},
{
name: 'Create Many',
value: 'createMany',
description: 'Create multiple rows in batch',
},
// altre operazioni...
],
},
2. Modifica la funzione execute()
nel file Baserow.node.ts
Inserisci un blocco che gestisce l’operazione createMany
:
if (operation === 'createMany') {
const tableId = this.getNodeParameter('tableId', 0, '') as string;
const rows = items.map((item, index) => {
const fields = this.getNodeParameter('fieldsUi.fieldValues', index, {}) as IDataObject;
return fields;
});
const endpoint = `/database/rows/table/${tableId}/batch/`;
const response = await baserowApiRequest.call(this, 'POST', endpoint, { items: rows });
return this.helpers.returnJsonArray(response.items);
}
3. Modifica il file di supporto (GenericFunctions.ts
)
Se non lo avessi già fatto, aggiungi il supporto della funzione baserowApiRequest
per garantire il corretto invio del body JSON:
export async function baserowApiRequest(
this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions,
method: string,
endpoint: string,
body: IDataObject = {},
qs: IDataObject = {},
): Promise<any> {
const credentials = await this.getCredentials('baserowApi');
const options: OptionsWithUri = {
method,
headers: {
'Authorization': `Token ${credentials.apiKey}`,
'Content-Type': 'application/json',
},
uri: `${credentials.url}/api${endpoint}`,
body,
qs,
json: true,
};
try {
return await this.helpers.request(options);
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}
}
Risultato finale
Ora avrai la possibilità di selezionare “Create Many” nel nodo Baserow di n8n, permettendo così l’inserimento di più righe contemporaneamente tramite una singola chiamata API, con maggiore efficienza rispetto agli inserimenti singoli ripetuti.
Fammi sapere se hai bisogno di ulteriori dettagli!