dtm-examples icon indicating copy to clipboard operation
dtm-examples copied to clipboard

gorm 使用报错

Open Itisyou opened this issue 3 years ago • 2 comments

image app.POST(BusiAPI+"/SagaBTransOutGorm", dtmutil.WrapHandler(func(c *gin.Context) interface{} { req := reqFrom(c) barrier := MustBarrierFromGin(c) tx := dbGet().DB.Begin() return barrier.Call(tx.Statement.ConnPool.(*sql.Tx), func(tx1 *sql.Tx) error { return tx.Exec("update dtm_busi.user_account set balance = balance + ? where user_id = ?", -req.Amount, TransOutUID).Error }) }))

报错信息: panic: interface conversion: gorm.ConnPool is *gorm.PreparedStmtTX, not *sql.Tx [recovered] panic: interface conversion: gorm.ConnPool is *gorm.PreparedStmtTX, not *sql.Tx

Itisyou avatar Oct 26 '22 03:10 Itisyou

搞定了 将 tx.Statement.ConnPool.(*sql.Tx) 修改为tx.Statement.ConnPool.(*gorm.PreparedStmtTX).Tx.(*sql.Tx) 即可

Itisyou avatar Oct 26 '22 06:10 Itisyou

帮忙把这个修改提个pr过来呗,感谢哈

yedf2 avatar Oct 26 '22 06:10 yedf2