Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why GORM perform single create, update, delete operations in transactions by default ? #5969

Closed
pigfu opened this issue Jan 9, 2023 · 4 comments
Assignees
Labels
type:question general questions

Comments

@pigfu
Copy link

pigfu commented Jan 9, 2023

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

@pigfu pigfu added the type:question general questions label Jan 9, 2023
@dkasyanov
Copy link

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

@pigfu
Copy link
Author

pigfu commented Jan 11, 2023

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...

@a631807682
Copy link
Member

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.

@pigfu
Copy link
Author

pigfu commented Jan 29, 2023

get,thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question general questions
Projects
None yet
Development

No branches or pull requests

4 participants