Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
590062c4
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
590062c4
编写于
6月 17, 2022
作者:
D
dingbo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs: rust and go
上级
0dfa8159
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
24 addition
and
254 deletion
+24
-254
docs/en/05-develop/01-connect/04-rust.md
docs/en/05-develop/01-connect/04-rust.md
+7
-10
docs/examples/go/connectexample/main.go
docs/examples/go/connectexample/main.go
+3
-2
docs/examples/rust/Cargo.toml
docs/examples/rust/Cargo.toml
+0
-2
docs/examples/rust/cloud_example/Cargo.toml
docs/examples/rust/cloud_example/Cargo.toml
+5
-4
docs/examples/rust/cloud_example/src/main.rs
docs/examples/rust/cloud_example/src/main.rs
+9
-0
docs/examples/rust/nativeexample/examples/connect.rs
docs/examples/rust/nativeexample/examples/connect.rs
+0
-19
docs/examples/rust/nativeexample/examples/stmt_example.rs
docs/examples/rust/nativeexample/examples/stmt_example.rs
+0
-38
docs/examples/rust/nativeexample/examples/subscribe_demo.rs
docs/examples/rust/nativeexample/examples/subscribe_demo.rs
+0
-3
docs/examples/rust/nativeexample/src/main.rs
docs/examples/rust/nativeexample/src/main.rs
+0
-3
docs/examples/rust/restexample/Cargo.toml
docs/examples/rust/restexample/Cargo.toml
+0
-8
docs/examples/rust/restexample/examples/connect.rs
docs/examples/rust/restexample/examples/connect.rs
+0
-20
docs/examples/rust/restexample/examples/insert_example.rs
docs/examples/rust/restexample/examples/insert_example.rs
+0
-18
docs/examples/rust/restexample/examples/query_example.rs
docs/examples/rust/restexample/examples/query_example.rs
+0
-39
docs/examples/rust/restexample/src/main.rs
docs/examples/rust/restexample/src/main.rs
+0
-3
docs/examples/rust/schemalessexample/Cargo.toml
docs/examples/rust/schemalessexample/Cargo.toml
+0
-7
docs/examples/rust/schemalessexample/examples/influxdb_line_example.rs
.../rust/schemalessexample/examples/influxdb_line_example.rs
+0
-22
docs/examples/rust/schemalessexample/examples/opentsdb_json_example.rs
.../rust/schemalessexample/examples/opentsdb_json_example.rs
+0
-25
docs/examples/rust/schemalessexample/examples/opentsdb_telnet_example.rs
...ust/schemalessexample/examples/opentsdb_telnet_example.rs
+0
-28
docs/examples/rust/schemalessexample/src/main.rs
docs/examples/rust/schemalessexample/src/main.rs
+0
-3
未找到文件。
docs/en/05-develop/01-connect/04-rust.md
浏览文件 @
590062c4
...
@@ -6,13 +6,18 @@ pagination_next: develop/insert-data
...
@@ -6,13 +6,18 @@ pagination_next: develop/insert-data
import Tabs from '@theme/Tabs';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import TabItem from '@theme/TabItem';
## Create Project
```
cargo new cloud_example
```
## Add Dependency
## Add Dependency
Add dependency to
`Cargo.toml`
.
Add dependency to
`Cargo.toml`
.
```
toml title="Cargo.toml"
```
toml title="Cargo.toml"
[dependencies]
[dependencies]
libtaos = { version
= "0.4.2"
}
libtaos = { version
="*", feature=["rest"]
}
```
```
## Config
## Config
...
@@ -59,15 +64,7 @@ To obtain the value of cloud token and URL, please log in [TDengine Cloud](https
...
@@ -59,15 +64,7 @@ To obtain the value of cloud token and URL, please log in [TDengine Cloud](https
Copy following code to
`main.rs`
.
Copy following code to
`main.rs`
.
```
rust title="main.rs"
```
rust title="main.rs"
use libtaos::*;
{{#include docs/examples/rust/cloud_example/src/main.rs}}
fn main() {
let token = std::env::var("TDENGINE_CLOUD_TOKEN").unwrap();
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.
Then you can execute
`cargo run`
to test the connection.
\ No newline at end of file
docs/examples/go/connectexample/main.go
浏览文件 @
590062c4
...
@@ -15,11 +15,12 @@ func main() {
...
@@ -15,11 +15,12 @@ func main() {
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
return
return
}
}
_
,
err
=
taos
.
Query
(
"select server_version()"
)
defer
taos
.
Close
()
rows
,
err
:=
taos
.
Query
(
"select server_version()"
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
return
return
}
}
rows
.
Close
()
fmt
.
Println
(
"connect success"
)
fmt
.
Println
(
"connect success"
)
defer
taos
.
Close
()
}
}
docs/examples/rust/Cargo.toml
已删除
100644 → 0
浏览文件 @
0dfa8159
[workspace]
members
=
[
"restexample"
,
"nativeexample"
,
"schemalessexample"
]
docs/examples/rust/
native
example/Cargo.toml
→
docs/examples/rust/
cloud_
example/Cargo.toml
浏览文件 @
590062c4
[package]
[package]
name
=
"
native
example"
name
=
"
cloud_
example"
version
=
"0.1.0"
version
=
"0.1.0"
edition
=
"2021"
edition
=
"2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[dependencies]
libtaos
=
{
version
=
"0.4.3"
}
libtaos
=
{
version
=
"0.4.5-alpha.0"
,
feature
=
["rest"]
}
tokio
=
{
version
=
"*"
,
features
=
[
"rt"
,
"macros"
,
"rt-multi-thread"
]
}
tokio
=
{
version
=
"1"
,
features
=
["full"]
}
bstr
=
{
version
=
"*"
}
docs/examples/rust/cloud_example/src/main.rs
0 → 100644
浏览文件 @
590062c4
use
libtaos
::
*
;
fn
main
()
{
let
token
=
std
::
env
::
var
(
"TDENGINE_CLOUD_TOKEN"
)
.unwrap
();
let
url
=
std
::
env
::
var
(
"TDENGINE_CLOUD_URL"
)
.unwrap
();
let
dsn
=
url
+
"?token="
+
&
token
;
let
taos
=
TaosCfg
::
from_dsn
(
dsn
)
?
;
println!
(
"connected"
);
}
\ No newline at end of file
docs/examples/rust/nativeexample/examples/connect.rs
已删除
100644 → 0
浏览文件 @
0dfa8159
use
libtaos
::
*
;
fn
taos_connect
()
->
Result
<
Taos
,
Error
>
{
TaosCfgBuilder
::
default
()
.ip
(
"localhost"
)
.user
(
"root"
)
.pass
(
"taosdata"
)
// .db("log") // remove comment if you want to connect to database log by default.
.port
(
6030u16
)
.build
()
.expect
(
"TaosCfg builder error"
)
.connect
()
}
fn
main
()
{
#[allow(unused_variables)]
let
taos
=
taos_connect
()
.unwrap
();
println!
(
"Connected"
)
}
docs/examples/rust/nativeexample/examples/stmt_example.rs
已删除
100644 → 0
浏览文件 @
0dfa8159
use
bstr
::
BString
;
use
libtaos
::
*
;
#[tokio::main]
async
fn
main
()
->
Result
<
(),
Error
>
{
let
taos
=
TaosCfg
::
default
()
.connect
()
.expect
(
"fail to connect"
);
taos
.create_database
(
"power"
)
.await
?
;
taos
.use_database
(
"power"
)
.await
?
;
taos
.exec
(
"CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"
)
.await
?
;
let
mut
stmt
=
taos
.stmt
(
"INSERT INTO ? USING meters TAGS(?, ?) VALUES(?, ?, ?, ?)"
)
?
;
// bind table name and tags
stmt
.set_tbname_tags
(
"d1001"
,
[
Field
::
Binary
(
BString
::
from
(
"California.SanFrancisco"
)),
Field
::
Int
(
2
),
],
)
?
;
// bind values.
let
values
=
vec!
[
Field
::
Timestamp
(
Timestamp
::
new
(
1648432611249
,
TimestampPrecision
::
Milli
)),
Field
::
Float
(
10.3
),
Field
::
Int
(
219
),
Field
::
Float
(
0.31
),
];
stmt
.bind
(
&
values
)
?
;
// bind one more row
let
values2
=
vec!
[
Field
::
Timestamp
(
Timestamp
::
new
(
1648432611749
,
TimestampPrecision
::
Milli
)),
Field
::
Float
(
12.6
),
Field
::
Int
(
218
),
Field
::
Float
(
0.33
),
];
stmt
.bind
(
&
values2
)
?
;
// execute
stmt
.execute
()
?
;
Ok
(())
}
docs/examples/rust/nativeexample/examples/subscribe_demo.rs
已删除
100644 → 0
浏览文件 @
0dfa8159
fn
main
()
{
}
\ No newline at end of file
docs/examples/rust/nativeexample/src/main.rs
已删除
100644 → 0
浏览文件 @
0dfa8159
fn
main
()
{
println!
(
"Hello, world!"
);
}
docs/examples/rust/restexample/Cargo.toml
已删除
100644 → 0
浏览文件 @
0dfa8159
[package]
name
=
"restexample"
version
=
"0.1.0"
edition
=
"2021"
[dependencies]
libtaos
=
{
version
=
"0.4.3"
,
features
=
["rest"]
}
tokio
=
{
version
=
"*"
,
features
=
[
"rt"
,
"macros"
,
"rt-multi-thread"
]
}
docs/examples/rust/restexample/examples/connect.rs
已删除
100644 → 0
浏览文件 @
0dfa8159
use
libtaos
::
*
;
fn
taos_connect
()
->
Result
<
Taos
,
Error
>
{
TaosCfgBuilder
::
default
()
.ip
(
"localhost"
)
.user
(
"root"
)
.pass
(
"taosdata"
)
// .db("log") // remove comment if you want to connect to database log by default.
.port
(
6030u16
)
.build
()
.expect
(
"TaosCfg builder error"
)
.connect
()
}
#[tokio::main]
async
fn
main
()
{
#[allow(unused_variables)]
let
taos
=
taos_connect
()
.expect
(
"connect error"
);
println!
(
"Connected"
)
}
docs/examples/rust/restexample/examples/insert_example.rs
已删除
100644 → 0
浏览文件 @
0dfa8159
use
libtaos
::
*
;
#[tokio::main]
async
fn
main
()
->
Result
<
(),
Error
>
{
let
taos
=
TaosCfg
::
default
()
.connect
()
.expect
(
"fail to connect"
);
taos
.create_database
(
"power"
)
.await
?
;
taos
.exec
(
"CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"
)
.await
?
;
let
sql
=
"INSERT INTO power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
power.d1002 USING power.meters TAGS(California.SanFrancisco, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
power.d1003 USING power.meters TAGS(California.LosAngeles, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
power.d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)"
;
let
result
=
taos
.query
(
sql
)
.await
?
;
println!
(
"{:?}"
,
result
);
Ok
(())
}
// output:
// TaosQueryData { column_meta: [ColumnMeta { name: "affected_rows", type_: Int, bytes: 4 }], rows: [[Int(8)]] }
docs/examples/rust/restexample/examples/query_example.rs
已删除
100644 → 0
浏览文件 @
0dfa8159
use
libtaos
::
*
;
fn
taos_connect
()
->
Result
<
Taos
,
Error
>
{
TaosCfgBuilder
::
default
()
.ip
(
"localhost"
)
.user
(
"root"
)
.pass
(
"taosdata"
)
.db
(
"power"
)
.port
(
6030u16
)
.build
()
.expect
(
"TaosCfg builder error"
)
.connect
()
}
#[tokio::main]
async
fn
main
()
->
Result
<
(),
Error
>
{
let
taos
=
taos_connect
()
.expect
(
"connect error"
);
let
result
=
taos
.query
(
"SELECT ts, current FROM meters LIMIT 2"
)
.await
?
;
// print column names
let
meta
:
Vec
<
ColumnMeta
>
=
result
.column_meta
;
for
column
in
meta
{
print!
(
"{}
\t
"
,
column
.name
)
}
println!
();
// print rows
let
rows
:
Vec
<
Vec
<
Field
>>
=
result
.rows
;
for
row
in
rows
{
for
field
in
row
{
print!
(
"{}
\t
"
,
field
);
}
println!
();
}
Ok
(())
}
// output:
// ts current
// 2022-03-28 09:56:51.249 10.3
// 2022-03-28 09:56:51.749 12.6
docs/examples/rust/restexample/src/main.rs
已删除
100644 → 0
浏览文件 @
0dfa8159
fn
main
()
{
println!
(
"Hello, world!"
);
}
docs/examples/rust/schemalessexample/Cargo.toml
已删除
100644 → 0
浏览文件 @
0dfa8159
[package]
name
=
"schemalessexample"
version
=
"0.1.0"
edition
=
"2021"
[dependencies]
libtaos
=
{
version
=
"0.4.3"
}
docs/examples/rust/schemalessexample/examples/influxdb_line_example.rs
已删除
100644 → 0
浏览文件 @
0dfa8159
use
libtaos
::
schemaless
::
*
;
use
libtaos
::
*
;
fn
main
()
{
let
taos
=
TaosCfg
::
default
()
.connect
()
.expect
(
"fail to connect"
);
taos
.raw_query
(
"CREATE DATABASE test"
)
.unwrap
();
taos
.raw_query
(
"USE test"
)
.unwrap
();
let
lines
=
[
"meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249"
,
"meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250"
,
"meters,location=California.LosAngeles,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249"
,
"meters,location=California.LosAngeles,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250"
];
let
affected_rows
=
taos
.schemaless_insert
(
&
lines
,
TSDB_SML_LINE_PROTOCOL
,
TSDB_SML_TIMESTAMP_MILLISECONDS
,
)
.unwrap
();
println!
(
"affected_rows={}"
,
affected_rows
);
}
// run with: cargo run --example influxdb_line_example
docs/examples/rust/schemalessexample/examples/opentsdb_json_example.rs
已删除
100644 → 0
浏览文件 @
0dfa8159
use
libtaos
::
schemaless
::
*
;
use
libtaos
::
*
;
fn
main
()
{
let
taos
=
TaosCfg
::
default
()
.connect
()
.expect
(
"fail to connect"
);
taos
.raw_query
(
"CREATE DATABASE test"
)
.unwrap
();
taos
.raw_query
(
"USE test"
)
.unwrap
();
let
lines
=
[
r#"[{"metric": "meters.current", "timestamp": 1648432611249, "value": 10.3, "tags": {"location": "California.SanFrancisco", "groupid": 2}},
{"metric": "meters.voltage", "timestamp": 1648432611249, "value": 219, "tags": {"location": "California.LosAngeles", "groupid": 1}},
{"metric": "meters.current", "timestamp": 1648432611250, "value": 12.6, "tags": {"location": "California.SanFrancisco", "groupid": 2}},
{"metric": "meters.voltage", "timestamp": 1648432611250, "value": 221, "tags": {"location": "California.LosAngeles", "groupid": 1}}]"#
,
];
let
affected_rows
=
taos
.schemaless_insert
(
&
lines
,
TSDB_SML_JSON_PROTOCOL
,
TSDB_SML_TIMESTAMP_NOT_CONFIGURED
,
)
.unwrap
();
println!
(
"affected_rows={}"
,
affected_rows
);
// affected_rows=4
}
// run with: cargo run --example opentsdb_json_example
docs/examples/rust/schemalessexample/examples/opentsdb_telnet_example.rs
已删除
100644 → 0
浏览文件 @
0dfa8159
use
libtaos
::
schemaless
::
*
;
use
libtaos
::
*
;
fn
main
()
{
let
taos
=
TaosCfg
::
default
()
.connect
()
.expect
(
"fail to connect"
);
taos
.raw_query
(
"CREATE DATABASE test"
)
.unwrap
();
taos
.raw_query
(
"USE test"
)
.unwrap
();
let
lines
=
[
"meters.current 1648432611249 10.3 location=California.SanFrancisco groupid=2"
,
"meters.current 1648432611250 12.6 location=California.SanFrancisco groupid=2"
,
"meters.current 1648432611249 10.8 location=California.LosAngeles groupid=3"
,
"meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3"
,
"meters.voltage 1648432611249 219 location=California.SanFrancisco groupid=2"
,
"meters.voltage 1648432611250 218 location=California.SanFrancisco groupid=2"
,
"meters.voltage 1648432611249 221 location=California.LosAngeles groupid=3"
,
"meters.voltage 1648432611250 217 location=California.LosAngeles groupid=3"
,
];
let
affected_rows
=
taos
.schemaless_insert
(
&
lines
,
TSDB_SML_TELNET_PROTOCOL
,
TSDB_SML_TIMESTAMP_NOT_CONFIGURED
,
)
.unwrap
();
println!
(
"affected_rows={}"
,
affected_rows
);
// affected_rows=8
}
// run with: cargo run --example opentsdb_telnet_example
docs/examples/rust/schemalessexample/src/main.rs
已删除
100644 → 0
浏览文件 @
0dfa8159
fn
main
()
{
println!
(
"Hello, world!"
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录