update gets a writable bolt db transaction either from the context or starts a new one with the provided bolt database.
(ctx context.Context, db Transactor, fn func(*bolt.Tx) error)
| 45 | // update gets a writable bolt db transaction either from the context |
| 46 | // or starts a new one with the provided bolt database. |
| 47 | func update(ctx context.Context, db Transactor, fn func(*bolt.Tx) error) error { |
| 48 | tx, ok := boltutil.Transaction(ctx) |
| 49 | if !ok { |
| 50 | return db.Update(fn) |
| 51 | } else if !tx.Writable() { |
| 52 | return fmt.Errorf("unable to use transaction from context: %w", errbolt.ErrTxNotWritable) |
| 53 | } |
| 54 | return fn(tx) |
| 55 | } |
no test coverage detected
searching dependent graphs…