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

gorm 使用报错 #5

Open
Itisyou opened this issue Oct 26, 2022 · 2 comments
Open

gorm 使用报错 #5

Itisyou opened this issue Oct 26, 2022 · 2 comments

Comments

@Itisyou
Copy link

Itisyou commented Oct 26, 2022

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
Copy link
Author

Itisyou commented Oct 26, 2022

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

@Itisyou Itisyou closed this as completed Oct 26, 2022
@yedf2
Copy link
Contributor

yedf2 commented Oct 26, 2022

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

@yedf2 yedf2 reopened this Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants