diff options
Diffstat (limited to 'db.go')
-rw-r--r-- | db.go | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -440,6 +440,13 @@ func (db *DB) Update(fn func(*Tx) error) error { return err } + // Make sure the transaction rolls back in the event of a panic. + defer func() { + if t.db != nil { + t.rollback() + } + }() + // Mark as a managed tx so that the inner function cannot manually commit. t.managed = true @@ -464,6 +471,13 @@ func (db *DB) View(fn func(*Tx) error) error { return err } + // Make sure the transaction rolls back in the event of a panic. + defer func() { + if t.db != nil { + t.rollback() + } + }() + // Mark as a managed tx so that the inner function cannot manually rollback. t.managed = true |