aboutsummaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/yt/src/commands/database/implm.rs35
-rw-r--r--crates/yt/src/commands/database/mod.rs28
2 files changed, 63 insertions, 0 deletions
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::<video::Operation>::get(app).await?;
+ display_log(&log);
+ }
+ super::OperationType::Subscription => {
+ let log = TxnLog::<subscription::Operation>::get(app).await?;
+ display_log(&log);
+ }
+ },
+ }
+
+ Ok(())
+ }
+}
+
+fn display_log<O: Committable>(log: &TxnLog<O>) {
+ 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 {
+ <Self as fmt::Debug>::fmt(self, f)
+ }
+}