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

@@ -84,7 +84,35 @@ func TestPostgres(t *testing.T) {
},
{
name: "bucket for each",
test: testBucketForEach,
test: func(t *testing.T, db walletdb.DB) {
testBucketIterator(t, db, func(bucket walletdb.ReadWriteBucket,
callback func(key, val []byte) error) error {
return bucket.ForEach(callback)
})
},
expectedDb: m{
"test_kv": []m{
{"id": int64(1), "key": "apple", "parent_id": nil, "sequence": nil, "value": nil},
{"id": int64(2), "key": "banana", "parent_id": int64(1), "sequence": nil, "value": nil},
{"id": int64(3), "key": "key1", "parent_id": int64(1), "sequence": nil, "value": "val1"},
{"id": int64(4), "key": "key1", "parent_id": int64(2), "sequence": nil, "value": "val1"},
{"id": int64(5), "key": "key2", "parent_id": int64(1), "sequence": nil, "value": "val2"},
{"id": int64(6), "key": "key2", "parent_id": int64(2), "sequence": nil, "value": "val2"},
{"id": int64(7), "key": "key3", "parent_id": int64(1), "sequence": nil, "value": "val3"},
{"id": int64(8), "key": "key3", "parent_id": int64(2), "sequence": nil, "value": "val3"},
},
},
},
{
name: "bucket for all",
test: func(t *testing.T, db walletdb.DB) {
testBucketIterator(t, db, func(bucket walletdb.ReadWriteBucket,
callback func(key, val []byte) error) error {
return ForAll(bucket, callback)
})
},
expectedDb: m{
"test_kv": []m{
{"id": int64(1), "key": "apple", "parent_id": nil, "sequence": nil, "value": nil},