mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: use Table::TABLE in more places (#6563)
This commit is contained in:
@ -158,19 +158,19 @@ where
|
||||
T::Key: Hash,
|
||||
T::Value: PartialEq,
|
||||
{
|
||||
let table_name = T::NAME;
|
||||
let table = T::TABLE;
|
||||
|
||||
info!("Analyzing table {table_name}...");
|
||||
info!("Analyzing table {table}...");
|
||||
let result = find_diffs_advanced::<T>(&primary_tx, &secondary_tx)?;
|
||||
info!("Done analyzing table {table_name}!");
|
||||
info!("Done analyzing table {table}!");
|
||||
|
||||
// Pretty info summary header: newline then header
|
||||
info!("");
|
||||
info!("Diff results for {table_name}:");
|
||||
info!("Diff results for {table}:");
|
||||
|
||||
// create directory and open file
|
||||
fs::create_dir_all(output_dir.as_ref())?;
|
||||
let file_name = format!("{table_name}.txt");
|
||||
let file_name = format!("{table}.txt");
|
||||
let mut file = File::create(output_dir.as_ref().join(file_name.clone()))?;
|
||||
|
||||
// analyze the result and print some stats
|
||||
@ -178,36 +178,36 @@ where
|
||||
let extra_elements = result.extra_elements.len();
|
||||
|
||||
// Make a pretty summary header for the table
|
||||
writeln!(file, "Diff results for {table_name}")?;
|
||||
writeln!(file, "Diff results for {table}")?;
|
||||
|
||||
if discrepancies > 0 {
|
||||
// write to file
|
||||
writeln!(file, "Found {discrepancies} discrepancies in table {table_name}")?;
|
||||
writeln!(file, "Found {discrepancies} discrepancies in table {table}")?;
|
||||
|
||||
// also print to info
|
||||
info!("Found {discrepancies} discrepancies in table {table_name}");
|
||||
info!("Found {discrepancies} discrepancies in table {table}");
|
||||
} else {
|
||||
// write to file
|
||||
writeln!(file, "No discrepancies found in table {table_name}")?;
|
||||
writeln!(file, "No discrepancies found in table {table}")?;
|
||||
|
||||
// also print to info
|
||||
info!("No discrepancies found in table {table_name}");
|
||||
info!("No discrepancies found in table {table}");
|
||||
}
|
||||
|
||||
if extra_elements > 0 {
|
||||
// write to file
|
||||
writeln!(file, "Found {extra_elements} extra elements in table {table_name}")?;
|
||||
writeln!(file, "Found {extra_elements} extra elements in table {table}")?;
|
||||
|
||||
// also print to info
|
||||
info!("Found {extra_elements} extra elements in table {table_name}");
|
||||
info!("Found {extra_elements} extra elements in table {table}");
|
||||
} else {
|
||||
writeln!(file, "No extra elements found in table {table_name}")?;
|
||||
writeln!(file, "No extra elements found in table {table}")?;
|
||||
|
||||
// also print to info
|
||||
info!("No extra elements found in table {table_name}");
|
||||
info!("No extra elements found in table {table}");
|
||||
}
|
||||
|
||||
info!("Writing diff results for {table_name} to {file_name}...");
|
||||
info!("Writing diff results for {table} to {file_name}...");
|
||||
|
||||
if discrepancies > 0 {
|
||||
writeln!(file, "Discrepancies:")?;
|
||||
@ -226,7 +226,7 @@ where
|
||||
}
|
||||
|
||||
let full_file_name = output_dir.as_ref().join(file_name);
|
||||
info!("Done writing diff results for {table_name} to {}", full_file_name.display());
|
||||
info!("Done writing diff results for {table} to {}", full_file_name.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@ -31,23 +31,20 @@ pub struct Command {
|
||||
impl Command {
|
||||
/// Execute `db get` command
|
||||
pub fn execute<DB: Database>(self, tool: &DbTool<'_, DB>) -> eyre::Result<()> {
|
||||
self.table.view(&GetValueViewer { tool, args: &self })?;
|
||||
|
||||
Ok(())
|
||||
self.table.view(&GetValueViewer { tool, args: &self })
|
||||
}
|
||||
|
||||
/// Get an instance of key for given table
|
||||
pub fn table_key<T: Table>(&self) -> Result<T::Key, eyre::Error> {
|
||||
assert_eq!(T::NAME, self.table.name());
|
||||
|
||||
serde_json::from_str::<T::Key>(&self.key).map_err(|e| eyre::eyre!(e))
|
||||
assert_eq!(T::TABLE, self.table);
|
||||
serde_json::from_str::<T::Key>(&self.key).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Get an instance of subkey for given dupsort table
|
||||
fn table_subkey<T: DupSort>(&self) -> Result<T::SubKey, eyre::Error> {
|
||||
assert_eq!(T::NAME, self.table.name());
|
||||
assert_eq!(T::TABLE, self.table);
|
||||
serde_json::from_str::<T::SubKey>(&self.subkey.clone().unwrap_or_default())
|
||||
.map_err(|e| eyre::eyre!(e))
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user