1use std::marker::PhantomData;
18
19use sea_query::{Alias, Expr, ExprTrait, Func};
20
21use super::{OrderExpr, Predicate};
22
23pub struct IntCol<T> {
25 pub(crate) name: &'static str,
26 _phantom: PhantomData<T>,
27}
28
29impl<T> IntCol<T> {
30 pub const fn new(name: &'static str) -> Self {
31 Self {
32 name,
33 _phantom: PhantomData,
34 }
35 }
36
37 pub fn eq(&self, val: i64) -> Predicate<T> {
49 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
50 }
51
52 pub fn ne(&self, val: i64) -> Predicate<T> {
54 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
55 }
56
57 pub fn lt(&self, val: i64) -> Predicate<T> {
59 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
60 }
61
62 pub fn le(&self, val: i64) -> Predicate<T> {
64 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
65 }
66
67 pub fn lte(&self, val: i64) -> Predicate<T> {
71 self.le(val)
72 }
73
74 pub fn gt(&self, val: i64) -> Predicate<T> {
76 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
77 }
78
79 pub fn ge(&self, val: i64) -> Predicate<T> {
81 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
82 }
83
84 pub fn gte(&self, val: i64) -> Predicate<T> {
87 self.ge(val)
88 }
89
90 pub fn in_(&self, vals: &[i64]) -> Predicate<T> {
101 Predicate::new(Expr::col(Alias::new(self.name)).is_in(vals.iter().copied()))
102 }
103
104 pub fn in_subquery(&self, sub: super::Subquery) -> Predicate<T> {
108 Predicate::new(Expr::col(Alias::new(self.name)).in_subquery(sub.into_statement()))
109 }
110
111 pub fn asc(&self) -> OrderExpr<T> {
113 OrderExpr::new(self.name, false)
114 }
115
116 pub fn desc(&self) -> OrderExpr<T> {
128 OrderExpr::new(self.name, true)
129 }
130}
131
132pub struct StrCol<T> {
134 pub(crate) name: &'static str,
135 _phantom: PhantomData<T>,
136}
137
138impl<T> StrCol<T> {
139 pub const fn new(name: &'static str) -> Self {
140 Self {
141 name,
142 _phantom: PhantomData,
143 }
144 }
145
146 pub fn eq<S: Into<String>>(&self, val: S) -> Predicate<T> {
157 Predicate::new(Expr::col(Alias::new(self.name)).eq(val.into()))
158 }
159
160 pub fn ne<S: Into<String>>(&self, val: S) -> Predicate<T> {
162 Predicate::new(Expr::col(Alias::new(self.name)).ne(val.into()))
163 }
164
165 pub fn in_<S: AsRef<str>>(&self, vals: &[S]) -> Predicate<T> {
168 Predicate::new(
169 Expr::col(Alias::new(self.name)).is_in(vals.iter().map(|s| s.as_ref().to_string())),
170 )
171 }
172
173 pub fn in_subquery(&self, sub: super::Subquery) -> Predicate<T> {
177 Predicate::new(Expr::col(Alias::new(self.name)).in_subquery(sub.into_statement()))
178 }
179
180 pub fn like<S: Into<String>>(&self, pattern: S) -> Predicate<T> {
191 Predicate::new(Expr::col(Alias::new(self.name)).like(pattern.into()))
192 }
193
194 pub fn ilike<S: Into<String>>(&self, pattern: S) -> Predicate<T> {
206 let pattern = pattern.into().to_uppercase();
207 Predicate::new(Expr::expr(Func::upper(Expr::col(Alias::new(self.name)))).like(pattern))
208 }
209
210 pub fn contains<S: Into<String>>(&self, substring: S) -> Predicate<T> {
221 let pattern = format!("%{}%", super::escape_like_literal(&substring.into()));
222 Predicate::new(
223 Expr::col(Alias::new(self.name)).like(sea_query::LikeExpr::new(pattern).escape('\\')),
224 )
225 }
226
227 pub fn icontains<S: Into<String>>(&self, substring: S) -> Predicate<T> {
243 let pattern = format!("%{}%", super::escape_like_literal(&substring.into())).to_uppercase();
244 Predicate::new(
245 Expr::expr(Func::upper(Expr::col(Alias::new(self.name))))
246 .like(sea_query::LikeExpr::new(pattern).escape('\\')),
247 )
248 }
249
250 pub fn startswith<S: Into<String>>(&self, prefix: S) -> Predicate<T> {
262 let pattern = format!("{}%", super::escape_like_literal(&prefix.into()));
263 Predicate::new(
264 Expr::col(Alias::new(self.name)).like(sea_query::LikeExpr::new(pattern).escape('\\')),
265 )
266 }
267
268 pub fn istartswith<S: Into<String>>(&self, prefix: S) -> Predicate<T> {
270 let pattern = format!("{}%", super::escape_like_literal(&prefix.into())).to_uppercase();
271 Predicate::new(
272 Expr::expr(Func::upper(Expr::col(Alias::new(self.name))))
273 .like(sea_query::LikeExpr::new(pattern).escape('\\')),
274 )
275 }
276
277 pub fn asc(&self) -> OrderExpr<T> {
279 OrderExpr::new(self.name, false)
280 }
281
282 pub fn desc(&self) -> OrderExpr<T> {
284 OrderExpr::new(self.name, true)
285 }
286}
287
288pub struct DateTimeCol<T> {
290 pub(crate) name: &'static str,
291 _phantom: PhantomData<T>,
292}
293
294impl<T> DateTimeCol<T> {
295 pub const fn new(name: &'static str) -> Self {
296 Self {
297 name,
298 _phantom: PhantomData,
299 }
300 }
301
302 pub fn eq(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
304 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
305 }
306
307 pub fn ne(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
309 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
310 }
311
312 pub fn lt(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
314 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
315 }
316
317 pub fn le(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
319 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
320 }
321
322 pub fn lte(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
325 self.le(val)
326 }
327
328 pub fn gt(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
330 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
331 }
332
333 pub fn ge(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
335 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
336 }
337
338 pub fn gte(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
341 self.ge(val)
342 }
343
344 pub fn before(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
346 self.lt(val)
347 }
348
349 pub fn after(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
351 self.gt(val)
352 }
353
354 pub fn asc(&self) -> OrderExpr<T> {
356 OrderExpr::new(self.name, false)
357 }
358
359 pub fn desc(&self) -> OrderExpr<T> {
361 OrderExpr::new(self.name, true)
362 }
363}
364
365pub struct NullableDateTimeCol<T> {
367 pub(crate) name: &'static str,
368 _phantom: PhantomData<T>,
369}
370
371impl<T> NullableDateTimeCol<T> {
372 pub const fn new(name: &'static str) -> Self {
373 Self {
374 name,
375 _phantom: PhantomData,
376 }
377 }
378
379 pub fn eq(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
381 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
382 }
383
384 pub fn ne(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
386 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
387 }
388
389 pub fn lt(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
391 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
392 }
393
394 pub fn le(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
396 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
397 }
398
399 pub fn lte(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
402 self.le(val)
403 }
404
405 pub fn gt(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
407 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
408 }
409
410 pub fn ge(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
412 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
413 }
414
415 pub fn gte(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
418 self.ge(val)
419 }
420
421 pub fn before(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
434 self.lt(val)
435 }
436
437 pub fn after(&self, val: chrono::DateTime<chrono::Utc>) -> Predicate<T> {
439 self.gt(val)
440 }
441
442 pub fn is_null(&self) -> Predicate<T> {
454 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
455 }
456
457 pub fn is_not_null(&self) -> Predicate<T> {
473 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
474 }
475
476 pub fn asc(&self) -> OrderExpr<T> {
478 OrderExpr::new(self.name, false)
479 }
480
481 pub fn desc(&self) -> OrderExpr<T> {
483 OrderExpr::new(self.name, true)
484 }
485}
486
487pub struct NaiveDateTimeCol<T> {
491 pub(crate) name: &'static str,
492 _phantom: PhantomData<T>,
493}
494
495impl<T> NaiveDateTimeCol<T> {
496 pub const fn new(name: &'static str) -> Self {
497 Self {
498 name,
499 _phantom: PhantomData,
500 }
501 }
502
503 pub fn eq(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
505 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
506 }
507
508 pub fn ne(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
510 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
511 }
512
513 pub fn lt(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
515 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
516 }
517
518 pub fn le(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
520 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
521 }
522
523 pub fn lte(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
525 self.le(val)
526 }
527
528 pub fn gt(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
530 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
531 }
532
533 pub fn ge(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
535 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
536 }
537
538 pub fn gte(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
540 self.ge(val)
541 }
542
543 pub fn before(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
545 self.lt(val)
546 }
547
548 pub fn after(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
550 self.gt(val)
551 }
552
553 pub fn asc(&self) -> OrderExpr<T> {
555 OrderExpr::new(self.name, false)
556 }
557
558 pub fn desc(&self) -> OrderExpr<T> {
560 OrderExpr::new(self.name, true)
561 }
562}
563
564pub struct NullableNaiveDateTimeCol<T> {
566 pub(crate) name: &'static str,
567 _phantom: PhantomData<T>,
568}
569
570impl<T> NullableNaiveDateTimeCol<T> {
571 pub const fn new(name: &'static str) -> Self {
572 Self {
573 name,
574 _phantom: PhantomData,
575 }
576 }
577
578 pub fn eq(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
580 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
581 }
582
583 pub fn ne(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
585 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
586 }
587
588 pub fn lt(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
590 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
591 }
592
593 pub fn le(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
595 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
596 }
597
598 pub fn lte(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
600 self.le(val)
601 }
602
603 pub fn gt(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
605 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
606 }
607
608 pub fn ge(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
610 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
611 }
612
613 pub fn gte(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
615 self.ge(val)
616 }
617
618 pub fn before(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
620 self.lt(val)
621 }
622
623 pub fn after(&self, val: chrono::NaiveDateTime) -> Predicate<T> {
625 self.gt(val)
626 }
627
628 pub fn is_null(&self) -> Predicate<T> {
630 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
631 }
632
633 pub fn is_not_null(&self) -> Predicate<T> {
635 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
636 }
637
638 pub fn asc(&self) -> OrderExpr<T> {
640 OrderExpr::new(self.name, false)
641 }
642
643 pub fn desc(&self) -> OrderExpr<T> {
645 OrderExpr::new(self.name, true)
646 }
647}
648
649pub struct F64Col<T> {
667 pub(crate) name: &'static str,
668 _phantom: PhantomData<T>,
669}
670
671impl<T> F64Col<T> {
672 pub const fn new(name: &'static str) -> Self {
673 Self {
674 name,
675 _phantom: PhantomData,
676 }
677 }
678
679 pub fn eq(&self, val: f64) -> Predicate<T> {
681 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
682 }
683
684 pub fn ne(&self, val: f64) -> Predicate<T> {
686 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
687 }
688
689 pub fn lt(&self, val: f64) -> Predicate<T> {
691 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
692 }
693
694 pub fn le(&self, val: f64) -> Predicate<T> {
696 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
697 }
698
699 pub fn lte(&self, val: f64) -> Predicate<T> {
702 self.le(val)
703 }
704
705 pub fn gt(&self, val: f64) -> Predicate<T> {
707 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
708 }
709
710 pub fn ge(&self, val: f64) -> Predicate<T> {
712 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
713 }
714
715 pub fn gte(&self, val: f64) -> Predicate<T> {
718 self.ge(val)
719 }
720
721 pub fn asc(&self) -> OrderExpr<T> {
723 OrderExpr::new(self.name, false)
724 }
725
726 pub fn desc(&self) -> OrderExpr<T> {
728 OrderExpr::new(self.name, true)
729 }
730}
731
732pub struct BoolCol<T> {
734 pub(crate) name: &'static str,
735 _phantom: PhantomData<T>,
736}
737
738impl<T> BoolCol<T> {
739 pub const fn new(name: &'static str) -> Self {
740 Self {
741 name,
742 _phantom: PhantomData,
743 }
744 }
745
746 pub fn eq(&self, val: bool) -> Predicate<T> {
748 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
749 }
750
751 pub fn ne(&self, val: bool) -> Predicate<T> {
753 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
754 }
755
756 pub fn is_true(&self) -> Predicate<T> {
758 self.eq(true)
759 }
760
761 pub fn is_false(&self) -> Predicate<T> {
763 self.eq(false)
764 }
765
766 pub fn asc(&self) -> OrderExpr<T> {
768 OrderExpr::new(self.name, false)
769 }
770
771 pub fn desc(&self) -> OrderExpr<T> {
773 OrderExpr::new(self.name, true)
774 }
775}
776
777pub struct UuidCol<T> {
779 pub(crate) name: &'static str,
780 _phantom: PhantomData<T>,
781}
782
783impl<T> UuidCol<T> {
784 pub const fn new(name: &'static str) -> Self {
785 Self {
786 name,
787 _phantom: PhantomData,
788 }
789 }
790
791 pub fn eq(&self, val: uuid::Uuid) -> Predicate<T> {
793 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
794 }
795
796 pub fn ne(&self, val: uuid::Uuid) -> Predicate<T> {
798 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
799 }
800
801 pub fn in_(&self, vals: &[uuid::Uuid]) -> Predicate<T> {
803 Predicate::new(Expr::col(Alias::new(self.name)).is_in(vals.iter().copied()))
804 }
805
806 pub fn asc(&self) -> OrderExpr<T> {
808 OrderExpr::new(self.name, false)
809 }
810
811 pub fn desc(&self) -> OrderExpr<T> {
813 OrderExpr::new(self.name, true)
814 }
815}
816
817pub struct DateCol<T> {
819 pub(crate) name: &'static str,
820 _phantom: PhantomData<T>,
821}
822
823impl<T> DateCol<T> {
824 pub const fn new(name: &'static str) -> Self {
825 Self {
826 name,
827 _phantom: PhantomData,
828 }
829 }
830
831 pub fn eq(&self, val: chrono::NaiveDate) -> Predicate<T> {
833 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
834 }
835
836 pub fn ne(&self, val: chrono::NaiveDate) -> Predicate<T> {
838 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
839 }
840
841 pub fn lt(&self, val: chrono::NaiveDate) -> Predicate<T> {
843 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
844 }
845
846 pub fn le(&self, val: chrono::NaiveDate) -> Predicate<T> {
848 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
849 }
850
851 pub fn lte(&self, val: chrono::NaiveDate) -> Predicate<T> {
854 self.le(val)
855 }
856
857 pub fn gt(&self, val: chrono::NaiveDate) -> Predicate<T> {
859 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
860 }
861
862 pub fn ge(&self, val: chrono::NaiveDate) -> Predicate<T> {
864 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
865 }
866
867 pub fn gte(&self, val: chrono::NaiveDate) -> Predicate<T> {
870 self.ge(val)
871 }
872
873 pub fn before(&self, val: chrono::NaiveDate) -> Predicate<T> {
875 self.lt(val)
876 }
877
878 pub fn after(&self, val: chrono::NaiveDate) -> Predicate<T> {
880 self.gt(val)
881 }
882
883 pub fn asc(&self) -> OrderExpr<T> {
885 OrderExpr::new(self.name, false)
886 }
887
888 pub fn desc(&self) -> OrderExpr<T> {
890 OrderExpr::new(self.name, true)
891 }
892}
893
894pub struct TimeCol<T> {
896 pub(crate) name: &'static str,
897 _phantom: PhantomData<T>,
898}
899
900impl<T> TimeCol<T> {
901 pub const fn new(name: &'static str) -> Self {
902 Self {
903 name,
904 _phantom: PhantomData,
905 }
906 }
907
908 pub fn eq(&self, val: chrono::NaiveTime) -> Predicate<T> {
910 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
911 }
912
913 pub fn ne(&self, val: chrono::NaiveTime) -> Predicate<T> {
915 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
916 }
917
918 pub fn lt(&self, val: chrono::NaiveTime) -> Predicate<T> {
920 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
921 }
922
923 pub fn le(&self, val: chrono::NaiveTime) -> Predicate<T> {
925 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
926 }
927
928 pub fn lte(&self, val: chrono::NaiveTime) -> Predicate<T> {
931 self.le(val)
932 }
933
934 pub fn gt(&self, val: chrono::NaiveTime) -> Predicate<T> {
936 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
937 }
938
939 pub fn ge(&self, val: chrono::NaiveTime) -> Predicate<T> {
941 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
942 }
943
944 pub fn gte(&self, val: chrono::NaiveTime) -> Predicate<T> {
947 self.ge(val)
948 }
949
950 pub fn before(&self, val: chrono::NaiveTime) -> Predicate<T> {
952 self.lt(val)
953 }
954
955 pub fn after(&self, val: chrono::NaiveTime) -> Predicate<T> {
957 self.gt(val)
958 }
959
960 pub fn asc(&self) -> OrderExpr<T> {
962 OrderExpr::new(self.name, false)
963 }
964
965 pub fn desc(&self) -> OrderExpr<T> {
967 OrderExpr::new(self.name, true)
968 }
969}
970
971pub struct NullableIntCol<T> {
980 pub(crate) name: &'static str,
981 _phantom: PhantomData<T>,
982}
983
984impl<T> NullableIntCol<T> {
985 pub const fn new(name: &'static str) -> Self {
986 Self {
987 name,
988 _phantom: PhantomData,
989 }
990 }
991
992 pub fn eq(&self, val: i64) -> Predicate<T> {
994 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
995 }
996
997 pub fn ne(&self, val: i64) -> Predicate<T> {
999 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
1000 }
1001
1002 pub fn lt(&self, val: i64) -> Predicate<T> {
1004 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
1005 }
1006
1007 pub fn le(&self, val: i64) -> Predicate<T> {
1009 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
1010 }
1011
1012 pub fn lte(&self, val: i64) -> Predicate<T> {
1015 self.le(val)
1016 }
1017
1018 pub fn gt(&self, val: i64) -> Predicate<T> {
1020 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
1021 }
1022
1023 pub fn ge(&self, val: i64) -> Predicate<T> {
1025 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
1026 }
1027
1028 pub fn gte(&self, val: i64) -> Predicate<T> {
1031 self.ge(val)
1032 }
1033
1034 pub fn in_(&self, vals: &[i64]) -> Predicate<T> {
1036 Predicate::new(Expr::col(Alias::new(self.name)).is_in(vals.iter().copied()))
1037 }
1038
1039 pub fn is_null(&self) -> Predicate<T> {
1041 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
1042 }
1043
1044 pub fn is_not_null(&self) -> Predicate<T> {
1046 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
1047 }
1048
1049 pub fn asc(&self) -> OrderExpr<T> {
1051 OrderExpr::new(self.name, false)
1052 }
1053
1054 pub fn desc(&self) -> OrderExpr<T> {
1056 OrderExpr::new(self.name, true)
1057 }
1058}
1059
1060pub struct NullableStrCol<T> {
1062 pub(crate) name: &'static str,
1063 _phantom: PhantomData<T>,
1064}
1065
1066impl<T> NullableStrCol<T> {
1067 pub const fn new(name: &'static str) -> Self {
1068 Self {
1069 name,
1070 _phantom: PhantomData,
1071 }
1072 }
1073
1074 pub fn eq<S: Into<String>>(&self, val: S) -> Predicate<T> {
1076 Predicate::new(Expr::col(Alias::new(self.name)).eq(val.into()))
1077 }
1078
1079 pub fn ne<S: Into<String>>(&self, val: S) -> Predicate<T> {
1081 Predicate::new(Expr::col(Alias::new(self.name)).ne(val.into()))
1082 }
1083
1084 pub fn in_<S: AsRef<str>>(&self, vals: &[S]) -> Predicate<T> {
1087 Predicate::new(
1088 Expr::col(Alias::new(self.name)).is_in(vals.iter().map(|s| s.as_ref().to_string())),
1089 )
1090 }
1091
1092 pub fn in_subquery(&self, sub: super::Subquery) -> Predicate<T> {
1094 Predicate::new(Expr::col(Alias::new(self.name)).in_subquery(sub.into_statement()))
1095 }
1096
1097 pub fn like<S: Into<String>>(&self, pattern: S) -> Predicate<T> {
1099 Predicate::new(Expr::col(Alias::new(self.name)).like(pattern.into()))
1100 }
1101
1102 pub fn ilike<S: Into<String>>(&self, pattern: S) -> Predicate<T> {
1104 let pattern = pattern.into().to_uppercase();
1105 Predicate::new(Expr::expr(Func::upper(Expr::col(Alias::new(self.name)))).like(pattern))
1106 }
1107
1108 pub fn contains<S: Into<String>>(&self, substring: S) -> Predicate<T> {
1110 let pattern = format!("%{}%", super::escape_like_literal(&substring.into()));
1111 Predicate::new(
1112 Expr::col(Alias::new(self.name)).like(sea_query::LikeExpr::new(pattern).escape('\\')),
1113 )
1114 }
1115
1116 pub fn icontains<S: Into<String>>(&self, substring: S) -> Predicate<T> {
1119 let pattern = format!("%{}%", super::escape_like_literal(&substring.into())).to_uppercase();
1120 Predicate::new(
1121 Expr::expr(Func::upper(Expr::col(Alias::new(self.name))))
1122 .like(sea_query::LikeExpr::new(pattern).escape('\\')),
1123 )
1124 }
1125
1126 pub fn startswith<S: Into<String>>(&self, prefix: S) -> Predicate<T> {
1129 let pattern = format!("{}%", super::escape_like_literal(&prefix.into()));
1130 Predicate::new(
1131 Expr::col(Alias::new(self.name)).like(sea_query::LikeExpr::new(pattern).escape('\\')),
1132 )
1133 }
1134
1135 pub fn istartswith<S: Into<String>>(&self, prefix: S) -> Predicate<T> {
1137 let pattern = format!("{}%", super::escape_like_literal(&prefix.into())).to_uppercase();
1138 Predicate::new(
1139 Expr::expr(Func::upper(Expr::col(Alias::new(self.name))))
1140 .like(sea_query::LikeExpr::new(pattern).escape('\\')),
1141 )
1142 }
1143
1144 pub fn is_null(&self) -> Predicate<T> {
1146 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
1147 }
1148
1149 pub fn is_not_null(&self) -> Predicate<T> {
1151 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
1152 }
1153
1154 pub fn asc(&self) -> OrderExpr<T> {
1156 OrderExpr::new(self.name, false)
1157 }
1158
1159 pub fn desc(&self) -> OrderExpr<T> {
1161 OrderExpr::new(self.name, true)
1162 }
1163}
1164
1165pub struct NullableF64Col<T> {
1167 pub(crate) name: &'static str,
1168 _phantom: PhantomData<T>,
1169}
1170
1171impl<T> NullableF64Col<T> {
1172 pub const fn new(name: &'static str) -> Self {
1173 Self {
1174 name,
1175 _phantom: PhantomData,
1176 }
1177 }
1178
1179 pub fn eq(&self, val: f64) -> Predicate<T> {
1181 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
1182 }
1183
1184 pub fn ne(&self, val: f64) -> Predicate<T> {
1186 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
1187 }
1188
1189 pub fn lt(&self, val: f64) -> Predicate<T> {
1191 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
1192 }
1193
1194 pub fn le(&self, val: f64) -> Predicate<T> {
1196 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
1197 }
1198
1199 pub fn lte(&self, val: f64) -> Predicate<T> {
1202 self.le(val)
1203 }
1204
1205 pub fn gt(&self, val: f64) -> Predicate<T> {
1207 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
1208 }
1209
1210 pub fn ge(&self, val: f64) -> Predicate<T> {
1212 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
1213 }
1214
1215 pub fn gte(&self, val: f64) -> Predicate<T> {
1218 self.ge(val)
1219 }
1220
1221 pub fn is_null(&self) -> Predicate<T> {
1223 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
1224 }
1225
1226 pub fn is_not_null(&self) -> Predicate<T> {
1228 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
1229 }
1230
1231 pub fn asc(&self) -> OrderExpr<T> {
1233 OrderExpr::new(self.name, false)
1234 }
1235
1236 pub fn desc(&self) -> OrderExpr<T> {
1238 OrderExpr::new(self.name, true)
1239 }
1240}
1241
1242pub struct NullableBoolCol<T> {
1244 pub(crate) name: &'static str,
1245 _phantom: PhantomData<T>,
1246}
1247
1248impl<T> NullableBoolCol<T> {
1249 pub const fn new(name: &'static str) -> Self {
1250 Self {
1251 name,
1252 _phantom: PhantomData,
1253 }
1254 }
1255
1256 pub fn eq(&self, val: bool) -> Predicate<T> {
1258 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
1259 }
1260
1261 pub fn ne(&self, val: bool) -> Predicate<T> {
1263 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
1264 }
1265
1266 pub fn is_true(&self) -> Predicate<T> {
1268 self.eq(true)
1269 }
1270
1271 pub fn is_false(&self) -> Predicate<T> {
1273 self.eq(false)
1274 }
1275
1276 pub fn is_null(&self) -> Predicate<T> {
1278 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
1279 }
1280
1281 pub fn is_not_null(&self) -> Predicate<T> {
1283 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
1284 }
1285
1286 pub fn asc(&self) -> OrderExpr<T> {
1288 OrderExpr::new(self.name, false)
1289 }
1290
1291 pub fn desc(&self) -> OrderExpr<T> {
1293 OrderExpr::new(self.name, true)
1294 }
1295}
1296
1297pub struct NullableUuidCol<T> {
1299 pub(crate) name: &'static str,
1300 _phantom: PhantomData<T>,
1301}
1302
1303impl<T> NullableUuidCol<T> {
1304 pub const fn new(name: &'static str) -> Self {
1305 Self {
1306 name,
1307 _phantom: PhantomData,
1308 }
1309 }
1310
1311 pub fn eq(&self, val: uuid::Uuid) -> Predicate<T> {
1313 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
1314 }
1315
1316 pub fn ne(&self, val: uuid::Uuid) -> Predicate<T> {
1318 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
1319 }
1320
1321 pub fn in_(&self, vals: &[uuid::Uuid]) -> Predicate<T> {
1323 Predicate::new(Expr::col(Alias::new(self.name)).is_in(vals.iter().copied()))
1324 }
1325
1326 pub fn is_null(&self) -> Predicate<T> {
1328 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
1329 }
1330
1331 pub fn is_not_null(&self) -> Predicate<T> {
1333 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
1334 }
1335
1336 pub fn asc(&self) -> OrderExpr<T> {
1338 OrderExpr::new(self.name, false)
1339 }
1340
1341 pub fn desc(&self) -> OrderExpr<T> {
1343 OrderExpr::new(self.name, true)
1344 }
1345}
1346
1347pub struct NullableDateCol<T> {
1349 pub(crate) name: &'static str,
1350 _phantom: PhantomData<T>,
1351}
1352
1353impl<T> NullableDateCol<T> {
1354 pub const fn new(name: &'static str) -> Self {
1355 Self {
1356 name,
1357 _phantom: PhantomData,
1358 }
1359 }
1360
1361 pub fn eq(&self, val: chrono::NaiveDate) -> Predicate<T> {
1363 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
1364 }
1365
1366 pub fn ne(&self, val: chrono::NaiveDate) -> Predicate<T> {
1368 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
1369 }
1370
1371 pub fn lt(&self, val: chrono::NaiveDate) -> Predicate<T> {
1373 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
1374 }
1375
1376 pub fn le(&self, val: chrono::NaiveDate) -> Predicate<T> {
1378 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
1379 }
1380
1381 pub fn lte(&self, val: chrono::NaiveDate) -> Predicate<T> {
1384 self.le(val)
1385 }
1386
1387 pub fn gt(&self, val: chrono::NaiveDate) -> Predicate<T> {
1389 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
1390 }
1391
1392 pub fn ge(&self, val: chrono::NaiveDate) -> Predicate<T> {
1394 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
1395 }
1396
1397 pub fn gte(&self, val: chrono::NaiveDate) -> Predicate<T> {
1400 self.ge(val)
1401 }
1402
1403 pub fn before(&self, val: chrono::NaiveDate) -> Predicate<T> {
1405 self.lt(val)
1406 }
1407
1408 pub fn after(&self, val: chrono::NaiveDate) -> Predicate<T> {
1410 self.gt(val)
1411 }
1412
1413 pub fn is_null(&self) -> Predicate<T> {
1415 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
1416 }
1417
1418 pub fn is_not_null(&self) -> Predicate<T> {
1420 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
1421 }
1422
1423 pub fn asc(&self) -> OrderExpr<T> {
1425 OrderExpr::new(self.name, false)
1426 }
1427
1428 pub fn desc(&self) -> OrderExpr<T> {
1430 OrderExpr::new(self.name, true)
1431 }
1432}
1433
1434pub struct NullableTimeCol<T> {
1436 pub(crate) name: &'static str,
1437 _phantom: PhantomData<T>,
1438}
1439
1440impl<T> NullableTimeCol<T> {
1441 pub const fn new(name: &'static str) -> Self {
1442 Self {
1443 name,
1444 _phantom: PhantomData,
1445 }
1446 }
1447
1448 pub fn eq(&self, val: chrono::NaiveTime) -> Predicate<T> {
1450 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
1451 }
1452
1453 pub fn ne(&self, val: chrono::NaiveTime) -> Predicate<T> {
1455 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
1456 }
1457
1458 pub fn lt(&self, val: chrono::NaiveTime) -> Predicate<T> {
1460 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
1461 }
1462
1463 pub fn le(&self, val: chrono::NaiveTime) -> Predicate<T> {
1465 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
1466 }
1467
1468 pub fn lte(&self, val: chrono::NaiveTime) -> Predicate<T> {
1471 self.le(val)
1472 }
1473
1474 pub fn gt(&self, val: chrono::NaiveTime) -> Predicate<T> {
1476 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
1477 }
1478
1479 pub fn ge(&self, val: chrono::NaiveTime) -> Predicate<T> {
1481 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
1482 }
1483
1484 pub fn gte(&self, val: chrono::NaiveTime) -> Predicate<T> {
1487 self.ge(val)
1488 }
1489
1490 pub fn before(&self, val: chrono::NaiveTime) -> Predicate<T> {
1492 self.lt(val)
1493 }
1494
1495 pub fn after(&self, val: chrono::NaiveTime) -> Predicate<T> {
1497 self.gt(val)
1498 }
1499
1500 pub fn is_null(&self) -> Predicate<T> {
1502 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
1503 }
1504
1505 pub fn is_not_null(&self) -> Predicate<T> {
1507 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
1508 }
1509
1510 pub fn asc(&self) -> OrderExpr<T> {
1512 OrderExpr::new(self.name, false)
1513 }
1514
1515 pub fn desc(&self) -> OrderExpr<T> {
1517 OrderExpr::new(self.name, true)
1518 }
1519}
1520
1521pub struct JsonCol<T> {
1536 pub(crate) name: &'static str,
1537 _phantom: PhantomData<T>,
1538}
1539
1540impl<T> JsonCol<T> {
1541 pub const fn new(name: &'static str) -> Self {
1542 Self {
1543 name,
1544 _phantom: PhantomData,
1545 }
1546 }
1547
1548 pub fn asc(&self) -> OrderExpr<T> {
1553 OrderExpr::new(self.name, false)
1554 }
1555
1556 pub fn desc(&self) -> OrderExpr<T> {
1558 OrderExpr::new(self.name, true)
1559 }
1560
1561 pub fn path_text(&self, keys: &[&str]) -> JsonPathText<T> {
1573 JsonPathText::new(self.name, keys)
1574 }
1575
1576 pub fn has_key(&self, key: &str) -> Predicate<T> {
1582 json_has_key_predicate(self.name, key)
1583 }
1584}
1585
1586pub struct NullableJsonCol<T> {
1588 pub(crate) name: &'static str,
1589 _phantom: PhantomData<T>,
1590}
1591
1592impl<T> NullableJsonCol<T> {
1593 pub const fn new(name: &'static str) -> Self {
1594 Self {
1595 name,
1596 _phantom: PhantomData,
1597 }
1598 }
1599
1600 pub fn is_null(&self) -> Predicate<T> {
1602 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
1603 }
1604
1605 pub fn is_not_null(&self) -> Predicate<T> {
1607 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
1608 }
1609
1610 pub fn asc(&self) -> OrderExpr<T> {
1612 OrderExpr::new(self.name, false)
1613 }
1614
1615 pub fn desc(&self) -> OrderExpr<T> {
1617 OrderExpr::new(self.name, true)
1618 }
1619
1620 pub fn path_text(&self, keys: &[&str]) -> JsonPathText<T> {
1624 JsonPathText::new(self.name, keys)
1625 }
1626
1627 pub fn has_key(&self, key: &str) -> Predicate<T> {
1629 json_has_key_predicate(self.name, key)
1630 }
1631}
1632
1633pub struct JsonPathText<T> {
1660 column: &'static str,
1661 path: Vec<String>,
1664 _phantom: PhantomData<T>,
1665}
1666
1667impl<T> JsonPathText<T> {
1668 fn new(column: &'static str, keys: &[&str]) -> Self {
1669 assert!(
1670 !keys.is_empty(),
1671 "umbral::orm::JsonPathText: path must have at least one segment"
1672 );
1673 Self {
1674 column,
1675 path: keys.iter().map(|s| s.to_string()).collect(),
1676 _phantom: PhantomData,
1677 }
1678 }
1679
1680 fn extract_template_pg(&self, base_placeholder: usize) -> (String, Vec<sea_query::Value>) {
1685 let col = self.column.replace('"', "\"\"");
1686 let n = self.path.len();
1687 let mut sql = format!("\"{col}\"");
1688 for i in 1..n {
1689 sql.push_str(&format!(" -> ${}", base_placeholder + i - 1));
1690 }
1691 sql.push_str(&format!(" ->> ${}", base_placeholder + n - 1));
1692 let values: Vec<sea_query::Value> = self
1693 .path
1694 .iter()
1695 .map(|k| sea_query::Value::String(Some(Box::new(k.clone()))))
1696 .collect();
1697 (sql, values)
1698 }
1699
1700 fn sqlite_json_path(&self) -> String {
1704 let mut s = String::from("$");
1705 for seg in &self.path {
1706 s.push('.');
1707 s.push_str(seg);
1708 }
1709 s
1710 }
1711
1712 pub fn eq(&self, val: &str) -> Predicate<T> {
1716 let (extract_pg, mut pg_values) = self.extract_template_pg(1);
1717 let pg_placeholder = pg_values.len() + 1;
1718 let pg_sql = format!("{extract_pg} = ${pg_placeholder}");
1719 pg_values.push(sea_query::Value::String(Some(Box::new(val.to_string()))));
1720 let pg_cond = Expr::cust_with_values(&pg_sql, pg_values);
1721
1722 let col = self.column.replace('"', "\"\"");
1723 let sqlite_sql = format!("json_extract(\"{col}\", ?) = ?");
1724 let sqlite_values = vec![
1725 sea_query::Value::String(Some(Box::new(self.sqlite_json_path()))),
1726 sea_query::Value::String(Some(Box::new(val.to_string()))),
1727 ];
1728 let sqlite_cond = Expr::cust_with_values(&sqlite_sql, sqlite_values);
1729
1730 Predicate::new_with_sqlite(pg_cond, sqlite_cond)
1731 }
1732
1733 pub fn ne(&self, val: &str) -> Predicate<T> {
1735 let (extract_pg, mut pg_values) = self.extract_template_pg(1);
1736 let pg_placeholder = pg_values.len() + 1;
1737 let pg_sql = format!("{extract_pg} <> ${pg_placeholder}");
1738 pg_values.push(sea_query::Value::String(Some(Box::new(val.to_string()))));
1739 let pg_cond = Expr::cust_with_values(&pg_sql, pg_values);
1740
1741 let col = self.column.replace('"', "\"\"");
1742 let sqlite_sql = format!("json_extract(\"{col}\", ?) <> ?");
1743 let sqlite_values = vec![
1744 sea_query::Value::String(Some(Box::new(self.sqlite_json_path()))),
1745 sea_query::Value::String(Some(Box::new(val.to_string()))),
1746 ];
1747 let sqlite_cond = Expr::cust_with_values(&sqlite_sql, sqlite_values);
1748
1749 Predicate::new_with_sqlite(pg_cond, sqlite_cond)
1750 }
1751
1752 pub fn is_null(&self) -> Predicate<T> {
1756 let (extract_pg, pg_values) = self.extract_template_pg(1);
1757 let pg_cond = Expr::cust_with_values(format!("{extract_pg} IS NULL"), pg_values);
1758
1759 let col = self.column.replace('"', "\"\"");
1760 let sqlite_sql = format!("json_extract(\"{col}\", ?) IS NULL");
1761 let sqlite_values = vec![sea_query::Value::String(Some(Box::new(
1762 self.sqlite_json_path(),
1763 )))];
1764 let sqlite_cond = Expr::cust_with_values(&sqlite_sql, sqlite_values);
1765
1766 Predicate::new_with_sqlite(pg_cond, sqlite_cond)
1767 }
1768
1769 pub fn is_not_null(&self) -> Predicate<T> {
1772 let (extract_pg, pg_values) = self.extract_template_pg(1);
1773 let pg_cond = Expr::cust_with_values(format!("{extract_pg} IS NOT NULL"), pg_values);
1774
1775 let col = self.column.replace('"', "\"\"");
1776 let sqlite_sql = format!("json_extract(\"{col}\", ?) IS NOT NULL");
1777 let sqlite_values = vec![sea_query::Value::String(Some(Box::new(
1778 self.sqlite_json_path(),
1779 )))];
1780 let sqlite_cond = Expr::cust_with_values(&sqlite_sql, sqlite_values);
1781
1782 Predicate::new_with_sqlite(pg_cond, sqlite_cond)
1783 }
1784}
1785
1786fn json_has_key_predicate<T>(col: &'static str, key: &str) -> Predicate<T> {
1795 let col_escaped = col.replace('"', "\"\"");
1796 let key_escaped = key.replace('\'', "''");
1797
1798 let pg_sql = format!("\"{col_escaped}\" ? '{key_escaped}'");
1804 let pg_cond = Expr::cust(&pg_sql);
1805
1806 let sqlite_sql = format!("json_extract(\"{col_escaped}\", ?) IS NOT NULL");
1815 let sqlite_values = vec![sea_query::Value::String(Some(Box::new(format!("$.{key}"))))];
1816 let sqlite_cond = Expr::cust_with_values(&sqlite_sql, sqlite_values);
1817
1818 Predicate::new_with_sqlite(pg_cond, sqlite_cond)
1819}
1820
1821pub struct ArrayCol<T> {
1839 pub(crate) name: &'static str,
1840 _phantom: PhantomData<T>,
1841}
1842
1843impl<T> ArrayCol<T> {
1844 pub const fn new(name: &'static str) -> Self {
1845 Self {
1846 name,
1847 _phantom: PhantomData,
1848 }
1849 }
1850
1851 pub fn asc(&self) -> OrderExpr<T> {
1854 OrderExpr::new(self.name, false)
1855 }
1856
1857 pub fn desc(&self) -> OrderExpr<T> {
1859 OrderExpr::new(self.name, true)
1860 }
1861
1862 pub fn contains<V: Into<sea_query::Value>>(&self, elem: V) -> Predicate<T> {
1872 array_contains_predicate(self.name, std::iter::once(elem.into()))
1873 }
1874
1875 pub fn contains_all<I, V>(&self, elems: I) -> Predicate<T>
1884 where
1885 I: IntoIterator<Item = V>,
1886 V: Into<sea_query::Value>,
1887 {
1888 array_contains_predicate(self.name, elems.into_iter().map(Into::into))
1889 }
1890
1891 pub fn contained_by<I, V>(&self, elems: I) -> Predicate<T>
1896 where
1897 I: IntoIterator<Item = V>,
1898 V: Into<sea_query::Value>,
1899 {
1900 array_contained_by_predicate(self.name, elems.into_iter().map(Into::into))
1901 }
1902
1903 pub fn overlaps<I, V>(&self, elems: I) -> Predicate<T>
1908 where
1909 I: IntoIterator<Item = V>,
1910 V: Into<sea_query::Value>,
1911 {
1912 array_overlaps_predicate(self.name, elems.into_iter().map(Into::into))
1913 }
1914}
1915
1916pub struct NullableArrayCol<T> {
1918 pub(crate) name: &'static str,
1919 _phantom: PhantomData<T>,
1920}
1921
1922impl<T> NullableArrayCol<T> {
1923 pub const fn new(name: &'static str) -> Self {
1924 Self {
1925 name,
1926 _phantom: PhantomData,
1927 }
1928 }
1929
1930 pub fn is_null(&self) -> Predicate<T> {
1934 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
1935 }
1936
1937 pub fn is_not_null(&self) -> Predicate<T> {
1939 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
1940 }
1941
1942 pub fn asc(&self) -> OrderExpr<T> {
1944 OrderExpr::new(self.name, false)
1945 }
1946
1947 pub fn desc(&self) -> OrderExpr<T> {
1949 OrderExpr::new(self.name, true)
1950 }
1951
1952 pub fn contains<V: Into<sea_query::Value>>(&self, elem: V) -> Predicate<T> {
1955 array_contains_predicate(self.name, std::iter::once(elem.into()))
1956 }
1957
1958 pub fn contains_all<I, V>(&self, elems: I) -> Predicate<T>
1960 where
1961 I: IntoIterator<Item = V>,
1962 V: Into<sea_query::Value>,
1963 {
1964 array_contains_predicate(self.name, elems.into_iter().map(Into::into))
1965 }
1966
1967 pub fn contained_by<I, V>(&self, elems: I) -> Predicate<T>
1969 where
1970 I: IntoIterator<Item = V>,
1971 V: Into<sea_query::Value>,
1972 {
1973 array_contained_by_predicate(self.name, elems.into_iter().map(Into::into))
1974 }
1975
1976 pub fn overlaps<I, V>(&self, elems: I) -> Predicate<T>
1978 where
1979 I: IntoIterator<Item = V>,
1980 V: Into<sea_query::Value>,
1981 {
1982 array_overlaps_predicate(self.name, elems.into_iter().map(Into::into))
1983 }
1984}
1985
1986fn array_op_predicate<T>(
2005 col: &'static str,
2006 op: &str,
2007 values: Vec<sea_query::Value>,
2008) -> Predicate<T> {
2009 if values.is_empty() {
2010 return Predicate::new(Expr::cust("1 = 1"));
2013 }
2014 let placeholders: Vec<String> = (1..=values.len()).map(|i| format!("${i}")).collect();
2015 let sql = format!(
2016 "\"{}\" {op} ARRAY[{}]",
2017 col.replace('"', "\"\""),
2018 placeholders.join(", ")
2019 );
2020 Predicate::new(Expr::cust_with_values(&sql, values))
2021}
2022
2023fn array_contains_predicate<T, I>(col: &'static str, elems: I) -> Predicate<T>
2024where
2025 I: IntoIterator<Item = sea_query::Value>,
2026{
2027 array_op_predicate::<T>(col, "@>", elems.into_iter().collect())
2031}
2032
2033fn array_contained_by_predicate<T, I>(col: &'static str, elems: I) -> Predicate<T>
2034where
2035 I: IntoIterator<Item = sea_query::Value>,
2036{
2037 let values: Vec<sea_query::Value> = elems.into_iter().collect();
2038 if values.is_empty() {
2039 return Predicate::new(Expr::cust("1 = 0"));
2046 }
2047 array_op_predicate::<T>(col, "<@", values)
2048}
2049
2050fn array_overlaps_predicate<T, I>(col: &'static str, elems: I) -> Predicate<T>
2051where
2052 I: IntoIterator<Item = sea_query::Value>,
2053{
2054 let values: Vec<sea_query::Value> = elems.into_iter().collect();
2055 if values.is_empty() {
2056 return Predicate::new(Expr::cust("1 = 0"));
2058 }
2059 array_op_predicate::<T>(col, "&&", values)
2060}
2061
2062pub struct InetCol<T> {
2085 pub(crate) name: &'static str,
2086 _phantom: PhantomData<T>,
2087}
2088
2089impl<T> InetCol<T> {
2090 pub const fn new(name: &'static str) -> Self {
2091 Self {
2092 name,
2093 _phantom: PhantomData,
2094 }
2095 }
2096
2097 pub fn eq(&self, val: ipnetwork::IpNetwork) -> Predicate<T> {
2099 let sql = format!("\"{}\" = $1", self.name.replace('"', "\"\""));
2103 Predicate::new(Expr::cust_with_values(&sql, vec![val]))
2107 }
2108
2109 pub fn ne(&self, val: ipnetwork::IpNetwork) -> Predicate<T> {
2111 let sql = format!("\"{}\" <> $1", self.name.replace('"', "\"\""));
2112 Predicate::new(Expr::cust_with_values(&sql, vec![val]))
2113 }
2114
2115 pub fn asc(&self) -> OrderExpr<T> {
2117 OrderExpr::new(self.name, false)
2118 }
2119
2120 pub fn desc(&self) -> OrderExpr<T> {
2122 OrderExpr::new(self.name, true)
2123 }
2124}
2125
2126pub struct NullableInetCol<T> {
2128 pub(crate) name: &'static str,
2129 _phantom: PhantomData<T>,
2130}
2131
2132impl<T> NullableInetCol<T> {
2133 pub const fn new(name: &'static str) -> Self {
2134 Self {
2135 name,
2136 _phantom: PhantomData,
2137 }
2138 }
2139
2140 pub fn eq(&self, val: ipnetwork::IpNetwork) -> Predicate<T> {
2142 let sql = format!("\"{}\" = $1", self.name.replace('"', "\"\""));
2143 Predicate::new(Expr::cust_with_values(&sql, vec![val]))
2144 }
2145
2146 pub fn ne(&self, val: ipnetwork::IpNetwork) -> Predicate<T> {
2148 let sql = format!("\"{}\" <> $1", self.name.replace('"', "\"\""));
2149 Predicate::new(Expr::cust_with_values(&sql, vec![val]))
2150 }
2151
2152 pub fn is_null(&self) -> Predicate<T> {
2154 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
2155 }
2156
2157 pub fn is_not_null(&self) -> Predicate<T> {
2159 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
2160 }
2161
2162 pub fn asc(&self) -> OrderExpr<T> {
2164 OrderExpr::new(self.name, false)
2165 }
2166
2167 pub fn desc(&self) -> OrderExpr<T> {
2169 OrderExpr::new(self.name, true)
2170 }
2171}
2172
2173pub struct CidrCol<T> {
2179 pub(crate) name: &'static str,
2180 _phantom: PhantomData<T>,
2181}
2182
2183impl<T> CidrCol<T> {
2184 pub const fn new(name: &'static str) -> Self {
2185 Self {
2186 name,
2187 _phantom: PhantomData,
2188 }
2189 }
2190
2191 pub fn eq(&self, val: ipnetwork::IpNetwork) -> Predicate<T> {
2192 let sql = format!("\"{}\" = $1", self.name.replace('"', "\"\""));
2193 Predicate::new(Expr::cust_with_values(&sql, vec![val]))
2194 }
2195
2196 pub fn ne(&self, val: ipnetwork::IpNetwork) -> Predicate<T> {
2197 let sql = format!("\"{}\" <> $1", self.name.replace('"', "\"\""));
2198 Predicate::new(Expr::cust_with_values(&sql, vec![val]))
2199 }
2200
2201 pub fn asc(&self) -> OrderExpr<T> {
2202 OrderExpr::new(self.name, false)
2203 }
2204
2205 pub fn desc(&self) -> OrderExpr<T> {
2206 OrderExpr::new(self.name, true)
2207 }
2208}
2209
2210pub struct NullableCidrCol<T> {
2212 pub(crate) name: &'static str,
2213 _phantom: PhantomData<T>,
2214}
2215
2216impl<T> NullableCidrCol<T> {
2217 pub const fn new(name: &'static str) -> Self {
2218 Self {
2219 name,
2220 _phantom: PhantomData,
2221 }
2222 }
2223
2224 pub fn eq(&self, val: ipnetwork::IpNetwork) -> Predicate<T> {
2225 let sql = format!("\"{}\" = $1", self.name.replace('"', "\"\""));
2226 Predicate::new(Expr::cust_with_values(&sql, vec![val]))
2227 }
2228
2229 pub fn ne(&self, val: ipnetwork::IpNetwork) -> Predicate<T> {
2230 let sql = format!("\"{}\" <> $1", self.name.replace('"', "\"\""));
2231 Predicate::new(Expr::cust_with_values(&sql, vec![val]))
2232 }
2233
2234 pub fn is_null(&self) -> Predicate<T> {
2235 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
2236 }
2237
2238 pub fn is_not_null(&self) -> Predicate<T> {
2239 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
2240 }
2241
2242 pub fn asc(&self) -> OrderExpr<T> {
2243 OrderExpr::new(self.name, false)
2244 }
2245
2246 pub fn desc(&self) -> OrderExpr<T> {
2247 OrderExpr::new(self.name, true)
2248 }
2249}
2250
2251pub struct MacAddrCol<T> {
2253 pub(crate) name: &'static str,
2254 _phantom: PhantomData<T>,
2255}
2256
2257impl<T> MacAddrCol<T> {
2258 pub const fn new(name: &'static str) -> Self {
2259 Self {
2260 name,
2261 _phantom: PhantomData,
2262 }
2263 }
2264
2265 pub fn eq(&self, val: mac_address::MacAddress) -> Predicate<T> {
2266 let sql = format!("\"{}\" = $1", self.name.replace('"', "\"\""));
2267 Predicate::new(Expr::cust_with_values(&sql, vec![val]))
2268 }
2269
2270 pub fn ne(&self, val: mac_address::MacAddress) -> Predicate<T> {
2271 let sql = format!("\"{}\" <> $1", self.name.replace('"', "\"\""));
2272 Predicate::new(Expr::cust_with_values(&sql, vec![val]))
2273 }
2274
2275 pub fn asc(&self) -> OrderExpr<T> {
2276 OrderExpr::new(self.name, false)
2277 }
2278
2279 pub fn desc(&self) -> OrderExpr<T> {
2280 OrderExpr::new(self.name, true)
2281 }
2282}
2283
2284pub struct FullTextCol<T> {
2299 pub(crate) name: &'static str,
2300 _phantom: PhantomData<T>,
2301}
2302
2303impl<T> FullTextCol<T> {
2304 pub const fn new(name: &'static str) -> Self {
2305 Self {
2306 name,
2307 _phantom: PhantomData,
2308 }
2309 }
2310
2311 pub fn matches(&self, query: &str) -> Predicate<T> {
2316 let col = self.name.replace('"', "\"\"");
2317 let sql = format!("\"{col}\" @@ to_tsquery($1)");
2318 let values = vec![sea_query::Value::String(Some(Box::new(query.to_string())))];
2319 Predicate::new(Expr::cust_with_values(&sql, values))
2320 }
2321
2322 pub fn matches_websearch(&self, query: &str) -> Predicate<T> {
2327 let col = self.name.replace('"', "\"\"");
2328 let sql = format!("\"{col}\" @@ websearch_to_tsquery($1)");
2329 let values = vec![sea_query::Value::String(Some(Box::new(query.to_string())))];
2330 Predicate::new(Expr::cust_with_values(&sql, values))
2331 }
2332
2333 pub fn asc(&self) -> OrderExpr<T> {
2334 OrderExpr::new(self.name, false)
2335 }
2336
2337 pub fn desc(&self) -> OrderExpr<T> {
2338 OrderExpr::new(self.name, true)
2339 }
2340}
2341
2342pub struct NullableFullTextCol<T> {
2344 pub(crate) name: &'static str,
2345 _phantom: PhantomData<T>,
2346}
2347
2348impl<T> NullableFullTextCol<T> {
2349 pub const fn new(name: &'static str) -> Self {
2350 Self {
2351 name,
2352 _phantom: PhantomData,
2353 }
2354 }
2355
2356 pub fn matches(&self, query: &str) -> Predicate<T> {
2357 let col = self.name.replace('"', "\"\"");
2358 let sql = format!("\"{col}\" @@ to_tsquery($1)");
2359 let values = vec![sea_query::Value::String(Some(Box::new(query.to_string())))];
2360 Predicate::new(Expr::cust_with_values(&sql, values))
2361 }
2362
2363 pub fn matches_websearch(&self, query: &str) -> Predicate<T> {
2364 let col = self.name.replace('"', "\"\"");
2365 let sql = format!("\"{col}\" @@ websearch_to_tsquery($1)");
2366 let values = vec![sea_query::Value::String(Some(Box::new(query.to_string())))];
2367 Predicate::new(Expr::cust_with_values(&sql, values))
2368 }
2369
2370 pub fn is_null(&self) -> Predicate<T> {
2371 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
2372 }
2373
2374 pub fn is_not_null(&self) -> Predicate<T> {
2375 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
2376 }
2377
2378 pub fn asc(&self) -> OrderExpr<T> {
2379 OrderExpr::new(self.name, false)
2380 }
2381
2382 pub fn desc(&self) -> OrderExpr<T> {
2383 OrderExpr::new(self.name, true)
2384 }
2385}
2386
2387pub struct NullableMacAddrCol<T> {
2389 pub(crate) name: &'static str,
2390 _phantom: PhantomData<T>,
2391}
2392
2393impl<T> NullableMacAddrCol<T> {
2394 pub const fn new(name: &'static str) -> Self {
2395 Self {
2396 name,
2397 _phantom: PhantomData,
2398 }
2399 }
2400
2401 pub fn eq(&self, val: mac_address::MacAddress) -> Predicate<T> {
2402 let sql = format!("\"{}\" = $1", self.name.replace('"', "\"\""));
2403 Predicate::new(Expr::cust_with_values(&sql, vec![val]))
2404 }
2405
2406 pub fn ne(&self, val: mac_address::MacAddress) -> Predicate<T> {
2407 let sql = format!("\"{}\" <> $1", self.name.replace('"', "\"\""));
2408 Predicate::new(Expr::cust_with_values(&sql, vec![val]))
2409 }
2410
2411 pub fn is_null(&self) -> Predicate<T> {
2412 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
2413 }
2414
2415 pub fn is_not_null(&self) -> Predicate<T> {
2416 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
2417 }
2418
2419 pub fn asc(&self) -> OrderExpr<T> {
2420 OrderExpr::new(self.name, false)
2421 }
2422
2423 pub fn desc(&self) -> OrderExpr<T> {
2424 OrderExpr::new(self.name, true)
2425 }
2426}
2427
2428pub struct XmlCol<T> {
2450 pub(crate) name: &'static str,
2451 _phantom: PhantomData<T>,
2452}
2453
2454impl<T> XmlCol<T> {
2455 pub const fn new(name: &'static str) -> Self {
2456 Self {
2457 name,
2458 _phantom: PhantomData,
2459 }
2460 }
2461
2462 pub fn eq(&self, val: &str) -> Predicate<T> {
2463 let sql = format!("\"{}\"::text = $1", self.name.replace('"', "\"\""));
2464 let values = vec![sea_query::Value::String(Some(Box::new(val.to_string())))];
2465 Predicate::new(Expr::cust_with_values(&sql, values))
2466 }
2467
2468 pub fn ne(&self, val: &str) -> Predicate<T> {
2469 let sql = format!("\"{}\"::text <> $1", self.name.replace('"', "\"\""));
2470 let values = vec![sea_query::Value::String(Some(Box::new(val.to_string())))];
2471 Predicate::new(Expr::cust_with_values(&sql, values))
2472 }
2473
2474 pub fn asc(&self) -> OrderExpr<T> {
2475 OrderExpr::new(self.name, false)
2476 }
2477
2478 pub fn desc(&self) -> OrderExpr<T> {
2479 OrderExpr::new(self.name, true)
2480 }
2481}
2482
2483pub struct NullableXmlCol<T> {
2485 pub(crate) name: &'static str,
2486 _phantom: PhantomData<T>,
2487}
2488
2489impl<T> NullableXmlCol<T> {
2490 pub const fn new(name: &'static str) -> Self {
2491 Self {
2492 name,
2493 _phantom: PhantomData,
2494 }
2495 }
2496
2497 pub fn eq(&self, val: &str) -> Predicate<T> {
2498 let sql = format!("\"{}\"::text = $1", self.name.replace('"', "\"\""));
2499 let values = vec![sea_query::Value::String(Some(Box::new(val.to_string())))];
2500 Predicate::new(Expr::cust_with_values(&sql, values))
2501 }
2502
2503 pub fn ne(&self, val: &str) -> Predicate<T> {
2504 let sql = format!("\"{}\"::text <> $1", self.name.replace('"', "\"\""));
2505 let values = vec![sea_query::Value::String(Some(Box::new(val.to_string())))];
2506 Predicate::new(Expr::cust_with_values(&sql, values))
2507 }
2508
2509 pub fn is_null(&self) -> Predicate<T> {
2510 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
2511 }
2512
2513 pub fn is_not_null(&self) -> Predicate<T> {
2514 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
2515 }
2516
2517 pub fn asc(&self) -> OrderExpr<T> {
2518 OrderExpr::new(self.name, false)
2519 }
2520
2521 pub fn desc(&self) -> OrderExpr<T> {
2522 OrderExpr::new(self.name, true)
2523 }
2524}
2525
2526pub struct LtreeCol<T> {
2528 pub(crate) name: &'static str,
2529 _phantom: PhantomData<T>,
2530}
2531
2532impl<T> LtreeCol<T> {
2533 pub const fn new(name: &'static str) -> Self {
2534 Self {
2535 name,
2536 _phantom: PhantomData,
2537 }
2538 }
2539
2540 pub fn eq(&self, val: &str) -> Predicate<T> {
2541 let sql = format!("\"{}\" = $1::ltree", self.name.replace('"', "\"\""));
2542 let values = vec![sea_query::Value::String(Some(Box::new(val.to_string())))];
2543 Predicate::new(Expr::cust_with_values(&sql, values))
2544 }
2545
2546 pub fn ne(&self, val: &str) -> Predicate<T> {
2547 let sql = format!("\"{}\" <> $1::ltree", self.name.replace('"', "\"\""));
2548 let values = vec![sea_query::Value::String(Some(Box::new(val.to_string())))];
2549 Predicate::new(Expr::cust_with_values(&sql, values))
2550 }
2551
2552 pub fn asc(&self) -> OrderExpr<T> {
2553 OrderExpr::new(self.name, false)
2554 }
2555
2556 pub fn desc(&self) -> OrderExpr<T> {
2557 OrderExpr::new(self.name, true)
2558 }
2559}
2560
2561pub struct NullableLtreeCol<T> {
2563 pub(crate) name: &'static str,
2564 _phantom: PhantomData<T>,
2565}
2566
2567impl<T> NullableLtreeCol<T> {
2568 pub const fn new(name: &'static str) -> Self {
2569 Self {
2570 name,
2571 _phantom: PhantomData,
2572 }
2573 }
2574
2575 pub fn eq(&self, val: &str) -> Predicate<T> {
2576 let sql = format!("\"{}\" = $1::ltree", self.name.replace('"', "\"\""));
2577 let values = vec![sea_query::Value::String(Some(Box::new(val.to_string())))];
2578 Predicate::new(Expr::cust_with_values(&sql, values))
2579 }
2580
2581 pub fn ne(&self, val: &str) -> Predicate<T> {
2582 let sql = format!("\"{}\" <> $1::ltree", self.name.replace('"', "\"\""));
2583 let values = vec![sea_query::Value::String(Some(Box::new(val.to_string())))];
2584 Predicate::new(Expr::cust_with_values(&sql, values))
2585 }
2586
2587 pub fn is_null(&self) -> Predicate<T> {
2588 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
2589 }
2590
2591 pub fn is_not_null(&self) -> Predicate<T> {
2592 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
2593 }
2594
2595 pub fn asc(&self) -> OrderExpr<T> {
2596 OrderExpr::new(self.name, false)
2597 }
2598
2599 pub fn desc(&self) -> OrderExpr<T> {
2600 OrderExpr::new(self.name, true)
2601 }
2602}
2603
2604pub struct BitCol<T> {
2606 pub(crate) name: &'static str,
2607 _phantom: PhantomData<T>,
2608}
2609
2610impl<T> BitCol<T> {
2611 pub const fn new(name: &'static str) -> Self {
2612 Self {
2613 name,
2614 _phantom: PhantomData,
2615 }
2616 }
2617
2618 pub fn eq(&self, val: &str) -> Predicate<T> {
2619 let sql = format!("\"{}\" = $1::bit varying", self.name.replace('"', "\"\""));
2620 let values = vec![sea_query::Value::String(Some(Box::new(val.to_string())))];
2621 Predicate::new(Expr::cust_with_values(&sql, values))
2622 }
2623
2624 pub fn ne(&self, val: &str) -> Predicate<T> {
2625 let sql = format!("\"{}\" <> $1::bit varying", self.name.replace('"', "\"\""));
2626 let values = vec![sea_query::Value::String(Some(Box::new(val.to_string())))];
2627 Predicate::new(Expr::cust_with_values(&sql, values))
2628 }
2629
2630 pub fn asc(&self) -> OrderExpr<T> {
2631 OrderExpr::new(self.name, false)
2632 }
2633
2634 pub fn desc(&self) -> OrderExpr<T> {
2635 OrderExpr::new(self.name, true)
2636 }
2637}
2638
2639pub struct NullableBitCol<T> {
2641 pub(crate) name: &'static str,
2642 _phantom: PhantomData<T>,
2643}
2644
2645impl<T> NullableBitCol<T> {
2646 pub const fn new(name: &'static str) -> Self {
2647 Self {
2648 name,
2649 _phantom: PhantomData,
2650 }
2651 }
2652
2653 pub fn eq(&self, val: &str) -> Predicate<T> {
2654 let sql = format!("\"{}\" = $1::bit varying", self.name.replace('"', "\"\""));
2655 let values = vec![sea_query::Value::String(Some(Box::new(val.to_string())))];
2656 Predicate::new(Expr::cust_with_values(&sql, values))
2657 }
2658
2659 pub fn ne(&self, val: &str) -> Predicate<T> {
2660 let sql = format!("\"{}\" <> $1::bit varying", self.name.replace('"', "\"\""));
2661 let values = vec![sea_query::Value::String(Some(Box::new(val.to_string())))];
2662 Predicate::new(Expr::cust_with_values(&sql, values))
2663 }
2664
2665 pub fn is_null(&self) -> Predicate<T> {
2666 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
2667 }
2668
2669 pub fn is_not_null(&self) -> Predicate<T> {
2670 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
2671 }
2672
2673 pub fn asc(&self) -> OrderExpr<T> {
2674 OrderExpr::new(self.name, false)
2675 }
2676
2677 pub fn desc(&self) -> OrderExpr<T> {
2678 OrderExpr::new(self.name, true)
2679 }
2680}
2681
2682pub struct ForeignKeyCol<T> {
2699 pub(crate) name: &'static str,
2700 _phantom: PhantomData<T>,
2701}
2702
2703impl<T> ForeignKeyCol<T> {
2704 pub const fn new(name: &'static str) -> Self {
2705 Self {
2706 name,
2707 _phantom: PhantomData,
2708 }
2709 }
2710
2711 pub fn eq<V: Into<sea_query::Value>>(&self, val: V) -> Predicate<T> {
2727 Predicate::new(Expr::col(Alias::new(self.name)).eq(val.into()))
2728 }
2729
2730 pub fn ne<V: Into<sea_query::Value>>(&self, val: V) -> Predicate<T> {
2732 Predicate::new(Expr::col(Alias::new(self.name)).ne(val.into()))
2733 }
2734
2735 pub fn lt(&self, val: i64) -> Predicate<T> {
2737 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
2738 }
2739
2740 pub fn le(&self, val: i64) -> Predicate<T> {
2742 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
2743 }
2744
2745 pub fn lte(&self, val: i64) -> Predicate<T> {
2748 self.le(val)
2749 }
2750
2751 pub fn gt(&self, val: i64) -> Predicate<T> {
2753 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
2754 }
2755
2756 pub fn ge(&self, val: i64) -> Predicate<T> {
2758 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
2759 }
2760
2761 pub fn gte(&self, val: i64) -> Predicate<T> {
2764 self.ge(val)
2765 }
2766
2767 pub fn in_(&self, vals: &[i64]) -> Predicate<T> {
2769 Predicate::new(Expr::col(Alias::new(self.name)).is_in(vals.iter().copied()))
2770 }
2771
2772 pub fn in_subquery(&self, sub: super::Subquery) -> Predicate<T> {
2775 Predicate::new(Expr::col(Alias::new(self.name)).in_subquery(sub.into_statement()))
2776 }
2777
2778 pub fn asc(&self) -> OrderExpr<T> {
2780 OrderExpr::new(self.name, false)
2781 }
2782
2783 pub fn desc(&self) -> OrderExpr<T> {
2785 OrderExpr::new(self.name, true)
2786 }
2787}
2788
2789pub struct NullableForeignKeyCol<T> {
2791 pub(crate) name: &'static str,
2792 _phantom: PhantomData<T>,
2793}
2794
2795impl<T> NullableForeignKeyCol<T> {
2796 pub const fn new(name: &'static str) -> Self {
2797 Self {
2798 name,
2799 _phantom: PhantomData,
2800 }
2801 }
2802
2803 pub fn eq(&self, val: i64) -> Predicate<T> {
2805 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
2806 }
2807
2808 pub fn ne(&self, val: i64) -> Predicate<T> {
2810 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
2811 }
2812
2813 pub fn in_(&self, vals: &[i64]) -> Predicate<T> {
2815 Predicate::new(Expr::col(Alias::new(self.name)).is_in(vals.iter().copied()))
2816 }
2817
2818 pub fn is_null(&self) -> Predicate<T> {
2820 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
2821 }
2822
2823 pub fn is_not_null(&self) -> Predicate<T> {
2825 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
2826 }
2827
2828 pub fn asc(&self) -> OrderExpr<T> {
2830 OrderExpr::new(self.name, false)
2831 }
2832
2833 pub fn desc(&self) -> OrderExpr<T> {
2835 OrderExpr::new(self.name, true)
2836 }
2837}
2838
2839pub struct BytesCol<T> {
2849 pub(crate) name: &'static str,
2850 _phantom: PhantomData<T>,
2851}
2852
2853impl<T> BytesCol<T> {
2854 pub const fn new(name: &'static str) -> Self {
2855 Self {
2856 name,
2857 _phantom: PhantomData,
2858 }
2859 }
2860
2861 pub fn eq(&self, val: &[u8]) -> Predicate<T> {
2863 Predicate::new(Expr::col(Alias::new(self.name)).eq(val.to_vec()))
2864 }
2865
2866 pub fn ne(&self, val: &[u8]) -> Predicate<T> {
2868 Predicate::new(Expr::col(Alias::new(self.name)).ne(val.to_vec()))
2869 }
2870
2871 pub fn asc(&self) -> OrderExpr<T> {
2873 OrderExpr::new(self.name, false)
2874 }
2875
2876 pub fn desc(&self) -> OrderExpr<T> {
2878 OrderExpr::new(self.name, true)
2879 }
2880}
2881
2882pub struct NullableBytesCol<T> {
2884 pub(crate) name: &'static str,
2885 _phantom: PhantomData<T>,
2886}
2887
2888impl<T> NullableBytesCol<T> {
2889 pub const fn new(name: &'static str) -> Self {
2890 Self {
2891 name,
2892 _phantom: PhantomData,
2893 }
2894 }
2895
2896 pub fn eq(&self, val: &[u8]) -> Predicate<T> {
2897 Predicate::new(Expr::col(Alias::new(self.name)).eq(val.to_vec()))
2898 }
2899
2900 pub fn ne(&self, val: &[u8]) -> Predicate<T> {
2901 Predicate::new(Expr::col(Alias::new(self.name)).ne(val.to_vec()))
2902 }
2903
2904 pub fn is_null(&self) -> Predicate<T> {
2906 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
2907 }
2908
2909 pub fn is_not_null(&self) -> Predicate<T> {
2911 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
2912 }
2913
2914 pub fn asc(&self) -> OrderExpr<T> {
2915 OrderExpr::new(self.name, false)
2916 }
2917
2918 pub fn desc(&self) -> OrderExpr<T> {
2919 OrderExpr::new(self.name, true)
2920 }
2921}
2922
2923pub struct DecimalCol<T> {
2931 pub(crate) name: &'static str,
2932 _phantom: PhantomData<T>,
2933}
2934
2935impl<T> DecimalCol<T> {
2936 pub const fn new(name: &'static str) -> Self {
2937 Self {
2938 name,
2939 _phantom: PhantomData,
2940 }
2941 }
2942
2943 pub fn eq(&self, val: rust_decimal::Decimal) -> Predicate<T> {
2945 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
2946 }
2947
2948 pub fn ne(&self, val: rust_decimal::Decimal) -> Predicate<T> {
2950 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
2951 }
2952
2953 pub fn lt(&self, val: rust_decimal::Decimal) -> Predicate<T> {
2955 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
2956 }
2957
2958 pub fn le(&self, val: rust_decimal::Decimal) -> Predicate<T> {
2960 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
2961 }
2962
2963 pub fn lte(&self, val: rust_decimal::Decimal) -> Predicate<T> {
2965 self.le(val)
2966 }
2967
2968 pub fn gt(&self, val: rust_decimal::Decimal) -> Predicate<T> {
2970 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
2971 }
2972
2973 pub fn ge(&self, val: rust_decimal::Decimal) -> Predicate<T> {
2975 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
2976 }
2977
2978 pub fn gte(&self, val: rust_decimal::Decimal) -> Predicate<T> {
2980 self.ge(val)
2981 }
2982
2983 pub fn asc(&self) -> OrderExpr<T> {
2985 OrderExpr::new(self.name, false)
2986 }
2987
2988 pub fn desc(&self) -> OrderExpr<T> {
2990 OrderExpr::new(self.name, true)
2991 }
2992}
2993
2994pub struct NullableDecimalCol<T> {
3003 pub(crate) name: &'static str,
3004 _phantom: PhantomData<T>,
3005}
3006
3007impl<T> NullableDecimalCol<T> {
3008 pub const fn new(name: &'static str) -> Self {
3009 Self {
3010 name,
3011 _phantom: PhantomData,
3012 }
3013 }
3014
3015 pub fn eq(&self, val: rust_decimal::Decimal) -> Predicate<T> {
3017 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
3018 }
3019
3020 pub fn ne(&self, val: rust_decimal::Decimal) -> Predicate<T> {
3022 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
3023 }
3024
3025 pub fn lt(&self, val: rust_decimal::Decimal) -> Predicate<T> {
3027 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
3028 }
3029
3030 pub fn le(&self, val: rust_decimal::Decimal) -> Predicate<T> {
3032 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
3033 }
3034
3035 pub fn lte(&self, val: rust_decimal::Decimal) -> Predicate<T> {
3037 self.le(val)
3038 }
3039
3040 pub fn gt(&self, val: rust_decimal::Decimal) -> Predicate<T> {
3042 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
3043 }
3044
3045 pub fn ge(&self, val: rust_decimal::Decimal) -> Predicate<T> {
3047 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
3048 }
3049
3050 pub fn gte(&self, val: rust_decimal::Decimal) -> Predicate<T> {
3052 self.ge(val)
3053 }
3054
3055 pub fn is_null(&self) -> Predicate<T> {
3057 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
3058 }
3059
3060 pub fn is_not_null(&self) -> Predicate<T> {
3062 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
3063 }
3064
3065 pub fn asc(&self) -> OrderExpr<T> {
3067 OrderExpr::new(self.name, false)
3068 }
3069
3070 pub fn desc(&self) -> OrderExpr<T> {
3072 OrderExpr::new(self.name, true)
3073 }
3074}
3075
3076pub struct BigDecimalCol<T> {
3086 pub(crate) name: &'static str,
3087 _phantom: PhantomData<T>,
3088}
3089
3090impl<T> BigDecimalCol<T> {
3091 pub const fn new(name: &'static str) -> Self {
3092 Self {
3093 name,
3094 _phantom: PhantomData,
3095 }
3096 }
3097
3098 pub fn eq(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3100 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
3101 }
3102
3103 pub fn ne(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3105 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
3106 }
3107
3108 pub fn lt(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3110 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
3111 }
3112
3113 pub fn le(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3115 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
3116 }
3117
3118 pub fn lte(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3120 self.le(val)
3121 }
3122
3123 pub fn gt(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3125 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
3126 }
3127
3128 pub fn ge(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3130 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
3131 }
3132
3133 pub fn gte(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3135 self.ge(val)
3136 }
3137
3138 pub fn asc(&self) -> OrderExpr<T> {
3140 OrderExpr::new(self.name, false)
3141 }
3142
3143 pub fn desc(&self) -> OrderExpr<T> {
3145 OrderExpr::new(self.name, true)
3146 }
3147}
3148
3149pub struct NullableBigDecimalCol<T> {
3156 pub(crate) name: &'static str,
3157 _phantom: PhantomData<T>,
3158}
3159
3160impl<T> NullableBigDecimalCol<T> {
3161 pub const fn new(name: &'static str) -> Self {
3162 Self {
3163 name,
3164 _phantom: PhantomData,
3165 }
3166 }
3167
3168 pub fn eq(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3170 Predicate::new(Expr::col(Alias::new(self.name)).eq(val))
3171 }
3172
3173 pub fn ne(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3175 Predicate::new(Expr::col(Alias::new(self.name)).ne(val))
3176 }
3177
3178 pub fn lt(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3180 Predicate::new(Expr::col(Alias::new(self.name)).lt(val))
3181 }
3182
3183 pub fn le(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3185 Predicate::new(Expr::col(Alias::new(self.name)).lte(val))
3186 }
3187
3188 pub fn lte(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3190 self.le(val)
3191 }
3192
3193 pub fn gt(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3195 Predicate::new(Expr::col(Alias::new(self.name)).gt(val))
3196 }
3197
3198 pub fn ge(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3200 Predicate::new(Expr::col(Alias::new(self.name)).gte(val))
3201 }
3202
3203 pub fn gte(&self, val: bigdecimal::BigDecimal) -> Predicate<T> {
3205 self.ge(val)
3206 }
3207
3208 pub fn is_null(&self) -> Predicate<T> {
3210 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
3211 }
3212
3213 pub fn is_not_null(&self) -> Predicate<T> {
3215 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
3216 }
3217
3218 pub fn asc(&self) -> OrderExpr<T> {
3220 OrderExpr::new(self.name, false)
3221 }
3222
3223 pub fn desc(&self) -> OrderExpr<T> {
3225 OrderExpr::new(self.name, true)
3226 }
3227}
3228
3229pub struct GeometryCol<T> {
3242 pub(crate) name: &'static str,
3243 _phantom: PhantomData<T>,
3244}
3245
3246impl<T> GeometryCol<T> {
3247 pub const fn new(name: &'static str) -> Self {
3248 Self {
3249 name,
3250 _phantom: PhantomData,
3251 }
3252 }
3253
3254 pub fn dwithin(&self, other: &str, distance: f64) -> Predicate<T> {
3260 Predicate::new(Expr::cust_with_values(
3264 format!("ST_DWithin(\"{}\", ST_GeomFromEWKT($1), $2)", self.name),
3265 [
3266 sea_query::Value::from(other.to_string()),
3267 sea_query::Value::from(distance),
3268 ],
3269 ))
3270 }
3271
3272 pub fn dwithin_meters(&self, other: &str, meters: f64) -> Predicate<T> {
3280 Predicate::new(Expr::cust_with_values(
3281 format!(
3282 "ST_DWithin(\"{}\"::geography, ST_GeomFromEWKT($1)::geography, $2)",
3283 self.name
3284 ),
3285 [
3286 sea_query::Value::from(other.to_string()),
3287 sea_query::Value::from(meters),
3288 ],
3289 ))
3290 }
3291
3292 pub fn intersects(&self, other: &str) -> Predicate<T> {
3294 self.st_binary("ST_Intersects", other)
3295 }
3296
3297 pub fn contains(&self, other: &str) -> Predicate<T> {
3299 self.st_binary("ST_Contains", other)
3300 }
3301
3302 pub fn within(&self, other: &str) -> Predicate<T> {
3304 self.st_binary("ST_Within", other)
3305 }
3306
3307 pub fn bbox_overlaps(&self, other: &str) -> Predicate<T> {
3310 Predicate::new(Expr::cust_with_values(
3311 format!("\"{}\" && ST_GeomFromEWKT($1)", self.name),
3312 [sea_query::Value::from(other.to_string())],
3313 ))
3314 }
3315
3316 fn st_binary(&self, func: &str, other: &str) -> Predicate<T> {
3317 Predicate::new(Expr::cust_with_values(
3318 format!("{func}(\"{}\", ST_GeomFromEWKT($1))", self.name),
3319 [sea_query::Value::from(other.to_string())],
3320 ))
3321 }
3322
3323 pub fn is_null(&self) -> Predicate<T> {
3325 Predicate::new(Expr::col(Alias::new(self.name)).is_null())
3326 }
3327
3328 pub fn is_not_null(&self) -> Predicate<T> {
3330 Predicate::new(Expr::col(Alias::new(self.name)).is_not_null())
3331 }
3332}
3333
3334pub struct ColExpr<T> {
3353 expr: sea_query::SimpleExpr,
3354 expr_sqlite: Option<sea_query::SimpleExpr>,
3355 _phantom: PhantomData<T>,
3356}
3357
3358impl<T> ColExpr<T> {
3359 pub(crate) fn new(expr: sea_query::SimpleExpr) -> Self {
3361 Self {
3362 expr,
3363 expr_sqlite: None,
3364 _phantom: PhantomData,
3365 }
3366 }
3367
3368 pub(crate) fn new_with_sqlite(
3372 expr: sea_query::SimpleExpr,
3373 sqlite: sea_query::SimpleExpr,
3374 ) -> Self {
3375 Self {
3376 expr,
3377 expr_sqlite: Some(sqlite),
3378 _phantom: PhantomData,
3379 }
3380 }
3381
3382 fn into_predicate<F>(self, op: F) -> Predicate<T>
3385 where
3386 F: Fn(sea_query::SimpleExpr) -> sea_query::SimpleExpr,
3387 {
3388 let cond = op(self.expr);
3389 let cond_sqlite = self.expr_sqlite.map(&op);
3390 match cond_sqlite {
3391 Some(sql) => Predicate::new_with_sqlite(cond, sql),
3392 None => Predicate::new(cond),
3393 }
3394 }
3395
3396 pub fn eq<V: Into<sea_query::Value>>(self, val: V) -> Predicate<T> {
3398 let val = val.into();
3399 self.into_predicate(move |e| e.eq(val.clone()))
3400 }
3401
3402 pub fn ne<V: Into<sea_query::Value>>(self, val: V) -> Predicate<T> {
3404 let val = val.into();
3405 self.into_predicate(move |e| e.ne(val.clone()))
3406 }
3407
3408 pub fn lt<V: Into<sea_query::Value>>(self, val: V) -> Predicate<T> {
3410 let val = val.into();
3411 self.into_predicate(move |e| e.lt(val.clone()))
3412 }
3413
3414 pub fn le<V: Into<sea_query::Value>>(self, val: V) -> Predicate<T> {
3416 let val = val.into();
3417 self.into_predicate(move |e| e.lte(val.clone()))
3418 }
3419
3420 pub fn gt<V: Into<sea_query::Value>>(self, val: V) -> Predicate<T> {
3422 let val = val.into();
3423 self.into_predicate(move |e| e.gt(val.clone()))
3424 }
3425
3426 pub fn ge<V: Into<sea_query::Value>>(self, val: V) -> Predicate<T> {
3428 let val = val.into();
3429 self.into_predicate(move |e| e.gte(val.clone()))
3430 }
3431}
3432
3433pub trait StrColExt<T> {
3443 fn lower(&self) -> ColExpr<T>;
3445 fn upper(&self) -> ColExpr<T>;
3447 fn length(&self) -> ColExpr<T>;
3449 fn trim(&self) -> ColExpr<T>;
3452 fn coalesce<V: Into<sea_query::Value>>(&self, default: V) -> ColExpr<T>;
3456 fn concat<V: Into<sea_query::Value>>(&self, suffix: V) -> ColExpr<T>;
3459}
3460
3461fn str_trim_expr(name: &'static str) -> sea_query::SimpleExpr {
3463 Expr::cust(format!("TRIM(\"{}\")", name.replace('"', "\"\"")))
3464}
3465
3466fn str_coalesce_expr(name: &'static str, default: sea_query::Value) -> sea_query::SimpleExpr {
3471 let col: sea_query::SimpleExpr = Expr::col(Alias::new(name)).into();
3472 let def: sea_query::SimpleExpr = Expr::val(default).into();
3473 Func::coalesce([col, def]).into()
3474}
3475
3476fn str_concat_expr(name: &'static str, suffix: sea_query::Value) -> sea_query::SimpleExpr {
3480 Expr::col(Alias::new(name)).binary(sea_query::BinOper::Custom("||"), Expr::val(suffix))
3481}
3482
3483impl<T> StrColExt<T> for StrCol<T> {
3484 fn lower(&self) -> ColExpr<T> {
3485 ColExpr::new(Func::lower(Expr::col(Alias::new(self.name))).into())
3486 }
3487 fn upper(&self) -> ColExpr<T> {
3488 ColExpr::new(Func::upper(Expr::col(Alias::new(self.name))).into())
3489 }
3490 fn length(&self) -> ColExpr<T> {
3491 ColExpr::new(Func::char_length(Expr::col(Alias::new(self.name))).into())
3492 }
3493 fn trim(&self) -> ColExpr<T> {
3494 ColExpr::new(str_trim_expr(self.name))
3495 }
3496 fn coalesce<V: Into<sea_query::Value>>(&self, default: V) -> ColExpr<T> {
3497 ColExpr::new(str_coalesce_expr(self.name, default.into()))
3498 }
3499 fn concat<V: Into<sea_query::Value>>(&self, suffix: V) -> ColExpr<T> {
3500 ColExpr::new(str_concat_expr(self.name, suffix.into()))
3501 }
3502}
3503
3504impl<T> StrColExt<T> for NullableStrCol<T> {
3505 fn lower(&self) -> ColExpr<T> {
3506 ColExpr::new(Func::lower(Expr::col(Alias::new(self.name))).into())
3507 }
3508 fn upper(&self) -> ColExpr<T> {
3509 ColExpr::new(Func::upper(Expr::col(Alias::new(self.name))).into())
3510 }
3511 fn length(&self) -> ColExpr<T> {
3512 ColExpr::new(Func::char_length(Expr::col(Alias::new(self.name))).into())
3513 }
3514 fn trim(&self) -> ColExpr<T> {
3515 ColExpr::new(str_trim_expr(self.name))
3516 }
3517 fn coalesce<V: Into<sea_query::Value>>(&self, default: V) -> ColExpr<T> {
3518 ColExpr::new(str_coalesce_expr(self.name, default.into()))
3519 }
3520 fn concat<V: Into<sea_query::Value>>(&self, suffix: V) -> ColExpr<T> {
3521 ColExpr::new(str_concat_expr(self.name, suffix.into()))
3522 }
3523}
3524
3525pub trait DateTimeColExt<T> {
3533 fn year(&self) -> ColExpr<T>;
3535 fn month(&self) -> ColExpr<T>;
3537 fn day(&self) -> ColExpr<T>;
3539 fn hour(&self) -> ColExpr<T>;
3541 fn minute(&self) -> ColExpr<T>;
3543 fn second(&self) -> ColExpr<T>;
3546 fn week_day(&self) -> ColExpr<T>;
3554}
3555
3556fn date_part_exprs(
3557 col_name: &str,
3558 part_pg: &'static str,
3559 fmt_sqlite: &'static str,
3560) -> (sea_query::SimpleExpr, sea_query::SimpleExpr) {
3561 let pg = sea_query::SimpleExpr::Custom(format!(
3562 "CAST(EXTRACT({part_pg} FROM \"{col_name}\") AS INTEGER)"
3563 ));
3564 let sqlite = sea_query::SimpleExpr::Custom(format!(
3565 "CAST(strftime('{fmt_sqlite}', \"{col_name}\") AS INTEGER)"
3566 ));
3567 (pg, sqlite)
3568}
3569
3570impl<T> DateTimeColExt<T> for DateTimeCol<T> {
3571 fn year(&self) -> ColExpr<T> {
3572 let (pg, sqlite) = date_part_exprs(self.name, "YEAR", "%Y");
3573 ColExpr::new_with_sqlite(pg, sqlite)
3574 }
3575 fn month(&self) -> ColExpr<T> {
3576 let (pg, sqlite) = date_part_exprs(self.name, "MONTH", "%m");
3577 ColExpr::new_with_sqlite(pg, sqlite)
3578 }
3579 fn day(&self) -> ColExpr<T> {
3580 let (pg, sqlite) = date_part_exprs(self.name, "DAY", "%d");
3581 ColExpr::new_with_sqlite(pg, sqlite)
3582 }
3583 fn hour(&self) -> ColExpr<T> {
3584 let (pg, sqlite) = date_part_exprs(self.name, "HOUR", "%H");
3585 ColExpr::new_with_sqlite(pg, sqlite)
3586 }
3587 fn minute(&self) -> ColExpr<T> {
3588 let (pg, sqlite) = date_part_exprs(self.name, "MINUTE", "%M");
3589 ColExpr::new_with_sqlite(pg, sqlite)
3590 }
3591 fn second(&self) -> ColExpr<T> {
3592 let (pg, sqlite) = date_part_exprs(self.name, "SECOND", "%S");
3593 ColExpr::new_with_sqlite(pg, sqlite)
3594 }
3595 fn week_day(&self) -> ColExpr<T> {
3596 let (pg, sqlite) = date_part_exprs(self.name, "DOW", "%w");
3597 ColExpr::new_with_sqlite(pg, sqlite)
3598 }
3599}
3600
3601impl<T> DateTimeColExt<T> for NullableDateTimeCol<T> {
3602 fn year(&self) -> ColExpr<T> {
3603 let (pg, sqlite) = date_part_exprs(self.name, "YEAR", "%Y");
3604 ColExpr::new_with_sqlite(pg, sqlite)
3605 }
3606 fn month(&self) -> ColExpr<T> {
3607 let (pg, sqlite) = date_part_exprs(self.name, "MONTH", "%m");
3608 ColExpr::new_with_sqlite(pg, sqlite)
3609 }
3610 fn day(&self) -> ColExpr<T> {
3611 let (pg, sqlite) = date_part_exprs(self.name, "DAY", "%d");
3612 ColExpr::new_with_sqlite(pg, sqlite)
3613 }
3614 fn hour(&self) -> ColExpr<T> {
3615 let (pg, sqlite) = date_part_exprs(self.name, "HOUR", "%H");
3616 ColExpr::new_with_sqlite(pg, sqlite)
3617 }
3618 fn minute(&self) -> ColExpr<T> {
3619 let (pg, sqlite) = date_part_exprs(self.name, "MINUTE", "%M");
3620 ColExpr::new_with_sqlite(pg, sqlite)
3621 }
3622 fn second(&self) -> ColExpr<T> {
3623 let (pg, sqlite) = date_part_exprs(self.name, "SECOND", "%S");
3624 ColExpr::new_with_sqlite(pg, sqlite)
3625 }
3626 fn week_day(&self) -> ColExpr<T> {
3627 let (pg, sqlite) = date_part_exprs(self.name, "DOW", "%w");
3628 ColExpr::new_with_sqlite(pg, sqlite)
3629 }
3630}