Created transaction wrapper
This commit is contained in:
parent
0caca1a6f9
commit
98d691603d
11
main.go
11
main.go
@ -522,6 +522,17 @@ func (s *DB) Rollback() *DB {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WrapInTx wraps a method in a transaction
|
||||||
|
func (s *DB) WrapInTx(f func(tx *gorm.DB) (error)) error {
|
||||||
|
tx := s.Begin()
|
||||||
|
if err := f(tx); err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tx.Commit()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// NewRecord check if value's primary key is blank
|
// NewRecord check if value's primary key is blank
|
||||||
func (s *DB) NewRecord(value interface{}) bool {
|
func (s *DB) NewRecord(value interface{}) bool {
|
||||||
return s.NewScope(value).PrimaryKeyZero()
|
return s.NewScope(value).PrimaryKeyZero()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user