mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
feat(core): Use filters for data table upsert (no-changelog) (#19292)
This commit is contained in:
@@ -37,7 +37,7 @@ export async function execute(
|
||||
throw new NodeOperationError(this.getNode(), 'At least one condition is required');
|
||||
}
|
||||
|
||||
const updatedRows = await dataStoreProxy.updateRows({
|
||||
const updatedRows = await dataStoreProxy.updateRow({
|
||||
data: row,
|
||||
filter,
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { makeAddRow, getAddRow } from '../../common/addRow';
|
||||
import { executeSelectMany, getSelectFields } from '../../common/selectMany';
|
||||
import { getSelectFields, getSelectFilter } from '../../common/selectMany';
|
||||
import { getDataTableProxyExecute } from '../../common/utils';
|
||||
|
||||
export const FIELD: string = 'upsert';
|
||||
@@ -32,35 +32,16 @@ export async function execute(
|
||||
|
||||
const row = getAddRow(this, index);
|
||||
|
||||
const matches = await executeSelectMany(this, index, dataStoreProxy, true);
|
||||
const filter = getSelectFilter(this, index);
|
||||
|
||||
// insert
|
||||
if (matches.length === 0) {
|
||||
const result = await dataStoreProxy.insertRows([row]);
|
||||
return result.map((json) => ({ json }));
|
||||
if (filter.filters.length === 0) {
|
||||
throw new NodeOperationError(this.getNode(), 'At least one condition is required');
|
||||
}
|
||||
|
||||
// update
|
||||
const result = [];
|
||||
for (const match of matches) {
|
||||
const updatedRows = await dataStoreProxy.updateRows({
|
||||
data: row,
|
||||
filter: {
|
||||
type: 'and',
|
||||
filters: [{ columnName: 'id', condition: 'eq', value: match.json.id }],
|
||||
},
|
||||
});
|
||||
if (updatedRows.length !== 1) {
|
||||
throw new NodeOperationError(this.getNode(), 'invariant broken');
|
||||
}
|
||||
|
||||
// The input object gets updated in the api call, somehow
|
||||
// And providing this column to the backend causes an unexpected column error
|
||||
// So let's just re-delete the field until we have a more aligned API
|
||||
delete row['updatedAt'];
|
||||
|
||||
result.push(updatedRows[0]);
|
||||
}
|
||||
const result = await dataStoreProxy.upsertRow({
|
||||
data: row,
|
||||
filter,
|
||||
});
|
||||
|
||||
return result.map((json) => ({ json }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user