cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Database rollback functionality in node.js in xsa

0 Likes
888

Hi Experts,

I am developing an Node.js service to expose data from HANA in an MTA application in XSA. I have written Multiple inserts in an app.post to insert records in more than one table . I want the database to rollback the inserts if any of the insert fails.

Could you please suggest solutions to achieve the rollback functionality. I am using async and await in app.post() to execute the insert queries.

Below is the code snippets.

apppost.png dbpromise.png

View Entire Topic
pfefferf
Active Contributor
0 Likes

By default the autoCommit option is set, so each inserts commits if no error occurred. One option to reach what you wanna have is to disable the auto commit using function setAutoCommit(false) on the db connection. Then do your inserts. In case of an error execute function rollback() on the db connection. In case of no error function success(). Afterwards (in both bases) enable the autoCommit option again.

If wanna do in general the commit/rollback handling by yourself you can set the autoCommit option to false when the db connection is created.

0 Likes

Thanks Florian . It worked.