Skip to content

Commit

Permalink
Prevent nested transactions with db.Transaction (jinzhu#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
qilx authored Jul 19, 2020
1 parent 652ce20 commit 345d18c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ func (s *DB) Debug() *DB {
// Transaction start a transaction as a block,
// return error will rollback, otherwise to commit.
func (s *DB) Transaction(fc func(tx *DB) error) (err error) {

if _, ok := s.db.(*sql.Tx); ok {
return fc(s)
}

panicked := true
tx := s.Begin()
defer func() {
Expand Down

0 comments on commit 345d18c

Please sign in to comment.