|
| 1 | +<div align="center"> |
| 2 | + <br/> |
| 3 | + <img |
| 4 | + alt="rust-influxdb" |
| 5 | + src="https://i.imgur.com/4k7l8XJ.png" |
| 6 | + width=250px /> |
| 7 | + <br/> |
| 8 | + <br/> |
| 9 | + <strong>Unofficial InfluxDB Driver for Rust</strong> |
| 10 | +</div> |
| 11 | +<br/> |
| 12 | +<p align="center"> |
| 13 | + <a href="https://travis-ci.org/Empty2k12/influxdb-rust"> |
| 14 | + <img src="https://travis-ci.org/Empty2k12/influxdb-rust.svg?branch=master" alt='Build Status' /> |
| 15 | + </a> |
| 16 | + <a href="https://coveralls.io/github/Empty2k12/influxdb-rust?branch=master"> |
| 17 | + <img src="https://coveralls.io/repos/github/Empty2k12/influxdb-rust/badge.svg?branch=master" alt='Coverage Status' /> |
| 18 | + </a> |
| 19 | + <a href="https://docs.rs/crate/influxdb"> |
| 20 | + <img src="https://docs.rs/influxdb/badge.svg" alt='Documentation Status' /> |
| 21 | + </a> |
| 22 | + <a href="https://www.rust-lang.org/en-US/"> |
| 23 | + <img src="https://img.shields.io/badge/Made%20with-Rust-orange.svg" alt='Build with Rust' /> |
| 24 | + </a> |
| 25 | +</p> |
| 26 | + |
| 27 | +This library is a work in progress. Although we've been using it in production at [OpenVelo](https://openvelo.org/), |
| 28 | +we're prioritized features that fit our use cases. This means a feature you might need is not implemented |
| 29 | +yet or could be handled better. |
| 30 | + |
| 31 | +Pull requests are always welcome. |
| 32 | + |
| 33 | +## Currently Supported Features |
| 34 | + |
| 35 | +- Reading and Writing to InfluxDB |
| 36 | +- Optional Serde Support for Deserialization |
| 37 | + |
| 38 | +## Planned Features |
| 39 | + |
| 40 | +- Running multiple queries in one request (e.g. `SELECT * FROM weather_berlin; SELECT * FROM weather_london`) |
| 41 | +- Read Query Builder instead of supplying raw queries |
| 42 | +- Authentication against InfluxDB |
| 43 | +- Methods for setting time and time precision in a query |
| 44 | + |
| 45 | +## Quickstart |
| 46 | + |
| 47 | +Add the following to your `Cargo.toml` |
| 48 | + |
| 49 | +```toml |
| 50 | +influxdb = "0.0.1" |
| 51 | +``` |
| 52 | + |
| 53 | +For an example with using Serde deserialization, please refer to [serde_integration](crate::integrations::serde_integration) |
| 54 | + |
| 55 | +```rust |
| 56 | +use influxdb::query::InfluxDbQuery; |
| 57 | +use influxdb::client::InfluxDbClient; |
| 58 | +use serde::Deserialize; |
| 59 | +use tokio::runtime::current_thread::Runtime; |
| 60 | + |
| 61 | +// Create a InfluxDbClient with URL `http://localhost:8086` |
| 62 | +// and database name `test` |
| 63 | +let client = InfluxDbClient::new("http://localhost:8086", "test"); |
| 64 | + |
| 65 | +// Let's write something to InfluxDB. First we're creating a |
| 66 | +// InfluxDbWriteQuery to write some data. |
| 67 | +// This creates a query which writes a new measurement into a series called `weather` |
| 68 | +let write_query = InfluxDbQuery::write_query("weather") |
| 69 | + .add_field("temperature", 82); |
| 70 | + |
| 71 | +// Since this library is async by default, we're going to need a Runtime, |
| 72 | +// which can asynchonously run our query. |
| 73 | +// The [tokio](https://crates.io/crates/tokio) crate lets us easily create a new Runtime. |
| 74 | +let mut rt = Runtime::new().expect("Unable to create a runtime"); |
| 75 | + |
| 76 | +// To actually submit the data to InfluxDB, the `block_on` method can be used to |
| 77 | +// halt execution of our program until it has been completed. |
| 78 | +let write_result = rt.block_on(client.query(write_query)); |
| 79 | +assert!(write_result.is_ok(), "Write result was not okay"); |
| 80 | + |
| 81 | +// Reading data is as simple as writing. First we need to create a query |
| 82 | +let read_query = InfluxDbQuery::raw_read_query("SELECT _ FROM weather"); |
| 83 | + |
| 84 | +// Again, we're blocking until the request is done |
| 85 | +let read_result = rt.block_on(client.query(read_query)); |
| 86 | + |
| 87 | +assert!(read_result.is_ok(), "Read result was not ok"); |
| 88 | + |
| 89 | +// We can be sure the result was successful, so we can unwrap the result to get |
| 90 | +// the response String from InfluxDB |
| 91 | +println!("{}", read_result.unwrap()); |
| 92 | +``` |
| 93 | + |
| 94 | +For further examples, check out the Integration Tests in `tests/integration_tests.rs` |
| 95 | +in the repository. |
| 96 | + |
| 97 | +## License |
| 98 | + |
| 99 | +The MIT License @ Gero Gerke 2019 |
0 commit comments