docs: fix README for influxdb_iox_client (#4825)

Closes #4816
pull/24376/head
Luke Bond 2022-06-10 10:13:17 +01:00 committed by GitHub
parent 50697906b1
commit aa97c918b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 47 deletions

View File

@ -2,61 +2,36 @@
This is the official Rust client library for connecting to InfluxDB IOx.
## Using the HTTP API
Currently only gRPC is supported.
If you only want to use the HTTP API, create an `influxdb_iox_client::Client`. Here is an example of
creating an instance that connects to an IOx server running at `http://127.0.0.1:8080` and creating
a database named `telemetry`:
## Using the gRPC Write Client
To write to IOx, create a connection and a write client, and then send line
protocol. Here is an example of creating an instance that connects to an IOx
server running at `http://127.0.0.1:8081` (the default bind address for the
gRPC endpoint of IOx when running in all-in-one mode) and sending a line of
line protocol:
```rust
#[tokio::main]
fn main() {
use data_types::database_rules::DatabaseRules;
use influxdb_iox_client::ClientBuilder;
use influxdb_iox_client::{
write::Client,
connection::Builder,
};
let client = ClientBuilder::default()
.build("http://127.0.0.1:8080")
.expect("client should be valid");
client
.create_database("telemetry", &DatabaseRules::default())
let mut connection = Builder::default()
.build("http://127.0.0.1:8081")
.await
.expect("failed to create database");
}
```
.unwrap();
## Using the Arrow Flight API
let mut client = Client::new(connection);
IOx supports an [Arrow Flight gRPC API](https://arrow.apache.org/docs/format/Flight.html). To use
it, enable the `flight` feature, which is off by default:
```toml
[dependencies]
influxdb_iox_client = { version = "[..]", features = ["flight"] }
```
Then you can create an `influxdb_iox_client::FlightClient` by using the `FlightClientBuilder`. Here
is an example of creating an instance that connects to an IOx server with its gRPC services
available at `http://localhost:8082` and using it to perform a query:
```rust
#[tokio::main]
fn main() {
use data_types::database_rules::DatabaseRules;
use influxdb_iox_client::FlightClientBuilder;
let client = FlightClientBuilder::default()
.build("http://127.0.0.1:8082")
.expect("client should be valid");
let mut query_results = client
.perform_query(scenario.database_name(), sql_query)
.await;
let mut batches = vec![];
while let Some(data) = query_results.next().await {
batches.push(data);
// write a line of line procol data
client
.write_lp("bananas", "cpu,region=west user=23.2 100",0)
.await
.expect("failed to write to IOx");
}
}
```

View File

@ -29,7 +29,7 @@ use crate::error::Error;
/// client
/// .write_lp("bananas", "cpu,region=west user=23.2 100",0)
/// .await
/// .expect("failed to create database");
/// .expect("failed to write to IOx");
/// # }
/// ```
#[derive(Debug, Clone)]