route/vendor/github.com/asdine/storm/transaction.go

53 lines
913 B
Go
Raw Normal View History

2017-04-28 23:28:25 +00:00
package storm
2018-01-03 19:29:07 +00:00
import "github.com/coreos/bbolt"
2017-04-28 23:28:25 +00:00
2018-01-03 19:29:07 +00:00
// tx is a transaction
type tx interface {
2017-04-28 23:28:25 +00:00
// Commit writes all changes to disk.
Commit() error
// Rollback closes the transaction and ignores all previous updates.
Rollback() error
}
// Begin starts a new transaction.
func (n node) Begin(writable bool) (Node, error) {
var err error
n.tx, err = n.s.Bolt.Begin(writable)
if err != nil {
return nil, err
}
return &n, nil
}
// Rollback closes the transaction and ignores all previous updates.
func (n *node) Rollback() error {
if n.tx == nil {
return ErrNotInTransaction
}
err := n.tx.Rollback()
if err == bolt.ErrTxClosed {
return ErrNotInTransaction
}
return err
}
// Commit writes all changes to disk.
func (n *node) Commit() error {
if n.tx == nil {
return ErrNotInTransaction
}
err := n.tx.Commit()
if err == bolt.ErrTxClosed {
return ErrNotInTransaction
}
return err
}