1
1
//! Utility functions
2
2
3
3
use rorm_sql:: value:: { NullType , Value } ;
4
- use sqlx:: types:: chrono:: { DateTime , NaiveDate , NaiveDateTime , NaiveTime , Utc } ;
5
- use sqlx:: types:: time:: { Date , OffsetDateTime , PrimitiveDateTime , Time } ;
6
- use sqlx:: types:: { Json , Uuid } ;
4
+ use sqlx:: types:: Json ;
7
5
8
- use super :: any:: AnyQuery ;
6
+ use super :: any:: { AnyEncode , AnyQuery , AnyType } ;
9
7
10
8
/// This helper method is used to bind ConditionValues to the query.
11
9
pub fn bind_param < ' post_query , ' query > ( query : & mut AnyQuery < ' query > , param : Value < ' post_query > )
41
39
42
40
Value :: JsonValue ( x) => query. bind ( Json ( x) ) ,
43
41
42
+ #[ cfg( feature = "postgres-only" ) ]
43
+ Value :: MacAddress ( x) => query. bind ( x) ,
44
+ #[ cfg( feature = "postgres-only" ) ]
45
+ Value :: IpNetwork ( x) => query. bind ( x) ,
46
+ #[ cfg( feature = "postgres-only" ) ]
47
+ Value :: BitVec ( x) => query. bind ( x) ,
48
+
44
49
Value :: Null ( null_type) => match null_type {
45
50
NullType :: String => query. bind ( None :: < & str > ) ,
46
51
NullType :: I64 => query. bind ( None :: < i64 > ) ,
@@ -52,21 +57,37 @@ where
52
57
NullType :: Binary => query. bind ( None :: < & [ u8 ] > ) ,
53
58
NullType :: Choice => { }
54
59
55
- NullType :: ChronoNaiveTime => query. bind ( None :: < NaiveTime > ) ,
56
- NullType :: ChronoNaiveDate => query. bind ( None :: < NaiveDate > ) ,
57
- NullType :: ChronoNaiveDateTime => query. bind ( None :: < NaiveDateTime > ) ,
58
- NullType :: ChronoDateTime => query. bind ( None :: < DateTime < Utc > > ) ,
60
+ NullType :: ChronoNaiveTime => query. bind ( none ( Value :: ChronoNaiveTime ) ) ,
61
+ NullType :: ChronoNaiveDate => query. bind ( none ( Value :: ChronoNaiveDate ) ) ,
62
+ NullType :: ChronoNaiveDateTime => query. bind ( none ( Value :: ChronoNaiveDateTime ) ) ,
63
+ NullType :: ChronoDateTime => query. bind ( none ( Value :: ChronoDateTime ) ) ,
59
64
60
- NullType :: TimeDate => query. bind ( None :: < Date > ) ,
61
- NullType :: TimeTime => query. bind ( None :: < Time > ) ,
62
- NullType :: TimeOffsetDateTime => query. bind ( None :: < OffsetDateTime > ) ,
63
- NullType :: TimePrimitiveDateTime => query. bind ( None :: < PrimitiveDateTime > ) ,
65
+ NullType :: TimeDate => query. bind ( none ( Value :: TimeDate ) ) ,
66
+ NullType :: TimeTime => query. bind ( none ( Value :: TimeTime ) ) ,
67
+ NullType :: TimeOffsetDateTime => query. bind ( none ( Value :: TimeOffsetDateTime ) ) ,
68
+ NullType :: TimePrimitiveDateTime => query. bind ( none ( Value :: TimePrimitiveDateTime ) ) ,
64
69
65
- NullType :: Uuid => query. bind ( None :: < Uuid > ) ,
70
+ NullType :: Uuid => query. bind ( none ( Value :: Uuid ) ) ,
66
71
NullType :: UuidHyphenated => query. bind ( None :: < String > ) ,
67
72
NullType :: UuidSimple => query. bind ( None :: < String > ) ,
68
73
69
- NullType :: JsonValue => query. bind ( None :: < Json < ( ) > > ) ,
74
+ NullType :: JsonValue => query. bind ( none ( Value :: JsonValue ) ) ,
75
+
76
+ #[ cfg( feature = "postgres-only" ) ]
77
+ NullType :: MacAddress => query. bind ( none ( Value :: MacAddress ) ) ,
78
+ #[ cfg( feature = "postgres-only" ) ]
79
+ NullType :: IpNetwork => query. bind ( none ( Value :: IpNetwork ) ) ,
80
+ #[ cfg( feature = "postgres-only" ) ]
81
+ NullType :: BitVec => query. bind ( none ( Value :: BitVec ) ) ,
70
82
} ,
71
83
}
72
84
}
85
+
86
+ /// Little helper hack to avoid using naming the types
87
+ fn none < ' a , T , F > ( _value_variant : F ) -> Option < T >
88
+ where
89
+ F : Fn ( T ) -> Value < ' a > ,
90
+ Option < T > : ' a + Send + AnyEncode < ' a > + AnyType ,
91
+ {
92
+ None
93
+ }
0 commit comments