terminal

codeando_simple

terminal

menu

terminal

search_module

guest@codeandosimple: ~/system/search $ grep -r "" .

Press [ENTER] to execute search

Status

Engine: Ready

Database: Online

Index: V2.1.0_LATEST

bash -- cat unit-of-work.md
guest@codeandosimple: ~/enterprise/patterns $ cat unit-of-work.md

Unit of Work_

// "Maintaining the integrity of your transactions"

The **Unit of Work** pattern is responsible for keeping track of everything you've done during a business transaction that can affect the database.

When the transaction ends, the Unit of Work calculates everything that needs to be done to reflect the changes in the database (insertions, updates, and deletions).

# Why use Unit of Work?

Without this pattern, you might end up making multiple small calls to the database, which is inefficient. Unit of Work groups all operations into a single block, optimizing performance and ensuring the transaction is atomic.

# Pros

  • verified

    Atomic Transactions

    Ensures that all changes are saved or none.

  • verified

    Reduction of DB Hits

    Minimizes the number of connections to the database.

# Conceptual Example

1. uow.registerNew(customer)
2. uow.registerDirty(order302)
3. uow.commit() // Executes everything