gluesql_core/query_builder/expr/
regex.rs1use super::ExprNode;
2
3impl ExprNode<'_> {
4 #[must_use]
5 pub fn regex<T: Into<Self>>(self, pattern: T) -> Self {
6 Self::Regex {
7 expr: Box::new(self),
8 negated: false,
9 pattern: Box::new(pattern.into()),
10 case_sensitive: true,
11 }
12 }
13
14 #[must_use]
15 pub fn iregex<T: Into<Self>>(self, pattern: T) -> Self {
16 Self::Regex {
17 expr: Box::new(self),
18 negated: false,
19 pattern: Box::new(pattern.into()),
20 case_sensitive: false,
21 }
22 }
23
24 #[must_use]
25 pub fn not_regex<T: Into<Self>>(self, pattern: T) -> Self {
26 Self::Regex {
27 expr: Box::new(self),
28 negated: true,
29 pattern: Box::new(pattern.into()),
30 case_sensitive: true,
31 }
32 }
33
34 #[must_use]
35 pub fn not_iregex<T: Into<Self>>(self, pattern: T) -> Self {
36 Self::Regex {
37 expr: Box::new(self),
38 negated: true,
39 pattern: Box::new(pattern.into()),
40 case_sensitive: false,
41 }
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use crate::query_builder::{col, test_expr, text};
48
49 #[test]
50 fn regex() {
51 test_expr(col("name").regex(text("a")), "name ~ 'a'");
52 test_expr(col("name").iregex(text("a")), "name ~* 'a'");
53 test_expr(col("name").not_regex(text("a")), "name !~ 'a'");
54 test_expr(col("name").not_iregex(text("a")), "name !~* 'a'");
55 }
56}