From 761560fe7b3d2e5cbc1fd942ea7bb84d440459fe Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 24 Jul 2025 16:09:15 +0200 Subject: feat(crates/yt/commands/database): Init, to show the txn_log --- crates/yt/src/commands/database/implm.rs | 35 ++++++++++++++++++++++++++++++++ crates/yt/src/commands/database/mod.rs | 28 +++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 crates/yt/src/commands/database/implm.rs create mode 100644 crates/yt/src/commands/database/mod.rs (limited to 'crates') diff --git a/crates/yt/src/commands/database/implm.rs b/crates/yt/src/commands/database/implm.rs new file mode 100644 index 0000000..0caaeb2 --- /dev/null +++ b/crates/yt/src/commands/database/implm.rs @@ -0,0 +1,35 @@ +use crate::{ + app::App, + commands::DatabaseCommand, + storage::db::{ + insert::{Committable, subscription, video}, + txn_log::TxnLog, + }, +}; + +use anyhow::Result; + +impl DatabaseCommand { + pub(crate) async fn implm(&self, app: &App) -> Result<()> { + match self { + DatabaseCommand::Log { kind } => match kind { + super::OperationType::Video => { + let log = TxnLog::::get(app).await?; + display_log(&log); + } + super::OperationType::Subscription => { + let log = TxnLog::::get(app).await?; + display_log(&log); + } + }, + } + + Ok(()) + } +} + +fn display_log(log: &TxnLog) { + for (time, value) in log.inner() { + println!("At {time}: {value:?}"); + } +} diff --git a/crates/yt/src/commands/database/mod.rs b/crates/yt/src/commands/database/mod.rs new file mode 100644 index 0000000..b391686 --- /dev/null +++ b/crates/yt/src/commands/database/mod.rs @@ -0,0 +1,28 @@ +use std::fmt::{self, Display}; + +use clap::{Subcommand, ValueEnum}; + +mod implm; + +#[derive(Subcommand, Debug)] +pub(super) enum DatabaseCommand { + /// Show the history of operations, in they groups they were committed in. + Log { + /// What kind of operation to show. + #[arg(short, long, default_value_t)] + kind: OperationType, + }, +} + +#[derive(Debug, Clone, Copy, ValueEnum, Default)] +pub(super) enum OperationType { + #[default] + Video, + Subscription, +} + +impl Display for OperationType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + ::fmt(self, f) + } +} -- cgit 1.4.1