From 716c7722cda29bf612508bb96f51822a86e0f69e Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Sat, 20 Mar 2021 00:50:31 +0000 Subject: Add TUI, resolve #19, #17, #16 (#21) --- src/local/database.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/local/database.rs') diff --git a/src/local/database.rs b/src/local/database.rs index 0c31566d..cba7142c 100644 --- a/src/local/database.rs +++ b/src/local/database.rs @@ -15,12 +15,17 @@ pub enum QueryParam { pub trait Database { fn save(&mut self, h: &History) -> Result<()>; fn save_bulk(&mut self, h: &[History]) -> Result<()>; + fn load(&self, id: &str) -> Result; fn list(&self) -> Result>; fn range(&self, from: chrono::DateTime, to: chrono::DateTime) -> Result>; - fn update(&self, h: &History) -> Result<()>; + fn query(&self, query: &str, params: &[QueryParam]) -> Result>; + fn update(&self, h: &History) -> Result<()>; + fn history_count(&self) -> Result; + + fn prefix_search(&self, query: &str) -> Result>; } // Intended for use on a developer machine and not a sync server. @@ -199,6 +204,21 @@ impl Database for Sqlite { Ok(history_iter.filter_map(Result::ok).collect()) } + + fn prefix_search(&self, query: &str) -> Result> { + self.query( + "select * from history where command like ?1 || '%' order by timestamp asc", + &[QueryParam::Text(query.to_string())], + ) + } + + fn history_count(&self) -> Result { + let res: i64 = + self.conn + .query_row_and_then("select count(1) from history;", params![], |row| row.get(0))?; + + Ok(res) + } } fn history_from_sqlite_row( -- cgit v1.3.1