aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-client/src/database.rs
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@atuin.sh>2024-12-27 15:21:45 +0000
committerGitHub <noreply@github.com>2024-12-27 15:21:45 +0000
commitaa5c7e7d1a0787dd07ff4f901ed0321c7005debb (patch)
tree1488254dfd47287ab7d5443f4deabce8b206e7c6 /crates/atuin-client/src/database.rs
parentchore(release): prepare for release 18.4.0-beta.5 (#2472) (diff)
downloadatuin-aa5c7e7d1a0787dd07ff4f901ed0321c7005debb.zip
feat: add `atuin wrapped` (#2493)
* wip * wip * final * fix clippy * do not hard code the year * support tz properly, allow specifying the year
Diffstat (limited to '')
-rw-r--r--crates/atuin-client/src/database.rs80
1 files changed, 40 insertions, 40 deletions
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<S: ToString, T: ToString>(
+ &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<S: ToString, T: ToString>(
+ &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<S: ToString, T: ToString>(
- &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<S: ToString, T: ToString>(
- &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)
- }
- }
-}