aboutsummaryrefslogtreecommitdiff
path: root/kv/src/bin/rocksdb_remove_prefix.rs
diff options
context:
space:
mode:
Diffstat (limited to 'kv/src/bin/rocksdb_remove_prefix.rs')
-rw-r--r--kv/src/bin/rocksdb_remove_prefix.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/kv/src/bin/rocksdb_remove_prefix.rs b/kv/src/bin/rocksdb_remove_prefix.rs
new file mode 100644
index 0000000..e09ce61
--- /dev/null
+++ b/kv/src/bin/rocksdb_remove_prefix.rs
@@ -0,0 +1,25 @@
+/*
+ This file is part of jellything (https://codeberg.org/metamuffin/jellything)
+ which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
+ Copyright (C) 2026 metamuffin <metamuffin.org>
+*/
+
+use anyhow::Result;
+use rocksdb::DB;
+use std::env::args;
+
+fn main() -> Result<()> {
+ let db = DB::open_default(args().nth(1).unwrap())?;
+ let prefix = args().nth(2).unwrap();
+ for r in db.prefix_iterator(&prefix) {
+ let key = r?.0;
+ let key_s = String::from_utf8_lossy(&key);
+ if !key_s.starts_with(&prefix) {
+ break;
+ }
+ println!("{key_s}");
+ db.delete(key)?;
+ }
+ db.flush()?;
+ Ok(())
+}