diff options
Diffstat (limited to 'crates/atuin-client/src/database.rs')
| -rw-r--r-- | crates/atuin-client/src/database.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/crates/atuin-client/src/database.rs b/crates/atuin-client/src/database.rs index de362766..06f0bbb8 100644 --- a/crates/atuin-client/src/database.rs +++ b/crates/atuin-client/src/database.rs @@ -119,6 +119,8 @@ pub trait Database: Send + Sync + 'static { async fn all_with_count(&self) -> Result<Vec<(History, i32)>>; async fn stats(&self, h: &History) -> Result<HistoryStats>; + + async fn get_dups(&self, before: i64, dupkeep: u32) -> Result<Vec<History>>; } // Intended for use on a developer machine and not a sync server. @@ -768,6 +770,26 @@ impl Database for Sqlite { duration_over_time, }) } + + async fn get_dups(&self, before: i64, dupkeep: u32) -> Result<Vec<History>> { + let res = sqlx::query( + "SELECT * FROM ( + SELECT *, ROW_NUMBER() + OVER (PARTITION BY command, cwd, hostname ORDER BY timestamp DESC) + AS rn + FROM history + ) sub + WHERE rn > ?1 and timestamp < ?2; + ", + ) + .bind(dupkeep) + .bind(before) + .map(Self::query_history) + .fetch_all(&self.pool) + .await?; + + Ok(res) + } } trait SqlBuilderExt { |
