From f0db29ee214cd7713ac338a0c133244ca6a7c9fb Mon Sep 17 00:00:00 2001 From: dingbo Date: Fri, 17 Jun 2022 10:57:35 +0800 Subject: [PATCH] docs: go and rust --- docs/en/05-develop/01-connect/04-rust.md | 17 ++++++++--------- docs/examples/go/connectexample/main.go | 2 +- docs/examples/rust/cloud_example/Cargo.toml | 3 ++- docs/examples/rust/cloud_example/src/main.rs | 15 +++++++++------ 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/docs/en/05-develop/01-connect/04-rust.md b/docs/en/05-develop/01-connect/04-rust.md index 32a6c30095..95ba477050 100644 --- a/docs/en/05-develop/01-connect/04-rust.md +++ b/docs/en/05-develop/01-connect/04-rust.md @@ -17,7 +17,10 @@ Add dependency to `Cargo.toml`. ```toml title="Cargo.toml" [dependencies] -libtaos = { version="*", feature=["rest"]} +[dependencies] +libtaos = { version="0.4.5-alpha.0", features=["rest"]} +tokio = { version = "1", features = ["full"]} +anyhow = "*" ``` ## Config @@ -28,24 +31,21 @@ Run this command in your terminal to save TDengine cloud token as variables: ```bash -export TDENGINE_CLOUD_TOKEN="" -export TDENGINE_CLOUD_URL="" +export TDENGINE_CLOUD_DSN="" ``` ```bash -set TDENGINE_CLOUD_TOKEN="" -set TDENGINE_CLOUD_URL="" +set TDENGINE_CLOUD_DSN="" ``` ```powershell -$env:TDENGINE_CLOUD_TOKEN="" -$env:TDENGINE_CLOUD_URL="" +$env:TDENGINE_CLOUD_DSN="" ``` @@ -53,8 +53,7 @@ $env:TDENGINE_CLOUD_URL="" :::note -Replace and with cloud token and URL. -To obtain the value of cloud token and URL, please log in [TDengine Cloud](https://cloud.tdengine.com) and click "Connector" and then select "Rust". +Replace with real TDengine cloud DSN. To obtain the real value, please log in [TDengine Cloud](https://cloud.tdengine.com) and click "Connector" and then select "Rust". ::: diff --git a/docs/examples/go/connectexample/main.go b/docs/examples/go/connectexample/main.go index 22d171d875..3a32425be3 100644 --- a/docs/examples/go/connectexample/main.go +++ b/docs/examples/go/connectexample/main.go @@ -16,7 +16,7 @@ func main() { return } defer taos.Close() - rows, err := taos.Query("select server_version()") + rows, err := taos.Query("show databases") if err != nil { fmt.Println(err) return diff --git a/docs/examples/rust/cloud_example/Cargo.toml b/docs/examples/rust/cloud_example/Cargo.toml index b4b2066b23..f9e1e54a65 100644 --- a/docs/examples/rust/cloud_example/Cargo.toml +++ b/docs/examples/rust/cloud_example/Cargo.toml @@ -7,5 +7,6 @@ edition = "2021" [dependencies] -libtaos = { version="0.4.5-alpha.0", feature=["rest"]} +libtaos = { version="0.4.5-alpha.0", features=["rest"]} tokio = { version = "1", features = ["full"]} +anyhow = "*" diff --git a/docs/examples/rust/cloud_example/src/main.rs b/docs/examples/rust/cloud_example/src/main.rs index faeedff997..2019c38952 100644 --- a/docs/examples/rust/cloud_example/src/main.rs +++ b/docs/examples/rust/cloud_example/src/main.rs @@ -1,9 +1,12 @@ +use anyhow::Result; use libtaos::*; -fn main() { - let token = std::env::var("TDENGINE_CLOUD_TOKEN").unwrap(); - let url = std::env::var("TDENGINE_CLOUD_URL").unwrap(); - let dsn = url + "?token=" + &token; - let taos = TaosCfg::from_dsn(dsn)?; - println!("connected"); +#[tokio::main] +async fn main() -> Result<()> { + let dsn = std::env::var("TDENGINE_CLOUD_DSN").unwrap(); + let cfg = TaosCfg::from_dsn(dsn)?; + let conn = cfg.connect()?; + let _ = conn.query("show databases").await?; + println!("Connected"); + Ok(()) } \ No newline at end of file -- GitLab