Implement --prefix for the DB inspector
This commit is contained in:
parent
3d3ab4a580
commit
f8756e1359
|
@ -1,4 +1,5 @@
|
|||
use clap::Parser;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
|
@ -85,13 +86,22 @@ impl<T: Debug> Inspectable for MdbxBare<T> {
|
|||
}
|
||||
}
|
||||
|
||||
fn inspect<'a, IV: Inspectable + TableObject<'a>>(
|
||||
fn inspect<'a, IV: Inspectable + TableObject<'a> + 'static>(
|
||||
key: &str,
|
||||
prefix: bool,
|
||||
database: &Database<'a>,
|
||||
txn: &'a RakerTxn<'a, RO>,
|
||||
) -> anyhow::Result<()> {
|
||||
if prefix {
|
||||
let mut cur = txn.mdbx_txn.cursor(database)?;
|
||||
for item in cur.iter_from::<Cow<'_, [u8]>, IV>(key.as_bytes()) {
|
||||
let (k, v) = item?;
|
||||
if !k.starts_with(key.as_bytes()) {
|
||||
break;
|
||||
}
|
||||
println!("• {}", std::str::from_utf8(&k).unwrap_or("<Not UTF-8>"));
|
||||
println!(" = {}", v.inspect());
|
||||
}
|
||||
} else {
|
||||
if let Some(entry) = txn.mdbx_txn.get::<IV>(database, key.as_bytes())? {
|
||||
println!("{}", entry.inspect());
|
||||
|
|
Loading…
Reference in New Issue