diff --git a/.travis.yml b/.travis.yml index 7de78c8..171cfbb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,7 @@ rust: - stable - beta - nightly + - 1.39.0 matrix: fast_finish: true @@ -37,8 +38,8 @@ matrix: - rust: stable env: NAME='linting' before_script: - - rustup component add rustfmt-preview - - rustup component add clippy-preview + - rustup component add rustfmt + - rustup component add clippy script: - cargo fmt --all -- --check - cargo clippy --all-targets --all-features -- -D warnings diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a41798..557a5e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Rewrite to `async` / `await`. Rust 1.39 is now the minimum required Rust version. + ## [0.0.5] - 2019-08-16 This release removes the prefix `InfluxDb` of most types in this library and reexports the types under the `influxdb::` path. In most cases, you can directly use the types now: e.g. `influxdb::Client` vs `influxdb::client::InfluxDbClient`. diff --git a/Cargo.toml b/Cargo.toml index 2b2b74d..ce24b1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,15 +14,17 @@ repository = "https://github.com/Empty2k12/influxdb-rust" travis-ci = { repository = "Empty2k12/influxdb-rust", branch = "master" } [dependencies] -reqwest = "0.9.17" -futures = "0.1.27" -tokio = "0.1.20" +chrono = { version = "0.4.9", optional = true } failure = "0.1.5" -serde = { version = "1.0.92", optional = true } +futures = "0.3.1" +reqwest = { version = "0.10", features = ["json"] } +serde = { version = "1.0.92", features = ["derive"], optional = true } serde_json = { version = "1.0", optional = true } -chrono = { version = "0.4.9", optional = true } [features] use-serde = ["serde", "serde_json"] chrono_timestamps = ["chrono"] default = ["use-serde"] + +[dev-dependencies] +tokio = { version = "0.2", features = ["macros"] } diff --git a/README.md b/README.md index 91d8309..b196c83 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ + + +
This library is a work in progress. Although we've been using it in production at [OpenVelo](https://openvelo.org/), @@ -54,8 +57,6 @@ For an example with using Serde deserialization, please refer to [serde_integrat ```rust use influxdb::{Client, Query, Timestamp}; -use serde::Deserialize; -use tokio::runtime::current_thread::Runtime; // Create a Client with URL `http://localhost:8086` // and database name `test` @@ -67,21 +68,15 @@ let client = Client::new("http://localhost:8086", "test"); let write_query = Query::write_query(Timestamp::Now, "weather") .add_field("temperature", 82); -// Since this library is async by default, we're going to need a Runtime, -// which can asynchonously run our query. -// The [tokio](https://crates.io/crates/tokio) crate lets us easily create a new Runtime. -let mut rt = Runtime::new().expect("Unable to create a runtime"); - -// To actually submit the data to InfluxDB, the `block_on` method can be used to -// halt execution of our program until it has been completed. -let write_result = rt.block_on(client.query(&write_query)); +// Submit the query to InfluxDB. +let write_result = client.query(&write_query).await; assert!(write_result.is_ok(), "Write result was not okay"); // Reading data is as simple as writing. First we need to create a query let read_query = Query::raw_read_query("SELECT * FROM weather"); -// Again, we're blocking until the request is done -let read_result = rt.block_on(client.query(&read_query)); +// submit the request and wait until it's done +let read_result = client.query(&read_query).await; assert!(read_result.is_ok(), "Read result was not ok"); diff --git a/README.tpl b/README.tpl index 3ecb796..633da45 100644 --- a/README.tpl +++ b/README.tpl @@ -22,6 +22,9 @@ + + + {{readme}} diff --git a/src/client/mod.rs b/src/client/mod.rs index d5f6432..2911f85 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -15,11 +15,8 @@ //! assert_eq!(client.database_name(), "test"); //! ``` -use futures::{Future, Stream}; -use reqwest::r#async::{Client as ReqwestClient, Decoder}; -use reqwest::{StatusCode, Url}; - -use std::mem; +use futures::prelude::*; +use reqwest::{self, Client as ReqwestClient, StatusCode, Url}; use crate::query::QueryTypes; use crate::Error; @@ -130,29 +127,27 @@ impl Client { /// Pings the InfluxDB Server /// /// Returns a tuple of build type and version number - pub fn ping(&self) -> impl Future