Your Question

why gorm perform single create, update, delete operations in transactions by default ? a single sql really need transactions? are there any specific differences between transactions of a single sql? mysql execute single sql as a implicit transaction

The document you expected this should be explained

Expected answer

Comment From: dkasyanov

Hi!

According to the GORM documentation, write (create/update/delete) operations run inside a transaction by default to ensure data consistency. However, you can disable this behavior during initialization if it is not required. Doing so may improve performance by about 30% or more.

Explicit transactions can still be useful in certain situations, even if you disable GORM's default behavior. For example, transactions can help to ensure data integrity by allowing you to roll back changes if something goes wrong during an operation. They can also help with concurrency issues by ensuring that multiple concurrent operations don't interfere with each other.

More docs here: https://gorm.io/docs/transactions.html

Comment From: pigfu

thanks,i know what you say,but i want to konw why write (create/update/delete) operations run inside a transaction,that can ensure db data consistency。 if don't do it, the db data may will be inconsistent ?? if possible,please for example...

Comment From: a631807682

Gorm provides logic-level APIs, such as CreateInBatches, which need to ensure consistency, and users need to choose whether to enable things according to their own needs.

Comment From: pigfu

get,thanks