boltdb/bolt — pull request #78 by benbjohnson (2014-03-23 16:42:44+00:00)
Title: Mark Do()/With() transaction as managed.

Transaction created from Do() and With() are now considered "managed". Managed transactions cannot be manually committed or rolled back since the Do() and With() functions provide that functionally automatically. Previously, a Tx could be manually committed and then any changes after that would be lost.

Managed transactions will now panic if they are manually committed or rolled back. A `panic()` is used because there is no recovery option and the end user should be notified that they are using the `Tx` incorrectly -- even if they are not checking their return errors.

---

Related: https://github.com/boltdb/bolt/issues/72#issuecomment-38341639 by @tv42:

> As for the example at the end, I firmly believe Commit/Rollback belongs in the With/Do level, I'm not suggesting a change there. But as it is now, *the inner function can call Commit/Rollback, and the result can be confusing*. That's what the example tried to demonstrate. In the example, the changes are committed to the db, but the caller sees an error. Imagine that Commit being somewhere a few levels deeper, and it can get messy to debug. I don't immediately see a use case for the inner function being able to call Commit/Rollback.

---