mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [NOD-885] Create database.Key type * [NOD-885] Rename FullKey()->FullKeyBytes() and Key()->KeyBytes() * [NOD-885] Make Key.String return a hex string * [NOD-885] Rename key parts * [NOD-885] Rename separator->bucketSeparator * [NOD-885] Rename SuffixBytes->Suffix and PrefixBytes->Prefix * [NOD-885] Change comments * [NOD-885] Change key prefix to bucket * [NOD-885] Don't use database.NewKey inside dbaccess * [NOD-885] Fix nil bug in Bucket.Path() * [NOD-885] Rename helpers.go -> keys.go * [NOD-885] Unexport database.NewKey * [NOD-885] Remove redundant code in Bucket.Path()
39 lines
717 B
Go
39 lines
717 B
Go
package dbaccess
|
|
|
|
import "github.com/kaspanet/kaspad/database"
|
|
|
|
func clearBucket(dbTx *TxContext, bucket *database.Bucket) error {
|
|
accessor, err := dbTx.accessor()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Collect all of the keys before deleting them. We do this
|
|
// as to not modify the cursor while we're still iterating
|
|
// over it.
|
|
keys := make([]*database.Key, 0)
|
|
cursor, err := accessor.Cursor(bucket)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer cursor.Close()
|
|
|
|
for cursor.Next() {
|
|
key, err := cursor.Key()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
keys = append(keys, key)
|
|
}
|
|
|
|
// Delete all of the keys
|
|
for _, key := range keys {
|
|
err := accessor.Delete(key)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|