BadgerDatabase Has

This commit is contained in:
andrew 2019-11-12 11:40:46 +01:00
parent 81d0d84ed4
commit 109217a9da
3 changed files with 14 additions and 3 deletions

View File

@ -189,7 +189,7 @@ func (db *BadgerDatabase) DeleteTimestamp(timestamp uint64) error {
})
}
// GetS returns the value that was put into a given historical bucket for an exact timestamp.
// GetS returns the value that was recorded in a given historical bucket for an exact timestamp.
func (db *BadgerDatabase) GetS(hBucket, key []byte, timestamp uint64) ([]byte, error) {
composite, _ := dbutils.CompositeKeySuffix(key, timestamp)
return db.Get(hBucket, composite)
@ -228,4 +228,13 @@ func (db *BadgerDatabase) GetAsOf(bucket, hBucket, key []byte, timestamp uint64)
return dat, err
}
// Has indicates whether a key exists in the database.
func (db *BadgerDatabase) Has(bucket, key []byte) (bool, error) {
_, err := db.Get(bucket, key)
if err == ErrKeyNotFound {
return false, nil
}
return err == nil, err
}
// TODO [Andrew] implement the full Database interface

View File

@ -182,7 +182,7 @@ func (db *BoltDatabase) Get(bucket, key []byte) ([]byte, error) {
return dat, err
}
// GetS returns the value that was put into a given historical bucket for an exact timestamp.
// GetS returns the value that was recorded in a given historical bucket for an exact timestamp.
func (db *BoltDatabase) GetS(hBucket, key []byte, timestamp uint64) ([]byte, error) {
composite, _ := dbutils.CompositeKeySuffix(key, timestamp)
return db.Get(hBucket, composite)

View File

@ -42,7 +42,7 @@ type Getter interface {
// Get returns the value for a given key if it's present.
Get(bucket, key []byte) ([]byte, error)
// GetS returns the value that was put into a given historical bucket for an exact timestamp.
// GetS returns the value that was recorded in a given historical bucket for an exact timestamp.
// timestamp == block number
GetS(hBucket, key []byte, timestamp uint64) ([]byte, error)
@ -50,7 +50,9 @@ type Getter interface {
// timestamp == block number
GetAsOf(bucket, hBucket, key []byte, timestamp uint64) ([]byte, error)
// Has indicates whether a key exists in the database.
Has(bucket, key []byte) (bool, error)
Walk(bucket, startkey []byte, fixedbits uint, walker func([]byte, []byte) (bool, error)) error
MultiWalk(bucket []byte, startkeys [][]byte, fixedbits []uint, walker func(int, []byte, []byte) (bool, error)) error
WalkAsOf(bucket, hBucket, startkey []byte, fixedbits uint, timestamp uint64, walker func([]byte, []byte) (bool, error)) error