diff options
author | Dieter Eickstaedt <eickstaedt@deicon.de> | 2023-10-04 20:13:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-04 18:13:29 +0000 |
commit | f25681d8b1acb49758e1c884e7a11a68df1d4a11 (patch) | |
tree | 8f26808dd387957aab659eda658b9bb3c944e0c2 /atuin-client/src/database.rs | |
parent | 573ff69749f6fa75b46780cdc3d2d438c528b082 (diff) |
Fix/1207 deleted entries shown in interactive search (#1272)
Diffstat (limited to 'atuin-client/src/database.rs')
-rw-r--r-- | atuin-client/src/database.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index 1a3dea16f..c75a32ceb 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -80,16 +80,17 @@ pub trait Database: Send + Sync + 'static { context: &Context, max: Option<usize>, unique: bool, + include_deleted: bool, ) -> Result<Vec<History>>; async fn range(&self, from: OffsetDateTime, to: OffsetDateTime) -> Result<Vec<History>>; async fn update(&self, h: &History) -> Result<()>; - async fn history_count(&self) -> Result<i64>; + async fn history_count(&self, include_deleted: bool) -> Result<i64>; async fn last(&self) -> Result<Option<History>>; async fn before(&self, timestamp: OffsetDateTime, count: i64) -> Result<Vec<History>>; - async fn delete(&self, mut h: History) -> Result<()>; + async fn delete(&self, h: History) -> Result<()>; async fn deleted(&self) -> Result<Vec<History>>; // Yes I know, it's a lot. @@ -257,11 +258,15 @@ impl Database for Sqlite { context: &Context, max: Option<usize>, unique: bool, + include_deleted: bool, ) -> Result<Vec<History>> { debug!("listing history"); let mut query = SqlBuilder::select_from(SqlName::new("history").alias("h").baquoted()); query.field("*").order_desc("timestamp"); + if !include_deleted { + query.and_where_is_null("deleted_at"); + } match filter { FilterMode::Global => &mut query, @@ -340,11 +345,13 @@ impl Database for Sqlite { Ok(res) } - async fn history_count(&self) -> Result<i64> { - let res: (i64,) = sqlx::query_as("select count(1) from history") - .fetch_one(&self.pool) - .await?; - + async fn history_count(&self, include_deleted: bool) -> Result<i64> { + let exclude_deleted: &str = if include_deleted { "" } else { "not" }; + let query = format!( + "select count(1) from history where deleted_at is {} null", + exclude_deleted + ); + let res: (i64,) = sqlx::query_as(&query).fetch_one(&self.pool).await?; Ok(res.0) } |