on 12-18-2020 1:43 PM
Hello community,
I have a question regarding transaction handling in CAP, maybe you can help me with my question, I am beginner with Node.js.
There is a following code snippet for overwriting of generic handler for update.
... (entities are renamed to abstract)
const tx = cds.transaction(req);
const ParentEntity= req.data;
const Children = ParentEntity.children;
if ( Children ) {
Children.forEach(async child=> {
let childDB = await tx.run(SELECT.one('Children').where({ID: child.ID})); //get from DB one child
if(child.version > childDB.version ) {
await tx.run(UPDATE.entity('Children').with( child).where({ ID: child.ID }));
} } return ParentEntity;
Idea: get Children from ParentEntry of request and for every entry, select one from DB and check version. If version is greater in request, then update. It works fine with the first request.
But, with the next request it got into wait mode and after timeout it is failed. It happens locally and in SCP. From log in SCP I understand that previous transaction was not closed. But how to do it? I return from function a ParentEntity. Thanks in advance.
best regards,
Andrey
Hi Daniel,
thanks a lot for the tip. Spending some hourse of investigating, luckily i searched for this and found the reason and solution.
Also thanks to Andrej for asking this question.
Just did not know, that i had a question 😉
Regards
Holger
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel,
cool! Thanks a lot!
Variants from first answer are working!
I have Node veriosn 12, so variant from second answer might work as well, however I will try it later.
best regards,
Andrey
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.