提交 e5615d84 编写于 作者: D dingbo

docs: preview connector code

上级 20667486
...@@ -15,16 +15,15 @@ You'll need to have Python3 installed. ...@@ -15,16 +15,15 @@ You'll need to have Python3 installed.
## Config ## 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 ```bash
export TDENGINE_CLOUD_URL=<URL> export TDENGINE_TOKEN=<token>
export TDENGINE_CLOUD_TOKEN=<token>
``` ```
<!-- exclude --> <!-- exclude -->
:::note :::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.
::: :::
<!-- exclude-end --> <!-- exclude-end -->
...@@ -37,8 +36,8 @@ Copy code bellow to your editor and run it with `python3` command. ...@@ -37,8 +36,8 @@ Copy code bellow to your editor and run it with `python3` command.
import taosrest import taosrest
import os import os
url = os.environ["TDENGINE_CLOUD_URL"] token = os.environ["TDENGINE_TOKEN"]
token = os.environ["TDENGINE_CLOUD_TOKEN"] url = "https://cloud.tdengine.com"
conn = taosrest.connect(url=url, token=token) conn = taosrest.connect(url=url, token=token)
``` ```
......
...@@ -25,35 +25,29 @@ dependencies { ...@@ -25,35 +25,29 @@ dependencies {
## Config ## 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 ```bash
export TDENGINE_CLOUD_URL=<url> export TDENGINE_TOKEN=<token>
export TDENGINE_CLOUD_TOKEN=<token>
``` ```
<!-- exclude -->
:::note
You should replace above placeholders as real values. To obtain these values, please log in TDengine Cloud and switch to "Connector" section.
:::
<!-- exclude-end -->
## Connect ## 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 ```java
import com.taosdata.jdbc.rs.RestfulConnection;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectCloudExample { public class ConnectCloudExample {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws SQLException {
String url = System.getenv("TDENGINE_CLOUD_URL"); String token = System.getenv("TDENGINE_TOKEN");
String token = System.getenv("TDENGINE_CLOUD_TOKEN"); String jdbcUrl = "jdbc:TAOS-RS://cloud.taosdata.com:8085?usessl=true&token=" + token;
Connection conn = new RestfulConnection(url, token); Connection conn = DriverManager.getConnection(jdbcUrl);
System.out.println("Connected");
conn.close();
} }
} }
``` ```
......
---
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=<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
---
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=<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
---
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=<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();
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册