Added sub-transaction detection to WrapInTx
This commit is contained in:
parent
410393c804
commit
221f8963db
8
main.go
8
main.go
@ -523,7 +523,12 @@ func (s *DB) Rollback() *DB {
|
||||
}
|
||||
|
||||
// WrapInTx wraps a method in a transaction
|
||||
func (s *DB) WrapInTx(f func(tx *DB) (error)) error {
|
||||
func (s *DB) WrapInTx(f func(tx *DB) error) error {
|
||||
if _, ok := s.db.(*sql.Tx); ok {
|
||||
// Already in a transaction
|
||||
return f(s)
|
||||
} else {
|
||||
// Lets start a new transaction
|
||||
tx := s.Begin()
|
||||
if err := f(tx); err != nil {
|
||||
tx.Rollback()
|
||||
@ -532,6 +537,7 @@ func (s *DB) WrapInTx(f func(tx *DB) (error)) error {
|
||||
tx.Commit()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// SkipAssocSave disables saving of associations
|
||||
func (s *DB) SkipAssocSave() *DB {
|
||||
|
Loading…
x
Reference in New Issue
Block a user