Skip to content

Commit 8a98d38

Browse files
committed
Updates from integrating into jetlag
1 parent 78df5a3 commit 8a98d38

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/integrations/serde_integration.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct InfluxDbSeries<T> {
3838
}
3939

4040
impl InfluxDbClient {
41-
pub fn json_query<T: 'static, Q>(self, q: Q) -> Box<dyn Future<Item = Option<Vec<T>>, Error = InfluxDbError>>
41+
pub fn json_query<T: 'static, Q>(&self, q: Q) -> Box<dyn Future<Item = Option<Vec<InfluxDbSeries<T>>>, Error = InfluxDbError>>
4242
where
4343
Q: InfluxDbQuery,
4444
T: DeserializeOwned,
@@ -56,7 +56,7 @@ impl InfluxDbClient {
5656
let error = InfluxDbError::UnspecifiedError {
5757
error: format!("{}", err),
5858
};
59-
return Box::new(future::err::<Option<Vec<T>>, InfluxDbError>(error));
59+
return Box::new(future::err::<Option<Vec<InfluxDbSeries<T>>>, InfluxDbError>(error));
6060
}
6161
Ok(query) => query,
6262
};
@@ -102,13 +102,13 @@ impl InfluxDbClient {
102102
error: format!("{}", err)
103103
})
104104
.and_then(|body| {
105-
println!("{:?}", &body);
106105
// Try parsing InfluxDBs { "error": "error message here" }
107106
if let Ok(error) = serde_json::from_slice::<_DatabaseError>(&body) {
108107
return futures::future::err(InfluxDbError::DatabaseError {
109108
error: error.error.to_string()
110109
})
111110
} else {
111+
// Json has another structure, let's try actually parsing it to the type we're deserializing
112112
let from_slice = serde_json::from_slice::<DatabaseQueryResult<T>>(&body);
113113

114114
let mut deserialized = match from_slice {
@@ -118,12 +118,7 @@ impl InfluxDbClient {
118118
})
119119
};
120120

121-
// Json has another structure, let's try actually parsing it to the type we're deserializing to
122-
let t_result = match deserialized.results.remove(0).series {
123-
Some(series) => Ok(Some(series.into_iter().flat_map(|x| { x.values }).collect::<Vec<T>>())),
124-
None => Ok(None)
125-
};
126-
return futures::future::result(t_result);
121+
return futures::future::result(Ok(deserialized.results.remove(0).series));
127122
}
128123
})
129124
)

src/query/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use crate::query::write_query::InfluxDbWriteQuery;
1919
///
2020
/// assert!(write_query.is_ok());
2121
///
22-
/// //todo: document read query once it's implemented.
22+
/// let read_query = InfluxDbQuery::raw_read_query("SELECT * FROM weather")
23+
/// .build();
24+
///
25+
/// assert!(read_query.is_ok());
2326
/// ```
2427
pub trait InfluxDbQuery {
2528
/// Builds valid InfluxSQL which can be run against the Database.

0 commit comments

Comments
 (0)