Skip to content

Commit

Permalink
use *sql.Tx for barrier
Browse files Browse the repository at this point in the history
  • Loading branch information
yedf2 committed Aug 20, 2021
1 parent 7e71bfe commit 9e48c6e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion examples/http_saga_gorm_barrier.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package examples

import (
"database/sql"

"github.com/gin-gonic/gin"
"github.com/yedf/dtm/common"
"github.com/yedf/dtm/dtmcli"
Expand Down Expand Up @@ -28,7 +30,7 @@ func sagaGormBarrierTransOut(c *gin.Context) (interface{}, error) {
req := reqFrom(c)
barrier := MustBarrierFromGin(c)
tx := dbGet().DB.Begin()
return dtmcli.ResultSuccess, barrier.Call(tx.Statement.ConnPool.(dtmcli.Tx), func(db dtmcli.DB) error {
return dtmcli.ResultSuccess, barrier.Call(tx.Statement.ConnPool.(*sql.Tx), func(db dtmcli.DB) error {
return tx.Exec("update dtm_busi.user_account set balance = balance + ? where user_id = ?", -req.Amount, 2).Error
})
}

0 comments on commit 9e48c6e

Please sign in to comment.