File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -22,11 +22,23 @@ impl Query {
22
22
}
23
23
}
24
24
25
- pub fn param < T : std :: convert :: Into < BoltType > > ( mut self , key : & str , value : T ) -> Self {
25
+ pub fn param < T : Into < BoltType > > ( mut self , key : & str , value : T ) -> Self {
26
26
self . params . put ( key. into ( ) , value. into ( ) ) ;
27
27
self
28
28
}
29
29
30
+ pub fn params < K , V > ( mut self , input_params : impl IntoIterator < Item = ( K , V ) > ) -> Self
31
+ where
32
+ K : Into < BoltString > ,
33
+ V : Into < BoltType > ,
34
+ {
35
+ for ( key, value) in input_params {
36
+ self . params . put ( key. into ( ) , value. into ( ) ) ;
37
+ }
38
+
39
+ self
40
+ }
41
+
30
42
pub ( crate ) async fn run (
31
43
self ,
32
44
config : & Config ,
@@ -64,3 +76,23 @@ impl Query {
64
76
}
65
77
}
66
78
}
79
+
80
+ #[ cfg( test) ]
81
+ mod tests {
82
+ use super :: * ;
83
+
84
+ #[ test]
85
+ fn add_params ( ) {
86
+ let q = Query :: new ( "MATCH (n) WHERE n.name = $name AND n.age > $age RETURN n" . to_owned ( ) ) ;
87
+ let q = q. params ( [
88
+ ( "name" , BoltType :: from ( "Frobniscante" ) ) ,
89
+ ( "age" , BoltType :: from ( 42 ) ) ,
90
+ ] ) ;
91
+
92
+ assert_eq ! (
93
+ q. params. get:: <String >( "name" ) . unwrap( ) ,
94
+ String :: from( "Frobniscante" )
95
+ ) ;
96
+ assert_eq ! ( q. params. get:: <i64 >( "age" ) . unwrap( ) , 42 ) ;
97
+ }
98
+ }
You can’t perform that action at this time.
0 commit comments