From aa5c7e7d1a0787dd07ff4f901ed0321c7005debb Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Fri, 27 Dec 2024 15:21:45 +0000 Subject: feat: add `atuin wrapped` (#2493) * wip * wip * final * fix clippy * do not hard code the year * support tz properly, allow specifying the year --- crates/atuin-client/src/database.rs | 80 ++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'crates/atuin-client/src') diff --git a/crates/atuin-client/src/database.rs b/crates/atuin-client/src/database.rs index 4f126030..5bdbb75c 100644 --- a/crates/atuin-client/src/database.rs +++ b/crates/atuin-client/src/database.rs @@ -760,6 +760,46 @@ impl Database for Sqlite { } } +trait SqlBuilderExt { + fn fuzzy_condition( + &mut self, + field: S, + mask: T, + inverse: bool, + glob: bool, + is_or: bool, + ) -> &mut Self; +} + +impl SqlBuilderExt for SqlBuilder { + /// adapted from the sql-builder *like functions + fn fuzzy_condition( + &mut self, + field: S, + mask: T, + inverse: bool, + glob: bool, + is_or: bool, + ) -> &mut Self { + let mut cond = field.to_string(); + if inverse { + cond.push_str(" NOT"); + } + if glob { + cond.push_str(" GLOB '"); + } else { + cond.push_str(" LIKE '"); + } + cond.push_str(&esc(mask.to_string())); + cond.push('\''); + if is_or { + self.or_where(cond) + } else { + self.and_where(cond) + } + } +} + #[cfg(test)] mod test { use crate::settings::test_local_timeout; @@ -1105,43 +1145,3 @@ mod test { assert!(duration < Duration::from_secs(15)); } } - -trait SqlBuilderExt { - fn fuzzy_condition( - &mut self, - field: S, - mask: T, - inverse: bool, - glob: bool, - is_or: bool, - ) -> &mut Self; -} - -impl SqlBuilderExt for SqlBuilder { - /// adapted from the sql-builder *like functions - fn fuzzy_condition( - &mut self, - field: S, - mask: T, - inverse: bool, - glob: bool, - is_or: bool, - ) -> &mut Self { - let mut cond = field.to_string(); - if inverse { - cond.push_str(" NOT"); - } - if glob { - cond.push_str(" GLOB '"); - } else { - cond.push_str(" LIKE '"); - } - cond.push_str(&esc(mask.to_string())); - cond.push('\''); - if is_or { - self.or_where(cond) - } else { - self.and_where(cond) - } - } -} -- cgit v1.3.1