diff --git a/docs/examples/rust/nativeexample/examples/query.rs b/docs/examples/rust/nativeexample/examples/query.rs index 857df01f01..08ec223761 100644 --- a/docs/examples/rust/nativeexample/examples/query.rs +++ b/docs/examples/rust/nativeexample/examples/query.rs @@ -1,4 +1,6 @@ use taos::*; +use chrono::Local; +use chrono::DateTime; #[tokio::main] async fn main() -> anyhow::Result<()> { @@ -61,6 +63,33 @@ async fn main() -> anyhow::Result<()> { } // ANCHOR_END: query_data + // ANCHOR: query_data_2 + // query data, make sure the database and table are created before + #[derive(Debug, serde::Deserialize)] + #[allow(dead_code)] + struct Record { + // deserialize timestamp to chrono::DateTime + ts: DateTime, + // float to f32 + current: Option, + // int to i32 + voltage: Option, + phase: Option, + groupid: i32, + // binary/varchar to String + location: String, + } + + let records: Vec = taos + .query("select ts, current, voltage, phase, groupid, location from power.meters limit 100") + .await? + .deserialize() + .try_collect() + .await?; + + dbg!(records); + // ANCHOR_END: query_data_2 + // ANCHOR: query_with_req_id let result = taos.query_with_req_id("SELECT ts, current, location FROM power.meters limit 1", 1).await?; for field in result.fields() { diff --git a/docs/zh/08-develop/02-sql.md b/docs/zh/08-develop/02-sql.md index 89c89680ac..aa77baaf6d 100644 --- a/docs/zh/08-develop/02-sql.md +++ b/docs/zh/08-develop/02-sql.md @@ -202,6 +202,11 @@ curl --location -uroot:taosdata 'http://127.0.0.1:6041/rest/sql' \ {{#include docs/examples/rust/nativeexample/examples/query.rs:query_data}} ``` +rust 连接器还支持使用 **serde** 进行反序列化行为结构体的结果获取方式: +```rust +{{#include docs/examples/rust/nativeexample/examples/query.rs:query_data_2}} +``` + ```js