Database Transaction And How To Handle It In NodeJS With Prisma

Saigon Technology
2 min readApr 24, 2024

--

1/ What is Database Transaction?

Database Transaction is a unit of work, which may include many actions we want to perform with the database system. In a simple word, the transaction represents any change of the database.

The main purpose of transaction is:

  • Furnish a dependable operational entity capable of facilitating accurate recovery and preserving database consistency in the event of system failure.
  • Provide isolation between programs and allow concurrent access to the database.

2/ Transaction basic and ACID properties

Each transaction can have a single operation or a set of operations, which will be performed sequentially. Transaction will wrap this set and using the following pattern to handle SQL execution:

  • Begin the transaction.
  • Perform a series of data manipulations and/or queries.
  • If executed without encountering errors, commit the transaction.
  • However, if an error arises during the process, roll back the transaction to its initial state.

By following this pattern, the database can make sure it will provide the ACID properties, which will be intended to guarantee data validity despite errors, power failures, and other mishaps.

…..

Read more at: https://saigontechnology.com/blog/database-transaction-and-how-to-handle-it-in-nodejs-with-prisma

--

--

Saigon Technology
Saigon Technology

Written by Saigon Technology

Saigon Technology is a leading software development company in Vietnam. Web: https://saigontechnology.com. Email: inquiry@saigontechnology.com.

No responses yet