2023-12-07 13:46:58 +00:00
|
|
|
import { Processor, Instruction, JOB_STATUS, FlowNodeModel } from '@nocobase/plugin-workflow';
|
2023-07-20 03:04:41 +00:00
|
|
|
|
2023-12-07 13:46:58 +00:00
|
|
|
export default class extends Instruction {
|
2023-07-20 03:04:41 +00:00
|
|
|
async run(node: FlowNodeModel, input, processor: Processor) {
|
|
|
|
const { sequelize } = (<typeof FlowNodeModel>node.constructor).database;
|
2023-08-22 12:13:52 +00:00
|
|
|
const sql = processor.getParsedValue(node.config.sql ?? '', node.id).trim();
|
2023-07-20 03:04:41 +00:00
|
|
|
if (!sql) {
|
|
|
|
return {
|
|
|
|
status: JOB_STATUS.RESOLVED,
|
2023-08-22 12:13:52 +00:00
|
|
|
};
|
2023-07-20 03:04:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const result = await sequelize.query(sql, {
|
2024-01-27 01:37:40 +00:00
|
|
|
transaction: processor.transaction,
|
2023-07-20 03:04:41 +00:00
|
|
|
// plain: true,
|
|
|
|
// model: db.getCollection(node.config.collection).model
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
result,
|
|
|
|
status: JOB_STATUS.RESOLVED,
|
|
|
|
};
|
2023-12-07 13:46:58 +00:00
|
|
|
}
|
|
|
|
}
|