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

docs: connector example

上级 a2f8c8ad
......@@ -34,14 +34,16 @@ Run this command in your terminal to save TDengine cloud token as variables:
```bash
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 -->
:::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 -->
......@@ -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)
```
......
......@@ -8,10 +8,11 @@ import TabItem from '@theme/TabItem';
## Add Dependency
<Tabs>
<TabItem value="maven" label="Maven">
```xml
```xml title="pom.xml"
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
......@@ -22,7 +23,7 @@ import TabItem from '@theme/TabItem';
</TabItem>
<TabItem value="gradel" label="Gradle">
```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=<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 -->
:::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 -->
## 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();
}
}
......
......@@ -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=<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
```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
......
......@@ -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=<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
```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");
}
```
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
## 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=<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");
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();
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册