提交 63fa91c0 编写于 作者: D dingbo

docs: connector example

上级 a2f8c8ad
...@@ -34,14 +34,16 @@ Run this command in your terminal to save TDengine cloud token as variables: ...@@ -34,14 +34,16 @@ Run this command in your terminal to save TDengine cloud token as variables:
```bash ```bash
export TDENGINE_CLOUD_TOKEN=<token> export TDENGINE_CLOUD_TOKEN=<token>
export TDENGINE_CLOUD_URL=<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.
<!-- exclude --> <!-- exclude -->
:::note :::note
To obtain your personal cloud token, please log in [TDengine Cloud](https://cloud.tdengine.com). Replace <token\> and <url\> 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".
::: :::
<!-- exclude-end --> <!-- exclude-end -->
...@@ -55,7 +57,7 @@ import taosrest ...@@ -55,7 +57,7 @@ import taosrest
import os import os
token = os.environ["TDENGINE_CLOUD_TOKEN"] token = os.environ["TDENGINE_CLOUD_TOKEN"]
url = "https://cloud.tdengine.com" url = os.environ["TDENGINE_ClOUD_URL"]
conn = taosrest.connect(url=url, token=token) conn = taosrest.connect(url=url, token=token)
``` ```
......
...@@ -8,10 +8,11 @@ import TabItem from '@theme/TabItem'; ...@@ -8,10 +8,11 @@ import TabItem from '@theme/TabItem';
## Add Dependency ## Add Dependency
<Tabs> <Tabs>
<TabItem value="maven" label="Maven"> <TabItem value="maven" label="Maven">
```xml ```xml title="pom.xml"
<dependency> <dependency>
<groupId>com.taosdata.jdbc</groupId> <groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId> <artifactId>taos-jdbcdriver</artifactId>
...@@ -22,7 +23,7 @@ import TabItem from '@theme/TabItem'; ...@@ -22,7 +23,7 @@ import TabItem from '@theme/TabItem';
</TabItem> </TabItem>
<TabItem value="gradel" label="Gradle"> <TabItem value="gradel" label="Gradle">
```groovy ```groovy title="build.gradle"
dependencies { dependencies {
implementation 'com.taosdata.jdbc:taos-jdbcdriver:2.0.39' implementation 'com.taosdata.jdbc:taos-jdbcdriver:2.0.39'
} }
...@@ -33,25 +34,25 @@ dependencies { ...@@ -33,25 +34,25 @@ dependencies {
## Config ## 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 ```bash
export TDENGINE_CLOUD_TOKEN=<token> export TDENGINE_JDBC_URL=<jdbcURL>
``` ```
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.
<!-- exclude --> <!-- exclude -->
:::note :::note
To obtain your personal cloud token, please log in [TDengine Cloud](https://cloud.tdengine.com). Replace <jdbcURL\> 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".
::: :::
<!-- exclude-end --> <!-- exclude-end -->
## Connect ## 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 ```java
import java.sql.Connection; import java.sql.Connection;
...@@ -61,10 +62,8 @@ import java.sql.SQLException; ...@@ -61,10 +62,8 @@ import java.sql.SQLException;
public class ConnectCloudExample { public class ConnectCloudExample {
public static void main(String[] args) throws SQLException { public static void main(String[] args) throws SQLException {
String token = System.getenv("TDENGINE_CLOUD_TOKEN"); String jdbcUrl = System.getenv("TDENGINE_JDBC_URL");
String jdbcUrl = "jdbc:TAOS-RS://cloud.taosdata.com:8085?usessl=true&token=" + token;
Connection conn = DriverManager.getConnection(jdbcUrl); Connection conn = DriverManager.getConnection(jdbcUrl);
System.out.println("Connected");
conn.close(); conn.close();
} }
} }
......
...@@ -7,7 +7,7 @@ title: Connect with Go Connector ...@@ -7,7 +7,7 @@ title: Connect with Go Connector
add `driver-go` dependency in `go.mod` . add `driver-go` dependency in `go.mod` .
``` title="go.mod" ```go-mod title="go.mod"
module goexample module goexample
go 1.17 go 1.17
...@@ -15,14 +15,24 @@ go 1.17 ...@@ -15,14 +15,24 @@ go 1.17
require github.com/taosdata/driver-go/v2 develop require github.com/taosdata/driver-go/v2 develop
``` ```
Then run command `go mod tidy` in your terminal to download dependencies.
## Config ## 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 ```bash
export TDENGINE_CLOUD_TOKEN=<token> export TDENGINE_GO_DSN=<goDSN>
``` ```
<!-- exclude -->
:::note
Replace <goDSN\> with the real value, the format should be `https(<cloud_host>)/?token=<token>`.
To obtain the value of `goDSN`, please log in [TDengine Cloud](https://cloud.tdengine.com) and click "Connector" and then select "Go".
:::
<!-- exclude-end -->
## Connect ## Connect
```go ```go
...@@ -37,9 +47,8 @@ import ( ...@@ -37,9 +47,8 @@ import (
) )
func main() { func main() {
token := os.Getenv("TDENGINE_CLOUD_TOKEN") dsn := os.Getenv("TDENGINE_CLOUD_TOKEN")
taosDSN := "http(cloud.tdengine.com:8085)/?token=" + token taos, err := sql.Open("taosRestful", dsn)
taos, err := sql.Open("taosRestful", taosDSN)
if err != nil { if err != nil {
fmt.Println("failed to connect TDengine, err:", err) fmt.Println("failed to connect TDengine, err:", err)
return return
......
...@@ -5,9 +5,11 @@ title: Connect with Rust Connector ...@@ -5,9 +5,11 @@ title: Connect with Rust Connector
## Add Dependency ## Add Dependency
Add dependency to `Cargo.toml`.
``` title="Cargo.toml" ```toml title="Cargo.toml"
[dependencies]
libtaos = { version = "0.4.2"}
``` ```
## Config ## Config
...@@ -16,16 +18,31 @@ Run this command in your terminal to save TDengine cloud token as variables: ...@@ -16,16 +18,31 @@ Run this command in your terminal to save TDengine cloud token as variables:
```bash ```bash
export TDENGINE_CLOUD_TOKEN=<token> export TDENGINE_CLOUD_TOKEN=<token>
export TDENGINE_CLOUD_URL=<url>
``` ```
<!-- exclude -->
:::note
Replace <token\> and <url\> 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".
:::
<!-- exclude-end -->
## Connect ## Connect
```go Copy following code to `main.rs`.
```rust title="main.rs"
use libtaos::*; use libtaos::*;
fn main() { fn main() {
let token = std::env::var("TDENGINE_CLOUD_TOKEN").unwrap(); 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)?; 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
...@@ -5,28 +5,37 @@ title: Connect with Node.js Connector ...@@ -5,28 +5,37 @@ title: Connect with Node.js Connector
## Install Connector ## Install Connector
```
npm i td2.0-rest-connector
```
## Config ## Config
Run this command in your terminal to save TDengine cloud token as variables: Run this command in your terminal to save TDengine cloud token as variables:
```bash ```bash
export TDENGINE_CLOUD_TOKEN=<token> export TDENGINE_CLOUD_TOKEN=<token>
export TDENGINE_CLOUD_URL=<url>
``` ```
<!-- exclude -->
:::note
Replace <token\> and <url\> 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 :::
<!-- exclude-end -->
## Connect
```python ```javascript
const { options, connect } = require("td2.0-rest-connector"); const { options, connect } = require("td2.0-rest-connector");
async function test() { async function test() {
options.url = "https://cloud.tdengine.com"; options.url = process.env.TDENGINE_CLOUD_URL;
options.token = process.env.TDENGINE_CLOUD_TOKEN; options.token = process.env.TDENGINE_CLOUD_TOKEN;
let conn = connect(options); let conn = connect(options);
} }
test(); test();
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册