auction key iterator

master
michael 2022-08-31 18:43:45 +00:00
parent d6b4b51ca6
commit 05144c4e06
1 changed files with 20 additions and 0 deletions

View File

@ -152,3 +152,23 @@ func (b *bidDB) ClearAuction(auctionId string) error {
return err return err
} }
// Iterate over all auction keys in memory. VIEW-ONLY.
func (b *bidDB) ForEachAuction(viewFunc func(string) error) error {
err := b.db.View(func(txn *badger.Txn) error {
opts := badger.DefaultIteratorOptions
// can customize options down here if we want
iter := txn.NewIterator(opts)
defer iter.Close()
for iter.Rewind(); iter.Valid(); iter.Next() {
item := iter.Item()
key := string(item.Key())
err := viewFunc(key)
if err != nil {
return err
}
}
return nil
})
return err
}