mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 03:36:05 +00:00
fix(plugin-workflow-sql): fix no result when calling stored procedure (#5385)
This commit is contained in:
parent
744d97c9b4
commit
0183ef0561
@ -24,12 +24,12 @@ export default class extends Instruction {
|
||||
};
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const [result, meta] = await db.sequelize.query(sql, {
|
||||
const [result = null, meta = null] =
|
||||
(await db.sequelize.query(sql, {
|
||||
transaction: this.workflow.useDataSourceTransaction(dataSourceName, processor.transaction),
|
||||
// plain: true,
|
||||
// model: db.getCollection(node.config.collection).model
|
||||
});
|
||||
})) ?? [];
|
||||
|
||||
return {
|
||||
result: node.config.withMeta ? [result, meta] : result,
|
||||
|
@ -14,6 +14,8 @@ import { getApp, sleep } from '@nocobase/plugin-workflow-test';
|
||||
|
||||
import Plugin from '..';
|
||||
|
||||
const mysql = process.env.DB_DIALECT === 'mysql' ? describe : describe.skip;
|
||||
|
||||
describe('workflow > instructions > sql', () => {
|
||||
let app: Application;
|
||||
let db: Database;
|
||||
@ -288,4 +290,48 @@ describe('workflow > instructions > sql', () => {
|
||||
expect(job.result[0].id).toBe(post.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dialects', () => {
|
||||
mysql('mysql', () => {
|
||||
it('stored procedure with result', async () => {
|
||||
await db.sequelize.query(`DROP PROCEDURE IF EXISTS hello`);
|
||||
await db.sequelize.query(`CREATE PROCEDURE hello(IN id INT) BEGIN select id + 1 as a; END;`);
|
||||
const n1 = await workflow.createNode({
|
||||
type: 'sql',
|
||||
config: {
|
||||
sql: 'call hello(1)',
|
||||
},
|
||||
});
|
||||
|
||||
await PostRepo.create({ values: { title: 't1' } });
|
||||
|
||||
await sleep(500);
|
||||
|
||||
const [execution] = await workflow.getExecutions();
|
||||
const [sqlJob] = await execution.getJobs({ order: [['id', 'ASC']] });
|
||||
expect(sqlJob.status).toBe(JOB_STATUS.RESOLVED);
|
||||
expect(sqlJob.result).toEqual({ a: 2 });
|
||||
});
|
||||
|
||||
it('stored procedure without result', async () => {
|
||||
await db.sequelize.query(`DROP PROCEDURE IF EXISTS hello`);
|
||||
await db.sequelize.query(`CREATE PROCEDURE hello(IN id INT) BEGIN declare i int default 0; END;`);
|
||||
const n1 = await workflow.createNode({
|
||||
type: 'sql',
|
||||
config: {
|
||||
sql: 'call hello(1)',
|
||||
},
|
||||
});
|
||||
|
||||
await PostRepo.create({ values: { title: 't1' } });
|
||||
|
||||
await sleep(500);
|
||||
|
||||
const [execution] = await workflow.getExecutions();
|
||||
const [sqlJob] = await execution.getJobs({ order: [['id', 'ASC']] });
|
||||
expect(sqlJob.status).toBe(JOB_STATUS.RESOLVED);
|
||||
expect(sqlJob.result).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user