Implement --prefix for the DB inspector
This commit is contained in:
parent
3d3ab4a580
commit
f8756e1359
|
@ -1,4 +1,5 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use std::fmt::Debug;
|
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,
|
key: &str,
|
||||||
prefix: bool,
|
prefix: bool,
|
||||||
database: &Database<'a>,
|
database: &Database<'a>,
|
||||||
txn: &'a RakerTxn<'a, RO>,
|
txn: &'a RakerTxn<'a, RO>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
if prefix {
|
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 {
|
} else {
|
||||||
if let Some(entry) = txn.mdbx_txn.get::<IV>(database, key.as_bytes())? {
|
if let Some(entry) = txn.mdbx_txn.get::<IV>(database, key.as_bytes())? {
|
||||||
println!("{}", entry.inspect());
|
println!("{}", entry.inspect());
|
||||||
|
|
Loading…
Reference in New Issue