3 ms·
Thanks for the suggestion. I added it to the README (33e7a07): https://github.com/boltdb/bolt#managing-transactions-manually https://github.com/boltdb/bolt#man
by benbjohnson 12y ago
Thanks for the suggestion. I added it to the README (33e7a07):
https://github.com/boltdb/bolt#managing-transactions-manually https://github.com/boltdb/bolt#managing-transactions-manuall...
The "defer tx.Rollback()" makes me cringe a little since it's confusing when you read the code top-down. It also throws out the error returned from Rollback(). Granted, the only possible error is if the DB is closed so it's not a big deal in most situations.
- AYBABTME 12y agoHow painful does this look? func action(...) (err error) { tx, err := db.Begin() if err != nil { return fmt.Errorf("preparing transaction: %v", err) } defer func(tx *sql.Tx) { if err != nil { _ = tx.Rollback() } else { err = tx.Commit() } }(tx) // do something return }