group db tx

This commit is contained in:
withchao
2023-02-20 17:43:09 +08:00
parent 6ef8228064
commit 762c49625c
16 changed files with 250 additions and 538 deletions
+19
View File
@@ -0,0 +1,19 @@
package tx
import (
"gorm.io/gorm"
)
func NewGorm(db *gorm.DB) Tx {
return &_Gorm{tx: db}
}
type _Gorm struct {
tx *gorm.DB
}
func (g *_Gorm) Transaction(fn func(tx any) error) error {
return g.tx.Transaction(func(tx *gorm.DB) error {
return fn(tx)
})
}