From 63fa91c0b61f5b62554a5a2348958af7533a4461 Mon Sep 17 00:00:00 2001 From: dingbo Date: Sat, 11 Jun 2022 14:23:21 +0800 Subject: [PATCH] docs: connector example --- docs-en/05-develop/01-connect/01-python.md | 8 ++++--- docs-en/05-develop/01-connect/02-java.md | 21 ++++++++--------- docs-en/05-develop/01-connect/03-go.md | 21 ++++++++++++----- docs-en/05-develop/01-connect/04-rust.md | 27 ++++++++++++++++++---- docs-en/05-develop/01-connect/05-node.md | 19 +++++++++++---- 5 files changed, 66 insertions(+), 30 deletions(-) diff --git a/docs-en/05-develop/01-connect/01-python.md b/docs-en/05-develop/01-connect/01-python.md index efbcc1ff75..dd9ae72b37 100644 --- a/docs-en/05-develop/01-connect/01-python.md +++ b/docs-en/05-develop/01-connect/01-python.md @@ -34,14 +34,16 @@ Run this command in your terminal to save TDengine cloud token as variables: ```bash export TDENGINE_CLOUD_TOKEN= +export TDENGINE_CLOUD_URL= ``` -You can also set environment variable in IDE. For example, you can set environmental variables in Pycharm's run configurations menu. +Alternatively, set environment variables in your IDE's run configurations. :::note -To obtain your personal cloud token, please log in [TDengine Cloud](https://cloud.tdengine.com). +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 "Python". ::: @@ -55,7 +57,7 @@ import taosrest import os token = os.environ["TDENGINE_CLOUD_TOKEN"] -url = "https://cloud.tdengine.com" +url = os.environ["TDENGINE_ClOUD_URL"] conn = taosrest.connect(url=url, token=token) ``` diff --git a/docs-en/05-develop/01-connect/02-java.md b/docs-en/05-develop/01-connect/02-java.md index 3c98f7e3e1..dc674b73d4 100644 --- a/docs-en/05-develop/01-connect/02-java.md +++ b/docs-en/05-develop/01-connect/02-java.md @@ -8,10 +8,11 @@ import TabItem from '@theme/TabItem'; ## Add Dependency + -```xml +```xml title="pom.xml" com.taosdata.jdbc taos-jdbcdriver @@ -22,7 +23,7 @@ import TabItem from '@theme/TabItem'; -```groovy +```groovy title="build.gradle" dependencies { implementation 'com.taosdata.jdbc:taos-jdbcdriver:2.0.39' } @@ -33,25 +34,25 @@ dependencies { ## Config -Run this command in your terminal to save TDengine cloud token as variables: - +Run this command in your terminal to save the JDBC URL as variable: ```bash -export TDENGINE_CLOUD_TOKEN= +export TDENGINE_JDBC_URL= ``` +Alternatively, set environment variable in your IDE's run configurations. -You can also set environment variable in IDE. For example, you can set environmental variables in IDEA's run configurations menu. :::note -To obtain your personal cloud token, please log in [TDengine Cloud](https://cloud.tdengine.com). +Replace with real JDBC URL, it will seems like: `jdbc:TAOS-RS://example.com?usessl=true&token=xxxx`. +To obtain the value of JDBC URL, please log in [TDengine Cloud](https://cloud.tdengine.com) and click "Connector" and then select "Java". ::: ## Connect -Code bellow get token from environment variables first and then create a `Connection` object, witch is a standard JDBC Connection object. +Code bellow get JDBC URL from environment variables first and then create a `Connection` object, witch is a standard JDBC Connection object. ```java import java.sql.Connection; @@ -61,10 +62,8 @@ import java.sql.SQLException; public class ConnectCloudExample { public static void main(String[] args) throws SQLException { - String token = System.getenv("TDENGINE_CLOUD_TOKEN"); - String jdbcUrl = "jdbc:TAOS-RS://cloud.taosdata.com:8085?usessl=true&token=" + token; + String jdbcUrl = System.getenv("TDENGINE_JDBC_URL"); Connection conn = DriverManager.getConnection(jdbcUrl); - System.out.println("Connected"); conn.close(); } } diff --git a/docs-en/05-develop/01-connect/03-go.md b/docs-en/05-develop/01-connect/03-go.md index c02497fd89..d3b142392c 100644 --- a/docs-en/05-develop/01-connect/03-go.md +++ b/docs-en/05-develop/01-connect/03-go.md @@ -7,7 +7,7 @@ title: Connect with Go Connector add `driver-go` dependency in `go.mod` . -``` title="go.mod" +```go-mod title="go.mod" module goexample go 1.17 @@ -15,14 +15,24 @@ go 1.17 require github.com/taosdata/driver-go/v2 develop ``` +Then run command `go mod tidy` in your terminal to download dependencies. + ## Config -Run this command in your terminal to save TDengine cloud token as variables: +Run this command in your terminal to save DSN(data source name) as variable: ```bash -export TDENGINE_CLOUD_TOKEN= +export TDENGINE_GO_DSN= ``` + +:::note +Replace with the real value, the format should be `https()/?token=`. +To obtain the value of `goDSN`, please log in [TDengine Cloud](https://cloud.tdengine.com) and click "Connector" and then select "Go". + +::: + + ## Connect ```go @@ -37,9 +47,8 @@ import ( ) func main() { - token := os.Getenv("TDENGINE_CLOUD_TOKEN") - taosDSN := "http(cloud.tdengine.com:8085)/?token=" + token - taos, err := sql.Open("taosRestful", taosDSN) + dsn := os.Getenv("TDENGINE_CLOUD_TOKEN") + taos, err := sql.Open("taosRestful", dsn) if err != nil { fmt.Println("failed to connect TDengine, err:", err) return diff --git a/docs-en/05-develop/01-connect/04-rust.md b/docs-en/05-develop/01-connect/04-rust.md index 0f3e11e647..aa494592ce 100644 --- a/docs-en/05-develop/01-connect/04-rust.md +++ b/docs-en/05-develop/01-connect/04-rust.md @@ -5,9 +5,11 @@ title: Connect with Rust Connector ## Add Dependency +Add dependency to `Cargo.toml`. -``` title="Cargo.toml" - +```toml title="Cargo.toml" +[dependencies] +libtaos = { version = "0.4.2"} ``` ## Config @@ -16,16 +18,31 @@ Run this command in your terminal to save TDengine cloud token as variables: ```bash export TDENGINE_CLOUD_TOKEN= +export 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". + +::: + + ## Connect -```go +Copy following code to `main.rs`. + +```rust title="main.rs" use libtaos::*; fn main() { let token = std::env::var("TDENGINE_CLOUD_TOKEN").unwrap(); - let dsn = format!("https://cloud.tdengine.com?token={}", token); + let url = std::env::var("TDENGINE_CLOUD_URL").unwrap(); + let dsn = url + "?token=" + &token; let taos = Taos::from_dsn(dsn)?; + println!("connected"); } -``` \ No newline at end of file +``` + +Then you can execute `cargo run` to test the connection. \ No newline at end of file diff --git a/docs-en/05-develop/01-connect/05-node.md b/docs-en/05-develop/01-connect/05-node.md index 4da75ab3c6..54b92b4ab9 100644 --- a/docs-en/05-develop/01-connect/05-node.md +++ b/docs-en/05-develop/01-connect/05-node.md @@ -5,28 +5,37 @@ title: Connect with Node.js Connector ## Install Connector - - +``` +npm i td2.0-rest-connector +``` ## Config Run this command in your terminal to save TDengine cloud token as variables: ```bash export TDENGINE_CLOUD_TOKEN= +export 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 "Node.js". -## Connect +::: + +## Connect -```python +```javascript const { options, connect } = require("td2.0-rest-connector"); async function test() { - options.url = "https://cloud.tdengine.com"; + options.url = process.env.TDENGINE_CLOUD_URL; options.token = process.env.TDENGINE_CLOUD_TOKEN; let conn = connect(options); } + test(); ``` -- GitLab