pub struct AnalyticsEngineDataPointBuilder { /* private fields */ }
Implementations§
Source§impl AnalyticsEngineDataPointBuilder
impl AnalyticsEngineDataPointBuilder
pub fn new() -> Self
Sourcepub fn indexes<'index>(self, indexes: impl AsRef<[&'index str]>) -> Self
pub fn indexes<'index>(self, indexes: impl AsRef<[&'index str]>) -> Self
Sets the index values for the data point. While the indexes field accepts an array, you currently must only provide a single index. If you attempt to provide multiple indexes, your data point will not be recorded.
§Arguments
index
: A string or byte-array value to use as the index.
returns: AnalyticsEngineDataPointBuilder
§Examples
use worker::AnalyticsEngineDataPointBuilder;
let data = AnalyticsEngineDataPointBuilder::new()
.indexes(["index1"])
.build();
Sourcepub fn add_double(self, double: impl Into<f64>) -> Self
pub fn add_double(self, double: impl Into<f64>) -> Self
Adds a numeric value to the end of the array of doubles.
§Arguments
double
: The numeric values that you want to record in your data point
returns: AnalyticsEngineDataPointBuilder
§Examples
use worker::AnalyticsEngineDataPointBuilder;
let point = AnalyticsEngineDataPointBuilder::new()
.indexes(["index1"])
.add_double(25) // double1
.add_double(0.5) // double2
.build();
println!("{:?}", point);
Sourcepub fn doubles(self, doubles: impl IntoIterator<Item = f64>) -> Self
pub fn doubles(self, doubles: impl IntoIterator<Item = f64>) -> Self
Set doubles1-20 with the provide values. This method will remove any doubles previously
added using the add_double
method.
§Arguments
doubles
: An array of doubles
returns: AnalyticsEngineDataPointBuilder
§Examples
use worker::AnalyticsEngineDataPointBuilder;
let point = AnalyticsEngineDataPointBuilder::new()
.indexes(["index1"])
.add_double(1) // value will be replaced by the following line
.doubles([1, 2, 3]) // sets double1, double2 and double3
.build();
println!("{:?}", point);
Sourcepub fn add_blob(self, blob: impl Into<BlobType>) -> Self
pub fn add_blob(self, blob: impl Into<BlobType>) -> Self
Adds a blob-like value to the end of the array of blobs.
§Arguments
blob
: The blob values that you want to record in your data point
returns: AnalyticsEngineDataPointBuilder
§Examples
use worker::AnalyticsEngineDataPointBuilder;
let point = AnalyticsEngineDataPointBuilder::new()
.indexes(["index1"])
.add_blob("Seattle") // blob1
.add_blob("USA") // blob2
.add_blob("pro_sensor_9000") // blob3
.build();
println!("{:?}", point);
Sourcepub fn blobs(self, blobs: impl IntoIterator<Item = impl Into<BlobType>>) -> Self
pub fn blobs(self, blobs: impl IntoIterator<Item = impl Into<BlobType>>) -> Self
Sets blobs1-20 with the provided array, replacing any values previously stored using add_blob
.
§Arguments
blob
: The blob values that you want to record in your data point
returns: AnalyticsEngineDataPointBuilder
§Examples
use worker::AnalyticsEngineDataPointBuilder;
let point = AnalyticsEngineDataPointBuilder::new()
.indexes(["index1"])
.blobs(["Seattle", "USA", "pro_sensor_9000"]) // sets blob1, blob2, and blob3
.build();
println!("{:?}", point);
pub fn build(self) -> AnalyticsEngineDataPoint
Sourcepub fn write_to(self, dataset: &AnalyticsEngineDataset) -> Result<()>
pub fn write_to(self, dataset: &AnalyticsEngineDataset) -> Result<()>
Write the data point to the provided analytics engine dataset. This is a convenience method
that can be used in place of a .build()
followed by a call to dataset.write_data_point(point)
.
§Arguments
dataset
: Analytics engine dataset binding
returns: worker::Result<()>
§Examples
use worker::{Env, AnalyticsEngineDataPointBuilder, Response};
use std::io::Error;
fn main(env: Env) -> worker::Result<Response> {
let dataset = match env.analytics_engine("HTTP_ANALYTICS") {
Ok(dataset) => dataset,
Err(err) => return Response::error(format!("Failed to get dataset: {err:?}"), 500),
};
AnalyticsEngineDataPointBuilder::new()
.indexes(vec!["index1"].as_slice())
.add_blob("GET") // blob1
.add_double(200) // double1
.write_to(&dataset)?;
Response::ok("OK")
}