db.Transaction method for create Transaction block. (#2767)
* Add `db.Transaction` method for create Transaction block.
example:
```go
func CreateAnimals(db *gorm.DB) error {
db.Transaction(func(tx *gorm.DB) error {
if err := tx.Create(&Animal{Name: "Giraffe"}).Error; err != nil {
// return any error will rollback
return err
}
if err := tx.Create(&Animal{Name: "Lion"}).Error; err != nil {
return err
}
// return nil will commit
return nil
})
}
```
* Ensure rollback when commit has error.
amended comments in error.go for clarity and grammar; for more polish when using IDEs (e.g. VSCODE) that show comments as help text (#2182)
GORM
The fantastic ORM library for Golang, aims to be developer friendly.
Overview
- Full-Featured ORM (almost)
- Associations (Has One, Has Many, Belongs To, Many To Many, Polymorphism)
- Hooks (Before/After Create/Save/Update/Delete/Find)
- Preloading (eager loading)
- Transactions
- Composite Primary Key
- SQL Builder
- Auto Migrations
- Logger
- Extendable, write Plugins based on GORM callbacks
- Every feature comes with tests
- Developer Friendly
Getting Started
- GORM Guides https://gorm.io
Contributing
You can help to deliver a better GORM, check out things you can do
License
© Jinzhu, 2013~time.Now
Released under the MIT License
Languages
Go
99.9%
Shell
0.1%