serverless-mysql icon indicating copy to clipboard operation
serverless-mysql copied to clipboard

How to create transaction?

Open carlosfer02 opened this issue 3 years ago • 1 comments

How can I commit a query only if the call to another method is successful?

I am trying something like this:

            const transaction = await mysql.connection.transaction();
            await transaction.query("UPDATE employees SET name=? WHERE id=3", [name]);
            let result = await CognitoAccessToken.signUp();
            if (result == true) {
                await transaction.commit();
            } else {
                await transaction.rollback();
            }
            await mysql.connection.end();

But for some reason, only after executing the query twice, it makes the employee update.

PS: I am using node.js

carlosfer02 avatar Aug 23 '21 20:08 carlosfer02

Maybe #85 is what you are looking for.

trasherdk avatar Aug 24 '21 03:08 trasherdk