kvdb: add ForAll

A new method to allow efficient range queries for backends that support
it.
This commit is contained in:
Joost Jager
2021-12-24 11:29:16 +01:00
parent 102a1cbaaa
commit b8408a1484
7 changed files with 114 additions and 3 deletions

View File

@@ -159,7 +159,20 @@ func testBucketDeletion(t *testing.T, db walletdb.DB) {
require.Nil(t, err)
}
type bucketIterator = func(walletdb.ReadWriteBucket,
func(key, val []byte) error) error
func testBucketForEach(t *testing.T, db walletdb.DB) {
testBucketIterator(t, db, func(bucket walletdb.ReadWriteBucket,
callback func(key, val []byte) error) error {
return bucket.ForEach(callback)
})
}
func testBucketIterator(t *testing.T, db walletdb.DB,
iterator bucketIterator) {
err := Update(db, func(tx walletdb.ReadWriteTx) error {
// "apple"
apple, err := tx.CreateTopLevelBucket([]byte("apple"))
@@ -199,7 +212,7 @@ func testBucketForEach(t *testing.T, db walletdb.DB) {
require.Equal(t, expected, got)
got = make(map[string]string)
err = banana.ForEach(func(key, val []byte) error {
err = iterator(banana, func(key, val []byte) error {
got[string(key)] = string(val)
return nil
})