|
28 | 28 | //!
|
29 | 29 | //! ```rust,no_run
|
30 | 30 | //! use influxdb::{Client, Query, Timestamp};
|
31 |
| -//! use serde::Deserialize; |
32 |
| -//! use tokio::runtime::current_thread::Runtime; |
33 | 31 | //!
|
| 32 | +//! # #[tokio::main] |
| 33 | +//! # async fn main() { |
34 | 34 | //! // Create a Client with URL `http://localhost:8086`
|
35 | 35 | //! // and database name `test`
|
36 | 36 | //! let client = Client::new("http://localhost:8086", "test");
|
|
41 | 41 | //! let write_query = Query::write_query(Timestamp::Now, "weather")
|
42 | 42 | //! .add_field("temperature", 82);
|
43 | 43 | //!
|
44 |
| -//! // Since this library is async by default, we're going to need a Runtime, |
45 |
| -//! // which can asynchonously run our query. |
46 |
| -//! // The [tokio](https://crates.io/crates/tokio) crate lets us easily create a new Runtime. |
47 |
| -//! let mut rt = Runtime::new().expect("Unable to create a runtime"); |
48 |
| -//! |
49 |
| -//! // To actually submit the data to InfluxDB, the `block_on` method can be used to |
50 |
| -//! // halt execution of our program until it has been completed. |
51 |
| -//! let write_result = rt.block_on(client.query(&write_query)); |
| 44 | +//! // Submit the query to InfluxDB. |
| 45 | +//! let write_result = client.query(&write_query).await; |
52 | 46 | //! assert!(write_result.is_ok(), "Write result was not okay");
|
53 | 47 | //!
|
54 | 48 | //! // Reading data is as simple as writing. First we need to create a query
|
55 | 49 | //! let read_query = Query::raw_read_query("SELECT * FROM weather");
|
56 | 50 | //!
|
57 |
| -//! // Again, we're blocking until the request is done |
58 |
| -//! let read_result = rt.block_on(client.query(&read_query)); |
| 51 | +//! // submit the request and wait until it's done |
| 52 | +//! let read_result = client.query(&read_query).await; |
59 | 53 | //!
|
60 | 54 | //! assert!(read_result.is_ok(), "Read result was not ok");
|
61 | 55 | //!
|
62 | 56 | //! // We can be sure the result was successful, so we can unwrap the result to get
|
63 | 57 | //! // the response String from InfluxDB
|
64 | 58 | //! println!("{}", read_result.unwrap());
|
| 59 | +//! # } |
65 | 60 | //! ```
|
66 | 61 | //!
|
67 | 62 | //! For further examples, check out the Integration Tests in `tests/integration_tests.rs`
|
|
0 commit comments