about summary refs log tree commit diff stats
path: root/crates
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-24 16:09:15 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-24 16:09:15 +0200
commit761560fe7b3d2e5cbc1fd942ea7bb84d440459fe (patch)
treeeadc52cb03862e15c4cd47d6294c44ec8d6a2111 /crates
parentfeat(crates/yt/storage/db/insert): Track all inserted operations (diff)
downloadyt-761560fe7b3d2e5cbc1fd942ea7bb84d440459fe.zip
feat(crates/yt/commands/database): Init, to show the txn_log
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)
+    }
+}