use crate::error::OxenError;
use bytevec::ByteDecodable;
use rocksdb::{IteratorMode, LogLevel, Options, DB};
use std::path::Path;
use std::str;
pub fn inspect(path: &Path) -> Result<(), OxenError> {
let mut opts = Options::default();
opts.set_log_level(LogLevel::Fatal);
let db = DB::open_for_read_only(&opts, dunce::simplified(path), false)?;
let iter = db.iterator(IteratorMode::Start);
for item in iter {
match item {
Ok((key, value)) => {
if let (Ok(key), Ok(value)) = (str::from_utf8(&key), u32::decode::<u8>(&value)) {
println!("{key}\t{value}")
} else if let (Ok(key), Ok(value)) = (str::from_utf8(&key), str::from_utf8(&value))
{
println!("{key}\t{value}")
}
}
_ => {
return Err(OxenError::basic_str(
"Could not read iterate over db values",
));
}
}
}
Ok(())
}