1 Star 0 Fork 0

Lucky.麒麟 / goboot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
transaction.go 695 Bytes
一键复制 编辑 原始数据 按行查看 历史
Lucky.麒麟 提交于 2023-09-24 16:50 . v0.0.1
package callbacks
import (
"gitee.com/molonglove/goboot/gorm"
)
func BeginTransaction(db *gorm.DB) {
if !db.Config.SkipDefaultTransaction && db.Error == nil {
if tx := db.Begin(); tx.Error == nil {
db.Statement.ConnPool = tx.Statement.ConnPool
db.InstanceSet("gorm:started_transaction", true)
} else if tx.Error == gorm.ErrInvalidTransaction {
tx.Error = nil
} else {
db.Error = tx.Error
}
}
}
func CommitOrRollbackTransaction(db *gorm.DB) {
if !db.Config.SkipDefaultTransaction {
if _, ok := db.InstanceGet("gorm:started_transaction"); ok {
if db.Error != nil {
db.Rollback()
} else {
db.Commit()
}
db.Statement.ConnPool = db.ConnPool
}
}
}
Go
1
https://gitee.com/molonglove/goboot.git
git@gitee.com:molonglove/goboot.git
molonglove
goboot
goboot
v1.0.4

搜索帮助