1
+ #![ allow( dead_code) ]
2
+
1
3
extern crate futures;
2
4
extern crate reqwest;
3
5
extern crate tokio;
@@ -12,36 +14,36 @@ trait InfluxDbQuery {
12
14
impl InfluxDbQuery {
13
15
pub fn write ( ) -> InfluxDbWrite {
14
16
InfluxDbWrite {
15
- _measurement : String :: from ( "marina_3" ) ,
16
- _fields : Vec :: new ( ) ,
17
- _tags : Vec :: new ( ) ,
17
+ measurement : String :: from ( "marina_3" ) ,
18
+ fields : Vec :: new ( ) ,
19
+ tags : Vec :: new ( ) ,
18
20
}
19
21
}
20
22
21
23
// pub fn read() {}
22
24
}
23
25
24
26
pub struct InfluxDbWrite {
25
- _fields : Vec < ( String , String ) > ,
26
- _tags : Vec < ( String , String ) > ,
27
- _measurement : String ,
27
+ fields : Vec < ( String , String ) > ,
28
+ tags : Vec < ( String , String ) > ,
29
+ measurement : String ,
28
30
// precision: Precision
29
31
}
30
32
31
33
impl InfluxDbWrite {
32
- fn add_field < ' a , S > ( & ' a mut self , point : S , value : S ) -> & ' a mut Self
34
+ fn add_field < ' a , S > ( mut self , point : S , value : S ) -> Self
33
35
where
34
36
S : Into < String > ,
35
37
{
36
- self . _fields . push ( ( point. into ( ) , value. into ( ) ) ) ;
38
+ self . fields . push ( ( point. into ( ) , value. into ( ) ) ) ;
37
39
self
38
40
}
39
41
40
- fn add_tag < ' a , S > ( & ' a mut self , tag : S , value : S ) -> & ' a mut Self
42
+ fn add_tag < ' a , S > ( mut self , tag : S , value : S ) -> Self
41
43
where
42
44
S : Into < String > ,
43
45
{
44
- self . _tags . push ( ( tag. into ( ) , value. into ( ) ) ) ;
46
+ self . tags . push ( ( tag. into ( ) , value. into ( ) ) ) ;
45
47
self
46
48
}
47
49
}
@@ -50,13 +52,13 @@ impl InfluxDbQuery for InfluxDbWrite {
50
52
// fixme: time (with precision) and measurement
51
53
fn build < ' a > ( self ) -> String {
52
54
let tags = self
53
- . _tags
55
+ . tags
54
56
. into_iter ( )
55
57
. map ( |( tag, value) | format ! ( "{tag}={value}" , tag = tag, value = value) )
56
58
. collect :: < Vec < String > > ( )
57
59
. join ( "," ) ;
58
60
let fields = self
59
- . _fields
61
+ . fields
60
62
. into_iter ( )
61
63
. map ( |( field, value) | format ! ( "{field}={value}" , field = field, value = value) )
62
64
. collect :: < Vec < String > > ( )
@@ -71,8 +73,8 @@ impl InfluxDbQuery for InfluxDbWrite {
71
73
}
72
74
73
75
pub struct InfluxDbClient {
74
- _url : String ,
75
- _database : String ,
76
+ url : String ,
77
+ database : String ,
76
78
// _auth: InfluxDbAuthentication | NoAuthentication
77
79
}
78
80
@@ -81,7 +83,7 @@ pub fn main() {}
81
83
impl InfluxDbClient {
82
84
pub fn ping ( & self ) -> impl Future < Item = ( String , String ) , Error = ( ) > {
83
85
Client :: new ( )
84
- . get ( format ! ( "{}/ping" , self . _url ) . as_str ( ) )
86
+ . get ( format ! ( "{}/ping" , self . url ) . as_str ( ) )
85
87
. send ( )
86
88
. map ( |res| {
87
89
let build = res
@@ -114,16 +116,16 @@ mod tests {
114
116
115
117
fn create_client ( ) -> InfluxDbClient {
116
118
InfluxDbClient {
117
- _url : String :: from ( "http://localhost:8086" ) ,
118
- _database : String :: from ( "test" ) ,
119
+ url : String :: from ( "http://localhost:8086" ) ,
120
+ database : String :: from ( "test" ) ,
119
121
}
120
122
}
121
123
122
124
#[ test]
123
125
fn test_ping ( ) {
124
126
let client = create_client ( ) ;
125
127
let result = get_runtime ( ) . block_on ( client. ping ( ) ) ;
126
- assert ! ( ! result. is_err ( ) , "Should be no error" ) ;
128
+ assert ! ( result. is_ok ( ) , "Should be no error" ) ;
127
129
128
130
let ( build, version) = result. unwrap ( ) ;
129
131
assert ! ( !build. is_empty( ) , "Build should not be empty" ) ;
@@ -134,19 +136,19 @@ mod tests {
134
136
135
137
#[ test]
136
138
fn test_write_builder_single_field ( ) {
137
- let mut query = InfluxDbQuery :: write ( ) ;
138
-
139
- query . add_field ( "water_level" , "2" ) ;
139
+ let query = InfluxDbQuery :: write ( )
140
+ . add_field ( "water_level" , "2" ) ;
141
+
140
142
assert_eq ! ( query. build( ) , "measurement, water_level=2 time" ) ;
141
143
}
142
144
143
145
#[ test]
144
146
fn test_write_builder_multiple_fields ( ) {
145
- let mut query = InfluxDbQuery :: write ( ) ;
147
+ let query = InfluxDbQuery :: write ( )
148
+ . add_field ( "water_level" , "2" )
149
+ . add_field ( "boat_count" , "31" )
150
+ . add_field ( "algae_content" , "0.85" ) ;
146
151
147
- query. add_field ( "water_level" , "2" ) ;
148
- query. add_field ( "boat_count" , "31" ) ;
149
- query. add_field ( "algae_content" , "0.85" ) ;
150
152
assert_eq ! (
151
153
query. build( ) ,
152
154
"measurement, water_level=2,boat_count=31,algae_content=0.85 time"
@@ -157,18 +159,18 @@ mod tests {
157
159
// fixme: quoting / escaping of long strings
158
160
#[ test]
159
161
fn test_write_builder_single_tag ( ) {
160
- let mut query = InfluxDbQuery :: write ( ) ;
162
+ let query = InfluxDbQuery :: write ( )
163
+ . add_tag ( "marina_manager" , "Smith" ) ;
161
164
162
- query. add_tag ( "marina_manager" , "Smith" ) ;
163
165
assert_eq ! ( query. build( ) , "measurement,marina_manager=Smith time" ) ;
164
166
}
165
167
166
168
#[ test]
167
169
fn test_write_builder_multiple_tags ( ) {
168
- let mut query = InfluxDbQuery :: write ( ) ;
170
+ let query = InfluxDbQuery :: write ( )
171
+ . add_tag ( "marina_manager" , "Smith" )
172
+ . add_tag ( "manager_to_the_marina_manager" , "Jonson" ) ;
169
173
170
- query. add_tag ( "marina_manager" , "Smith" ) ;
171
- query. add_tag ( "manager_to_the_marina_manager" , "Jonson" ) ;
172
174
assert_eq ! (
173
175
query. build( ) ,
174
176
"measurement,marina_manager=Smith,manager_to_the_marina_manager=Jonson time"
@@ -177,16 +179,21 @@ mod tests {
177
179
178
180
#[ test]
179
181
fn test_write_builder_full_query ( ) {
180
- let mut query = InfluxDbQuery :: write ( ) ;
182
+ let query = InfluxDbQuery :: write ( )
183
+ . add_field ( "water_level" , "2" )
184
+ . add_field ( "boat_count" , "31" )
185
+ . add_field ( "algae_content" , "0.85" )
186
+ . add_tag ( "marina_manager" , "Smith" )
187
+ . add_tag ( "manager_to_the_marina_manager" , "Jonson" ) ;
181
188
182
- query. add_field ( "water_level" , "2" ) ;
183
- query. add_field ( "boat_count" , "31" ) ;
184
- query. add_field ( "algae_content" , "0.85" ) ;
185
- query. add_tag ( "marina_manager" , "Smith" ) ;
186
- query. add_tag ( "manager_to_the_marina_manager" , "Jonson" ) ;
187
189
assert_eq ! (
188
190
query. build( ) ,
189
191
"measurement,marina_manager=Smith,manager_to_the_marina_manager=Jonson water_level=2,boat_count=31,algae_content=0.85 time"
190
192
) ;
191
193
}
192
- }
194
+
195
+ #[ test]
196
+ fn test_test ( ) {
197
+ InfluxDbQuery :: write ( ) . add_field ( "test" , "1" ) . add_tag ( "my_tag" , "0.85" ) . build ( ) ;
198
+ }
199
+ }
0 commit comments