From 851285225fce83bd63410d44e106df0c2a4a4733 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Sun, 14 Feb 2021 22:12:35 +0000 Subject: Add stats command (#9) * Add stats command For example atuin stats day yesterday atuin stats day last friday atuin stats day 01/01/21 * Output tables, fix import blanks --- src/local/database.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/local') diff --git a/src/local/database.rs b/src/local/database.rs index 8e4b00ef..5b98bb36 100644 --- a/src/local/database.rs +++ b/src/local/database.rs @@ -13,7 +13,8 @@ pub trait Database { fn save_bulk(&mut self, h: &[History]) -> Result<()>; fn load(&self, id: &str) -> Result; fn list(&self) -> Result>; - fn since(&self, date: chrono::DateTime) -> Result>; + fn range(&self, from: chrono::DateTime, to: chrono::DateTime) + -> Result>; fn update(&self, h: &History) -> Result<()>; } @@ -157,16 +158,21 @@ impl Database for Sqlite { Ok(history_iter.filter_map(Result::ok).collect()) } - fn since(&self, date: chrono::DateTime) -> Result> { - debug!("listing history since {:?}", date); + fn range( + &self, + from: chrono::DateTime, + to: chrono::DateTime, + ) -> Result> { + debug!("listing history from {:?} to {:?}", from, to); let mut stmt = self.conn.prepare( - "SELECT distinct command FROM history where timestamp > ?1 order by timestamp asc", + "SELECT * FROM history where timestamp >= ?1 and timestamp <= ?2 order by timestamp asc", )?; - let history_iter = stmt.query_map(params![date.timestamp_nanos()], |row| { - history_from_sqlite_row(None, row) - })?; + let history_iter = stmt.query_map( + params![from.timestamp_nanos(), to.timestamp_nanos()], + |row| history_from_sqlite_row(None, row), + )?; Ok(history_iter.filter_map(Result::ok).collect()) } -- cgit v1.3.1