From e5615d8444ca6306f0c2b57ec225784a97e29dc1 Mon Sep 17 00:00:00 2001 From: dingbo Date: Thu, 9 Jun 2022 15:59:04 +0800 Subject: [PATCH] docs: preview connector code --- docs-en/05-develop/01-connect/01-python.md | 11 +++-- docs-en/05-develop/01-connect/02-java.md | 26 +++++------ docs-en/05-develop/01-connect/03-go.md | 50 ++++++++++++++++++++++ docs-en/05-develop/01-connect/04-rust.md | 31 ++++++++++++++ docs-en/05-develop/01-connect/05-node.md | 32 ++++++++++++++ 5 files changed, 128 insertions(+), 22 deletions(-) create mode 100644 docs-en/05-develop/01-connect/03-go.md create mode 100644 docs-en/05-develop/01-connect/04-rust.md create mode 100644 docs-en/05-develop/01-connect/05-node.md diff --git a/docs-en/05-develop/01-connect/01-python.md b/docs-en/05-develop/01-connect/01-python.md index c137df32f6..48202137e8 100644 --- a/docs-en/05-develop/01-connect/01-python.md +++ b/docs-en/05-develop/01-connect/01-python.md @@ -15,16 +15,15 @@ You'll need to have Python3 installed. ## Config -Run this command in your terminal to save your URL and token as variables: +Run this command in your terminal to save TDengine cloud token as variables: ```bash -export TDENGINE_CLOUD_URL= -export TDENGINE_CLOUD_TOKEN= +export TDENGINE_TOKEN= ``` :::note -You should replace above placeholders as real values. To obtain these values, please log in TDengine Cloud and switch to "Connector" section. +To obtain cloud token, please log in TDengine Cloud and switch to "Connector" section. ::: @@ -37,8 +36,8 @@ Copy code bellow to your editor and run it with `python3` command. import taosrest import os -url = os.environ["TDENGINE_CLOUD_URL"] -token = os.environ["TDENGINE_CLOUD_TOKEN"] +token = os.environ["TDENGINE_TOKEN"] +url = "https://cloud.tdengine.com" 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 d17dfddaf7..f4cd583af4 100644 --- a/docs-en/05-develop/01-connect/02-java.md +++ b/docs-en/05-develop/01-connect/02-java.md @@ -25,35 +25,29 @@ dependencies { ## Config -Run this command in your terminal to save your url and token as variables: +Run this command in your terminal to save TDengine cloud token as variables: ```bash -export TDENGINE_CLOUD_URL= -export TDENGINE_CLOUD_TOKEN= +export TDENGINE_TOKEN= ``` - -:::note -You should replace above placeholders as real values. To obtain these values, please log in TDengine Cloud and switch to "Connector" section. - -::: - - ## Connect -Code bellow get URL and token from environment variables first and then create a `RestfulConnection` object, witch is a standard JDBC Connection object. ```java -import com.taosdata.jdbc.rs.RestfulConnection; import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; public class ConnectCloudExample { - public static void main(String[] args) throws Exception { - String url = System.getenv("TDENGINE_CLOUD_URL"); - String token = System.getenv("TDENGINE_CLOUD_TOKEN"); - Connection conn = new RestfulConnection(url, token); + public static void main(String[] args) throws SQLException { + String token = System.getenv("TDENGINE_TOKEN"); + String jdbcUrl = "jdbc:TAOS-RS://cloud.taosdata.com:8085?usessl=true&token=" + token; + 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 new file mode 100644 index 0000000000..f1cd8118ca --- /dev/null +++ b/docs-en/05-develop/01-connect/03-go.md @@ -0,0 +1,50 @@ +--- +sidebar_label: Go +title: Connect with Go Connector +--- + +## Add Dependency + +add `driver-go` dependency in `go.mod` . + +``` title="go.mod" +module goexample + +go 1.17 + +require github.com/taosdata/driver-go/v2 develop +``` + +## Config + +Run this command in your terminal to save TDengine cloud token as variables: + +```bash +export TDENGINE_TOKEN= +``` + +## Connect + +```go +package main + +import ( + "database/sql" + "fmt" + "os" + + _ "github.com/taosdata/driver-go/v2/taosRestful" +) + +func main() { + host := os.Getenv("TDENGIN_TOKEN") + taosDSN := "https://cloud.taosdata.com?token=" + token + taos, err := sql.Open("taosRestful", taosDSN) + if err != nil { + fmt.Println("failed to connect TDengine, err:", err) + return + } + fmt.Println("Connected") + defer taos.Close() +} +``` \ No newline at end of file diff --git a/docs-en/05-develop/01-connect/04-rust.md b/docs-en/05-develop/01-connect/04-rust.md new file mode 100644 index 0000000000..44d3a1fab4 --- /dev/null +++ b/docs-en/05-develop/01-connect/04-rust.md @@ -0,0 +1,31 @@ +--- +sidebar_label: Rust +title: Connect with Rust Connector +--- + +## Add Dependency + + +``` title="Cargo.toml" + +``` + +## Config + +Run this command in your terminal to save TDengine cloud token as variables: + +```bash +export TDENGINE_TOKEN= +``` + +## Connect + +```go +use libtaos::*; + +fn main() { + let token = std::env::var("TDENGINE_TOKEN").unwrap(); + let dsn = format!("https://cloud:tdengine.com?token={}", token); + let taos = Taos::from_dsn(dsn.as_str())?; +} +``` \ 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 new file mode 100644 index 0000000000..4d3808f8e4 --- /dev/null +++ b/docs-en/05-develop/01-connect/05-node.md @@ -0,0 +1,32 @@ +--- +sidebar_label: Node.js +title: Connect with Node.js Connector +--- + +## Install Connector + + + +## Config + +Run this command in your terminal to save TDengine cloud token as variables: + +```bash +export TDENGINE_TOKEN= +``` + + +## Connect + + +```python +const { options, connect } = require("td2.0-rest-connector"); + +async function test() { + options.url = "https://cloud.tdengine.com"; + options.token = process.env.TDENGIN_TOKEN; + let conn = connect(options); +} +test(); +``` + -- GitLab