Junyi 6a589543f9
refactor(db): add batch logic to update for better performance (#2070)
* refactor(db): add batch logic to update for better performance

* test(plugin-workflow): fix test cases

* fix(db): treat belongsTo field in update values as foreignKey

* fix(db): also handle object with id for belongsTo field

* fix(db): avoid 0 as falsy

* fix(db): fix test case
2023-06-21 16:37:06 +08:00

25 lines
700 B
TypeScript

import FlowNodeModel from '../models/FlowNode';
import Processor from '../Processor';
import { JOB_STATUS } from '../constants';
export default {
async run(node: FlowNodeModel, input, processor: Processor) {
const { collection, params = {} } = node.config;
const repo = (<typeof FlowNodeModel>node.constructor).database.getRepository(collection);
const options = processor.getParsedValue(params, node);
const result = await repo.update({
...options,
context: {
executionId: processor.execution.id,
},
transaction: processor.transaction,
});
return {
result: result.length ?? result,
status: JOB_STATUS.RESOLVED,
};
},
};