diff options
| author | Ellie Huxtable <e@elm.sh> | 2021-02-14 22:12:35 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-14 22:12:35 +0000 |
| commit | 851285225fce83bd63410d44e106df0c2a4a4733 (patch) | |
| tree | 943681c16d49a464dbc1ac80441a37572c271b47 /src/local | |
| parent | zsh bin is sometimes /usr/bin/zsh or might be elsewhere too (#8) (diff) | |
| download | atuin-851285225fce83bd63410d44e106df0c2a4a4733.zip | |
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
Diffstat (limited to 'src/local')
| -rw-r--r-- | src/local/database.rs | 20 |
1 files changed, 13 insertions, 7 deletions
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<History>; fn list(&self) -> Result<Vec<History>>; - fn since(&self, date: chrono::DateTime<Utc>) -> Result<Vec<History>>; + fn range(&self, from: chrono::DateTime<Utc>, to: chrono::DateTime<Utc>) + -> Result<Vec<History>>; 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<Utc>) -> Result<Vec<History>> { - debug!("listing history since {:?}", date); + fn range( + &self, + from: chrono::DateTime<Utc>, + to: chrono::DateTime<Utc>, + ) -> Result<Vec<History>> { + 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()) } |
