ForEach executes a function for each key/value pair in a bucket. Because ForEach uses a Cursor, the iteration over keys is in lexicographical order. If the provided function returns an error then the iteration is stopped and the error is returned to the caller. The provided function must not modify
(fn func(k, v []byte) error)
| 583 | // the error is returned to the caller. The provided function must not modify |
| 584 | // the bucket; this will result in undefined behavior. |
| 585 | func (b *Bucket) ForEach(fn func(k, v []byte) error) error { |
| 586 | if b.tx.db == nil { |
| 587 | return errors.ErrTxClosed |
| 588 | } |
| 589 | c := b.Cursor() |
| 590 | for k, v := c.First(); k != nil; k, v = c.Next() { |
| 591 | if err := fn(k, v); err != nil { |
| 592 | return err |
| 593 | } |
| 594 | } |
| 595 | return nil |
| 596 | } |
| 597 | |
| 598 | func (b *Bucket) ForEachBucket(fn func(k []byte) error) error { |
| 599 | if b.tx.db == nil { |