pub struct Client { /* private fields */ }Expand description
InfluxDB 2.x streaming client.
This client executes Flux queries and returns results as an async stream, allowing you to process millions of rows without loading them all into memory.
§Example
ⓘ
use influxdb_stream::Client;
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new("http://localhost:8086", "my-org", "my-token");
let mut stream = client.query_stream(r#"
from(bucket: "sensors")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "temperature")
"#).await?;
while let Some(record) = stream.next().await {
let record = record?;
println!("Got: {:?}", record);
}
Ok(())
}Implementations§
Source§impl Client
impl Client
Sourcepub fn new(
url: impl Into<String>,
org: impl Into<String>,
token: impl Into<String>,
) -> Self
pub fn new( url: impl Into<String>, org: impl Into<String>, token: impl Into<String>, ) -> Self
Sourcepub fn with_http_client(
http: Client,
url: impl Into<String>,
org: impl Into<String>,
token: impl Into<String>,
) -> Self
pub fn with_http_client( http: Client, url: impl Into<String>, org: impl Into<String>, token: impl Into<String>, ) -> Self
Create a new client with a custom reqwest client.
This allows you to configure timeouts, proxies, TLS settings, etc.
Sourcepub async fn query_stream(
&self,
query: impl Into<String>,
) -> Result<Pin<Box<dyn Stream<Item = Result<FluxRecord>> + Send>>>
pub async fn query_stream( &self, query: impl Into<String>, ) -> Result<Pin<Box<dyn Stream<Item = Result<FluxRecord>> + Send>>>
Execute a Flux query and return results as an async stream.
This is the primary method for querying InfluxDB. Results are streamed one record at a time, so you can process arbitrarily large result sets without running out of memory.
§Arguments
query- Flux query string
§Returns
A stream of Result<FluxRecord>. Each item is either a successfully
parsed record or an error.
§Example
ⓘ
use futures::StreamExt;
let mut stream = client.query_stream("from(bucket: \"test\") |> range(start: -1h)").await?;
let mut count = 0;
while let Some(result) = stream.next().await {
let record = result?;
count += 1;
}
println!("Processed {} records", count);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more