未验证 提交 b2325071 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

docs: refine reference docs (#12590)

* docs: reference doc in English

[TD-15603]

* docs: reference docs in English

[TD-15603]

* docs: refine reference English docs

[TD-15603]

* docs: refine reference docs

* docs: refine refince docs
上级 c0529691
...@@ -9,7 +9,7 @@ description: TDengine Java 连接器基于标准 JDBC API 实现, 并提供原 ...@@ -9,7 +9,7 @@ description: TDengine Java 连接器基于标准 JDBC API 实现, 并提供原
import Tabs from '@theme/Tabs'; import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem'; import TabItem from '@theme/TabItem';
`taos-jdbcdriver` 是 TDengine 的官方 Java 语言连接器,Java 开发人员可以通过它开发存取 TDengine 数据库的应用软件。`taos-jdbcdriver` 实现了 JDBC driver 标准的接口,并提供两种形式的连接器。一种是通过 TDengine 客户端驱动程序(taosc)原生连接 TDengine 实例,支持数据写入、查询、订阅、schemaless 接口和参数绑定接口等功能,一种是通过 taosAdapter 提供的 REST 接口连接 TDengine 实例(2.0.18 及更高版本)。REST 连接实现的功能集合和原生连接有少量不同。 `taos-jdbcdriver` 是 TDengine 的官方 Java 语言连接器,Java 开发人员可以通过它开发存取 TDengine 数据库的应用软件。`taos-jdbcdriver` 实现了 JDBC driver 标准的接口,并提供两种形式的连接器。一种是通过 TDengine 客户端驱动程序(taosc)原生连接 TDengine 实例,支持数据写入、查询、订阅、schemaless 接口和参数绑定接口等功能,一种是通过 taosAdapter 提供的 REST 接口连接 TDengine 实例(2.4.0.0 及更高版本)。REST 连接实现的功能集合和原生连接有少量不同。
![tdengine-connector](tdengine-jdbc-connector.png) ![tdengine-connector](tdengine-jdbc-connector.png)
...@@ -804,7 +804,7 @@ Query OK, 1 row(s) in set (0.000141s) ...@@ -804,7 +804,7 @@ Query OK, 1 row(s) in set (0.000141s)
请参考:[JDBC example](https://github.com/taosdata/TDengine/tree/develop/examples/JDBC) 请参考:[JDBC example](https://github.com/taosdata/TDengine/tree/develop/examples/JDBC)
## 重要更新记录 ## 最近更新记录
| taos-jdbcdriver 版本 | 主要变化 | | taos-jdbcdriver 版本 | 主要变化 |
| :------------------: | :----------------------------: | | :------------------: | :----------------------------: |
...@@ -814,7 +814,7 @@ Query OK, 1 row(s) in set (0.000141s) ...@@ -814,7 +814,7 @@ Query OK, 1 row(s) in set (0.000141s)
## 常见问题 ## 常见问题
1. 使用 Statement 的 `addBatch` 和 `executeBatch` 来执行“批量写入/更行”,为什么没有带来性能上的提升? 1. 使用 Statement 的 `addBatch()` 和 `executeBatch()` 来执行“批量写入/更新”,为什么没有带来性能上的提升?
**原因**:TDengine 的 JDBC 实现中,通过 `addBatch` 方法提交的 SQL 语句,会按照添加的顺序,依次执行,这种方式没有减少与服务端的交互次数,不会带来性能上的提升。 **原因**:TDengine 的 JDBC 实现中,通过 `addBatch` 方法提交的 SQL 语句,会按照添加的顺序,依次执行,这种方式没有减少与服务端的交互次数,不会带来性能上的提升。
......
...@@ -122,7 +122,7 @@ Requirement already satisfied: taospy in c:\users\username\appdata\local\program ...@@ -122,7 +122,7 @@ Requirement already satisfied: taospy in c:\users\username\appdata\local\program
<Tabs> <Tabs>
<TabItem value="native" label="原生连接"> <TabItem value="native" label="原生连接">
请确保 TDengine 集群已经启动, 且集群中机器的 FQDN (如果启动的是单机版,FQDN 默认为 hostname)在本机能够解析, 可用 ping 命令进行测试: 请确保 TDengine 集群已经启动, 且集群中机器的 FQDN (如果启动的是单机版,FQDN 默认为 hostname)在本机能够解析, 可用 `ping` 命令进行测试:
``` ```
ping <FQDN> ping <FQDN>
...@@ -197,7 +197,7 @@ curl -u root:taosdata http://<FQDN>:<PORT>/rest/sql -d "select server_version()" ...@@ -197,7 +197,7 @@ curl -u root:taosdata http://<FQDN>:<PORT>/rest/sql -d "select server_version()"
{{#include docs-examples/python/connect_rest_examples.py:connect}} {{#include docs-examples/python/connect_rest_examples.py:connect}}
``` ```
`connect` 函数的所有参数都是可选的关键字参数。下面是连接参数的具体说明: `connect()` 函数的所有参数都是可选的关键字参数。下面是连接参数的具体说明:
- `host`: 要连接的主机。默认是 localhost。 - `host`: 要连接的主机。默认是 localhost。
- `user`: TDenigne 用户名。默认是 root。 - `user`: TDenigne 用户名。默认是 root。
...@@ -205,10 +205,6 @@ curl -u root:taosdata http://<FQDN>:<PORT>/rest/sql -d "select server_version()" ...@@ -205,10 +205,6 @@ curl -u root:taosdata http://<FQDN>:<PORT>/rest/sql -d "select server_version()"
- `port`: taosAdapter REST 服务监听端口。默认是 6041. - `port`: taosAdapter REST 服务监听端口。默认是 6041.
- `timeout`: HTTP 请求超时时间。单位为秒。默认为 `socket._GLOBAL_DEFAULT_TIMEOUT`。 一般无需配置。 - `timeout`: HTTP 请求超时时间。单位为秒。默认为 `socket._GLOBAL_DEFAULT_TIMEOUT`。 一般无需配置。
:::note
:::
</TabItem> </TabItem>
</Tabs> </Tabs>
...@@ -232,12 +228,12 @@ curl -u root:taosdata http://<FQDN>:<PORT>/rest/sql -d "select server_version()" ...@@ -232,12 +228,12 @@ curl -u root:taosdata http://<FQDN>:<PORT>/rest/sql -d "select server_version()"
``` ```
:::tip :::tip
查询结果只能获取一次。比如上面的示例中 `featch_all` 和 `fetch_all_into_dict` 只能用一个。重复获取得到的结果为空列表。 查询结果只能获取一次。比如上面的示例中 `fetch_all()` 和 `fetch_all_into_dict()` 只能用一个。重复获取得到的结果为空列表。
::: :::
##### TaosResult 类的使用 ##### TaosResult 类的使用
上面 `TaosConnection` 类的使用示例中,我们已经展示了两种获取查询结果的方法: `featch_all` 和 `fetch_all_into_dict`。除此之外 `TaosResult` 还提供了按行迭代(`rows_iter`)或按数据块迭代(`blocks_iter`)结果集的方法。在查询数据量较大的场景,使用这两个方法会更高效。 上面 `TaosConnection` 类的使用示例中,我们已经展示了两种获取查询结果的方法: `fetch_all()` 和 `fetch_all_into_dict()`。除此之外 `TaosResult` 还提供了按行迭代(`rows_iter`)或按数据块迭代(`blocks_iter`)结果集的方法。在查询数据量较大的场景,使用这两个方法会更高效。
```python title="blocks_iter 方法" ```python title="blocks_iter 方法"
{{#include docs-examples/python/result_set_examples.py}} {{#include docs-examples/python/result_set_examples.py}}
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
title: Connector title: Connector
--- ---
TDengine provides a rich application development interface. To facilitate users to develop their own applications quickly, TDengine supports connectors for multiple programming languages, including official connectors for C/C++, Java, Python, Go, Node.js, C#, and Rust. These connectors support connecting to TDengine clusters using both native interfaces (taosc) and REST interfaces (not supported in some languages yet). Community developers have also contributed several unofficial connectors, such as the ADO.NET connector, the Lua connector, and the PHP connector. TDengine provides a rich set of APIs (application development interface). To facilitate users to develop their applications quickly, TDengine supports connectors for multiple programming languages, including official connectors for C/C++, Java, Python, Go, Node.js, C#, and Rust. These connectors support connecting to TDengine clusters using both native interfaces (taosc) and REST interfaces (not supported in a few languages yet). Community developers have also contributed several unofficial connectors, such as the ADO.NET connector, the Lua connector, and the PHP connector.
![image-connector](/img/connector.png) ![image-connector](/img/connector.png)
...@@ -84,7 +84,7 @@ import InstallOnLinux from "./_windows_install.mdx"; ...@@ -84,7 +84,7 @@ import InstallOnLinux from "./_windows_install.mdx";
import VerifyWindows from "./_verify_windows.mdx"; import VerifyWindows from "./_verify_windows.mdx";
import VerifyLinux from "./_verify_linux.mdx"; import VerifyLinux from "./_verify_linux.mdx";
## Install client driver ## Install Client Driver
:::info :::info
The client driver needs to be installed if you use the native interface connector on a system that does not have the TDengine server software installed. The client driver needs to be installed if you use the native interface connector on a system that does not have the TDengine server software installed.
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
Since the TDengine client driver is written in C, using the native connection requires loading the client driver shared library file, which is usually included in the TDengine installer. You can install either standard TDengine server installation package or [TDengine client installtion package](/get-started/). For Windows development, you need to install the corresponding [Windows client](https://www.taosdata.com/cn/all-downloads/#TDengine-Windows-Client) for TDengine. Since the TDengine client driver is written in C, using the native connection requires loading the client driver shared library file, which is usually included in the TDengine installer. You can install either standard TDengine server installation package or [TDengine client installtion package](/get-started/). For Windows development, you need to install the corresponding [Windows client](https://www.taosdata.com/cn/all-downloads/#TDengine-Windows-Client) for TDengine.
- libtaos.so: After successful installation of TDengine on a Linux system, the dependent Linux version of the client driver libtaos.so file will be automatically copied to /usr/lib/libtaos.so, which is included in the Linux scanable path and does not need to be specified separately. - libtaos.so: After successful installation of TDengine on a Linux system, the dependent Linux version of the client driver `libtaos.so` file will be automatically linked to `/usr/lib/libtaos.so`, which is included in the Linux scannable path and does not need to be specified separately.
- taos.dll: After installing the client on Windows, the dependent Windows version of the client driver taos.dll file will be automatically copied to the system default search path C:/Windows/System32, again without the need to specify it separately. - taos.dll: After installing the client on Windows, the dependent Windows version of the client driver taos.dll file will be automatically copied to the system default search path C:/Windows/System32, again without the need to specify it separately.
::: :::
Execute `taos` directly from the Linux shell to connect to the TDengine service and enter the TDengine CLI interface, as shown in the following example. Execute TDengine CLI program `taos` directly from the Linux shell to connect to the TDengine service and enter the TDengine CLI interface, as shown in the following example.
```text ```text
$ taos $ taos
......
Go to the C:\TDengine directory from `cmd` and execute `taos.exe` directly to connect to the TDengine service and enter the TDengine CLI interface, for example, as follows: Go to the `C:\TDengine` directory from `cmd` and execute TDengine CLI program `taos.exe` directly to connect to the TDengine service and enter the TDengine CLI interface, for example, as follows:
```text ```text
C:\TDengine>taos C:\TDengine>taos
......
...@@ -17,9 +17,9 @@ import CSQuery from "../../04-develop/04-query-data/_cs.mdx" ...@@ -17,9 +17,9 @@ import CSQuery from "../../04-develop/04-query-data/_cs.mdx"
import CSAsyncQuery from "../../04-develop/04-query-data/_cs_async.mdx" import CSAsyncQuery from "../../04-develop/04-query-data/_cs_async.mdx"
TDengine.Connector` is a C# language connector provided by TDengine that allows C# developers to develop C# applications that access TDengine cluster data. `TDengine.Connector` is a C# language connector provided by TDengine that allows C# developers to develop C# applications that access TDengine cluster data.
The `TDengine.Connector` connector supports connection to TDengine runtime instances via the TDengine client driver (taosc), providing data writing, querying, subscription, schemaless data writing, bind interface data writing, etc. The `TDengine.Connector` currently does not provide a REST connection. REST connection is not yet available. Users can write their RESTful APIs by referring to the [RESTful APIs](https://docs.taosdata.com//reference/restful-api/) documentation. The `TDengine.Connector` connector supports connect to TDengine instances via the TDengine client driver (taosc), providing data writing, querying, subscription, schemaless writing, bind interface, etc. The `TDengine.Connector` currently does not provide a REST connection interface. Developers can write their RESTful application by referring to the [RESTful APIs](https://docs.taosdata.com//reference/restful-api/) documentation.
This article describes how to install `TDengine.Connector` in a Linux or Windows environment and connect to TDengine clusters via `TDengine.Connector` to perform basic operations such as data writing and querying. This article describes how to install `TDengine.Connector` in a Linux or Windows environment and connect to TDengine clusters via `TDengine.Connector` to perform basic operations such as data writing and querying.
...@@ -35,11 +35,11 @@ Please refer to [version support list](/reference/connector#version support) ...@@ -35,11 +35,11 @@ Please refer to [version support list](/reference/connector#version support)
## Supported features ## Supported features
1. connection management 1. Connection Mmanagement
2. general query 2. General Query
3. continuous query 3. Continuous Query
4. parameter binding 4. Parameter Binding
5. subscription function 5. Subscription
6. Schemaless 6. Schemaless
## Installation Steps ## Installation Steps
...@@ -50,7 +50,7 @@ Please refer to [version support list](/reference/connector#version support) ...@@ -50,7 +50,7 @@ Please refer to [version support list](/reference/connector#version support)
* [Nuget Client](https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools) (optional installation) * [Nuget Client](https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools) (optional installation)
* Install TDengine client driver, please refer to [Install client driver](/reference/connector#Install client driver) for details * Install TDengine client driver, please refer to [Install client driver](/reference/connector#Install client driver) for details
### Install using dotnet CLI ### Install via dotnet CLI
<Tabs defaultValue="CLI"> <Tabs defaultValue="CLI">
<TabItem value="CLI" label="Get C# driver using dotnet CLI"> <TabItem value="CLI" label="Get C# driver using dotnet CLI">
...@@ -179,7 +179,7 @@ namespace TDengineExample ...@@ -179,7 +179,7 @@ namespace TDengineExample
1. "Unable to establish connection", "Unable to resolve FQDN" 1. "Unable to establish connection", "Unable to resolve FQDN"
Usually, because the FQDN configuration is incorrect, you can refer to [How to understand TDengine's FQDN thoroughly](https://www.taosdata.com/blog/2021/07/29/2741.html) to solve it. 2. Usually, it cause by the FQDN configuration is incorrect, you can refer to [How to understand TDengine's FQDN (Chinese)](https://www.taosdata.com/blog/2021/07/29/2741.html) to solve it. 2.
Unhandled exception. System.DllNotFoundException: Unable to load DLL 'taos' or one of its dependencies: The specified module cannot be found. Unhandled exception. System.DllNotFoundException: Unable to load DLL 'taos' or one of its dependencies: The specified module cannot be found.
......
...@@ -15,9 +15,9 @@ import GoOpenTSDBTelnet from "../../04-develop/03-insert-data/_go_opts_telnet.md ...@@ -15,9 +15,9 @@ import GoOpenTSDBTelnet from "../../04-develop/03-insert-data/_go_opts_telnet.md
import GoOpenTSDBJson from "../../04-develop/03-insert-data/_go_opts_json.mdx" import GoOpenTSDBJson from "../../04-develop/03-insert-data/_go_opts_json.mdx"
import GoQuery from "../../04-develop/04-query-data/_go.mdx" import GoQuery from "../../04-develop/04-query-data/_go.mdx"
`driver-go` is the official Go language connector for TDengine, which implements the interface to the Go language [ database/sql ](https://golang.org/pkg/database/sql/) package. Go developers can use it to develop applications that access TDengine cluster data. `driver-go` is the official Go language connector for TDengine, which implements the interface to the Go language [database/sql](https://golang.org/pkg/database/sql/) package. Go developers can use it to develop applications that access TDengine cluster data.
`driver-go` provides two ways to establish connections. One is **native connection**, which connects to TDengine runtime instances natively through the TDengine client driver (taosc), supporting data writing, querying, subscriptions, schemaless interface, and parameter binding interface. The other is the **REST connection**, which connects to TDengine runtime instances via the REST interface provided by taosAdapter. The set of features implemented by the REST connection differs slightly from the native connection. `driver-go` provides two ways to establish connections. One is **native connection**, which connects to TDengine instances natively through the TDengine client driver (taosc), supporting data writing, querying, subscriptions, schemaless writing, and bind interface. The other is the **REST connection**, which connects to TDengine instances via the REST interface provided by taosAdapter. The set of features implemented by the REST connection differs slightly from the native connection.
This article describes how to install `driver-go` and connect to TDengine clusters and perform basic operations such as data query and data writing through `driver-go`. This article describes how to install `driver-go` and connect to TDengine clusters and perform basic operations such as data query and data writing through `driver-go`.
...@@ -36,7 +36,7 @@ Please refer to [version support list](/reference/connector#version support) ...@@ -36,7 +36,7 @@ Please refer to [version support list](/reference/connector#version support)
### Native connections ### Native connections
A "native connection" is established by the connector directly to the TDengine runtime instance via the TDengine client driver (taosc). The supported functional features are A "native connection" is established by the connector directly to the TDengine instance via the TDengine client driver (taosc). The supported functional features are:
* Normal queries * Normal queries
* Continuous queries * Continuous queries
...@@ -46,7 +46,7 @@ A "native connection" is established by the connector directly to the TDengine r ...@@ -46,7 +46,7 @@ A "native connection" is established by the connector directly to the TDengine r
### REST connection ### REST connection
A "REST connection" is a connection between a connector and a TDengine runtime instance via the REST API provided by the taosAdapter component. The following features are supported. A "REST connection" is a connection between the application and the TDengine instance via the REST API provided by the taosAdapter component. The following features are supported:
* General queries * General queries
* Continuous queries * Continuous queries
...@@ -75,7 +75,7 @@ Configure the environment variables and check the command. ...@@ -75,7 +75,7 @@ Configure the environment variables and check the command.
go mod init taos-demo go mod init taos-demo
``` text ``` text
2. Introduce taosSql: ``text 2. Introduce taosSql
```go ```go
import ( import (
...@@ -101,7 +101,7 @@ Configure the environment variables and check the command. ...@@ -101,7 +101,7 @@ Configure the environment variables and check the command.
### Data source name (DSN) ### Data source name (DSN)
Data source names have a standard format, e.g. [PEAR DB](http://pear.php.net/manual/en/package.database.db.intro-dsn.php), but no type prefix (square brackets indicate optionally): the Data source names have a standard format, e.g. [PEAR DB](http://pear.php.net/manual/en/package.database.db.intro-dsn.php), but no type prefix (square brackets indicate optionally):
``` text ``` text
[username[:password]@][protocol[(address)]]/[dbname][?param1=value1&... &paramN=valueN] [username[:password]@][protocol[(address)]]/[dbname][?param1=value1&... &paramN=valueN]
...@@ -112,7 +112,8 @@ DSN in full form. ...@@ -112,7 +112,8 @@ DSN in full form.
```text ```text
username:password@protocol(address)/dbname?param=value username:password@protocol(address)/dbname?param=value
``` ```
### Connecting using connectors
### Connecting via connector
<Tabs defaultValue="native"> <Tabs defaultValue="native">
<TabItem value="native" label="native connection"> <TabItem value="native" label="native connection">
...@@ -121,7 +122,7 @@ _taosSql_ implements Go's `database/sql/driver` interface via cgo. You can use t ...@@ -121,7 +122,7 @@ _taosSql_ implements Go's `database/sql/driver` interface via cgo. You can use t
Use `taosSql` as `driverName` and use a correct [DSN](#DSN) as `dataSourceName`, DSN supports the following parameters. Use `taosSql` as `driverName` and use a correct [DSN](#DSN) as `dataSourceName`, DSN supports the following parameters.
* configPath specifies the taos.cfg directory * configPath specifies the `taos.cfg` directory
Example. Example.
...@@ -210,7 +211,7 @@ func main() { ...@@ -210,7 +211,7 @@ func main() {
## Usage limitations ## Usage limitations
Since the REST interface is stateless, the `use db` syntax will not work. You need to put the db name into the SQL statement, e.g. `create table if not exists tb1 (ts timestamp, a int)` to `create table if not exists test.tb1 (ts timestamp, a int)` otherwise it will report the error `[0x217] Database not specified or available`. Since the REST interface is stateless, the `use db` syntax will not work. You need to put the db name into the SQL command, e.g. `create table if not exists tb1 (ts timestamp, a int)` to `create table if not exists test.tb1 (ts timestamp, a int)` otherwise it will report the error `[0x217] Database not specified or available`.
You can also put the db name in the DSN by changing `root:taosdata@http(localhost:6041)/` to `root:taosdata@http(localhost:6041)/test`. This method is supported by taosAdapter in TDengine 2.4.0.5. is supported since TDengine 2.4.0.5. Executing the `create database` statement when the specified db does not exist will not report an error while executing other queries or writing against that db will report an error. You can also put the db name in the DSN by changing `root:taosdata@http(localhost:6041)/` to `root:taosdata@http(localhost:6041)/test`. This method is supported by taosAdapter in TDengine 2.4.0.5. is supported since TDengine 2.4.0.5. Executing the `create database` statement when the specified db does not exist will not report an error while executing other queries or writing against that db will report an error.
...@@ -268,27 +269,27 @@ func main() { ...@@ -268,27 +269,27 @@ func main() {
1. Cannot find the package `github.com/taosdata/driver-go/v2/taosRestful` 1. Cannot find the package `github.com/taosdata/driver-go/v2/taosRestful`
Change the reference to `github.com/taosdata/driver-go/v2` in the require block in `go.mod` to `github.com/taosdata/driver-go/v2 develop`, then execute `go mod tidy`. Change the `github.com/taosdata/driver-go/v2` line in the require block of the `go.mod` file to `github.com/taosdata/driver-go/v2 develop`, then execute `go mod tidy`.
2. stmt (parameter binding) related interface in database/sql crashes 2. bind interface in database/sql crashes
REST does not support parameter binding related interface. It is recommended to use `db.Exec` and `db.Query`. REST does not support parameter binding related interface. It is recommended to use `db.Exec` and `db.Query`.
3. error `[0x217] Database not specified or available` after executing other statements with `use db` statement 3. error `[0x217] Database not specified or available` after executing other statements with `use db` statement
The execution of SQL statements in the REST interface is not contextual, so using `use db` statement will not work, see the usage restrictions section above. The execution of SQL command in the REST interface is not contextual, so using `use db` statement will not work, see the usage restrictions section above.
4. use taosSql without error use taosRestful with error `[0x217] Database not specified or available` 4. use `taosSql` without error but use `taosRestful` with error `[0x217] Database not specified or available`
Because the REST interface is stateless, using the `use db` statement will not take effect. See the usage restrictions section above. Because the REST interface is stateless, using the `use db` statement will not take effect. See the usage restrictions section above.
5. Upgrade `github.com/taosdata/driver-go/v2/taosRestful` 5. Upgrade `github.com/taosdata/driver-go/v2/taosRestful`
Change the reference to `github.com/taosdata/driver-go/v2` in the `go.mod` file to `github.com/taosdata/driver-go/v2 develop`, then execute `go mod tidy`. Change the `github.com/taosdata/driver-go/v2` line in the `go.mod` file to `github.com/taosdata/driver-go/v2 develop`, then execute `go mod tidy`.
6. `readBufferSize` parameter has no significant effect after being increased 6. `readBufferSize` parameter has no significant effect after being increased
If you increase `readBufferSize` will reduce the number of `syscall` calls when fetching results. If the query result is more petite, modifying this parameter will not improve significantly. If you increase the parameter too much, the bottleneck will be parsing JSON data. If you need to optimize the query speed, you must adjust the value according to the actual situation to achieve the best query result. If you increase `readBufferSize` will reduce the number of `syscall` calls when fetching results. If the query result is smaller, modifying this parameter will not improve significantly. If you increase the parameter value too much, the bottleneck will be parsing JSON data. If you need to optimize the query speed, you must adjust the value according to the actual situation to achieve the best query result.
7. `disableCompression` parameter is set to `false` when the query efficiency is reduced 7. `disableCompression` parameter is set to `false` when the query efficiency is reduced
......
...@@ -16,9 +16,9 @@ import NodeOpenTSDBJson from "../../04-develop/03-insert-data/_js_opts_json.mdx" ...@@ -16,9 +16,9 @@ import NodeOpenTSDBJson from "../../04-develop/03-insert-data/_js_opts_json.mdx"
import NodeQuery from "../../04-develop/04-query-data/_js.mdx"; import NodeQuery from "../../04-develop/04-query-data/_js.mdx";
import NodeAsyncQuery from "../../04-develop/04-query-data/_js_async.mdx"; import NodeAsyncQuery from "../../04-develop/04-query-data/_js_async.mdx";
`td2.0-connector` and `td2.0-rest-connector` are the official Node.js language connectors for TDengine, through which Node.js developers can develop applications that can access TDengine cluster data. `td2.0-connector` and `td2.0-rest-connector` are the official Node.js language connectors for TDengine. Node.js developers can develop applications to access TDengine instance data.
`td2.0-connector` is a **native connector** that connects to TDengine runtime instances via the TDengine client driver (taosc) and supports data writing, querying, subscriptions, schemaless interface, and parameter binding interface. The `td2.0-rest-connector` is a **REST connector** that connects to TDengine runtime instances via the REST interface provided by taosAdapter. The REST connector can run on any platform, but performance is slightly degraded, and the interface implements a somewhat different set of functional features than the native interface. `td2.0-connector` is a **native connector** that connects to TDengine instances via the TDengine client driver (taosc) and supports data writing, querying, subscriptions, schemaless writing, and bind interface. The `td2.0-rest-connector` is a **REST connector** that connects to TDengine instances via the REST interface provided by taosAdapter. The REST connector can run on any platform, but performance is slightly degraded, and the interface implements a somewhat different set of functional features than the native interface.
The Node.js connector source code is hosted on [GitHub](https://github.com/taosdata/taos-connector-node). The Node.js connector source code is hosted on [GitHub](https://github.com/taosdata/taos-connector-node).
...@@ -53,7 +53,7 @@ Please refer to [version support list](/reference/connector#version support) ...@@ -53,7 +53,7 @@ Please refer to [version support list](/reference/connector#version support)
### Pre-installation ### Pre-installation
- Install the Node.js development environment - Install the Node.js development environment
- If you are using the REST connector, skip this step. However, if you use the native connector, please install the TDengine client driver. Please refer to [install client driver](/reference/connector#install-client-driver) for more details. We use [node-gyp](https://github.com/nodejs/node-gyp) to interact with TDengine instances and also need to install some dependencies mentioned below depending on the specific OS. - If you are using the REST connector, skip this step. However, if you use the native connector, please install the TDengine client driver. Please refer to [Install Client Driver](/reference/connector#Install-Client-Driver) for more details. We use [node-gyp](https://github.com/nodejs/node-gyp) to interact with TDengine instances and also need to install some dependencies mentioned below depending on the specific OS.
<Tabs defaultValue="Linux"> <Tabs defaultValue="Linux">
<TabItem value="Linux" label="Linux system installation dependencies"> <TabItem value="Linux" label="Linux system installation dependencies">
...@@ -68,17 +68,17 @@ Please refer to [version support list](/reference/connector#version support) ...@@ -68,17 +68,17 @@ Please refer to [version support list](/reference/connector#version support)
- Installation method 1 - Installation method 1
Use Microsoft's [ windows-build-tools ](https://github.com/felixrieseberg/windows-build-tools) to execute `npm install --global --production` from the `cmd` command-line interface to install all the necessary tools. Use Microsoft's [windows-build-tools](https://github.com/felixrieseberg/windows-build-tools) to execute `npm install --global --production` from the `cmd` command-line interface to install all the necessary tools.
- Installation method 2 - Installation method 2
Manually install the following tools. Manually install the following tools.
- Install Visual Studio related: [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools) or [ Visual Studio 2017 Community](https://visualstudio.microsoft.com/pl/thank-you-downloading-visual-studio/?sku=Community) - Install Visual Studio related: [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools) or [Visual Studio 2017 Community](https://visualstudio.microsoft.com/pl/thank-you-downloading-visual-studio/?sku=Community)
- Install [Python](https://www.python.org/downloads/) 2.7 (`v3.x.x` is not supported) and execute `npm config set python python2.7`. - Install [Python](https://www.python.org/downloads/) 2.7 (`v3.x.x` is not supported) and execute `npm config set python python2.7`.
- Go to the `cmd` command-line interface, `npm config set msvs_version 2017` - Go to the `cmd` command-line interface, `npm config set msvs_version 2017`
Refer to Microsoft's Node.js User Manual [ Microsoft's Node.js Guidelines for Windows ](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows- environment. md#compiling-native-addon-modules). Refer to Microsoft's Node.js User Manual [Microsoft's Node.js Guidelines for Windows](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows- environment. md#compiling-native-addon-modules).
If using ARM64 Node.js on Windows 10 ARM, you must add "Visual C++ compilers and libraries for ARM64" and "Visual C++ ATL for ARM64". If using ARM64 Node.js on Windows 10 ARM, you must add "Visual C++ compilers and libraries for ARM64" and "Visual C++ ATL for ARM64".
...@@ -106,11 +106,11 @@ npm i td2.0-rest-connector ...@@ -106,11 +106,11 @@ npm i td2.0-rest-connector
### Installation verification ### Installation verification
After installing the TDengine client, use the nodejsChecker.js program to verify that the current environment supports Node.js access to TDengine. After installing the TDengine client, use the `nodejsChecker.js` program to verify that the current environment supports Node.js access to TDengine.
Validation method. Verification in details:
- Create a new installation verification directory, e.g. `~/tdengine-test`, and download the [nodejsChecker.js source code](https://github.com/taosdata/TDengine/tree/develop/examples/nodejs/) from GitHub. nodejsChecker.js) to local. - Create a new installation verification directory, e.g. `~/tdengine-test`, and download the [nodejsChecker.js source code](https://github.com/taosdata/TDengine/tree/develop/examples/nodejs/) from GitHub. to the work directory.
- Execute the following command from the command-line. - Execute the following command from the command-line.
...@@ -120,7 +120,7 @@ npm install td2.0-connector ...@@ -120,7 +120,7 @@ npm install td2.0-connector
node nodejsChecker.js host=localhost node nodejsChecker.js host=localhost
``` ```
- After executing the above steps, the command-line will output the result of nodejsChecker.js connecting to the TDengine instance and performing a simple insert and query. - After executing the above steps, the command-line will output the result of `nodejsChecker.js` connecting to the TDengine instance and performing a simple insert and query.
## Establishing a connection ## Establishing a connection
...@@ -148,7 +148,7 @@ conn.close(); ...@@ -148,7 +148,7 @@ conn.close();
``` ```
</TabItem> </TabItem>
<TabItem value="rest" label="REST 连接"> <TabItem value="rest" label="REST connection">
Install and refer to `td2.0-rest-connector`package: Install and refer to `td2.0-rest-connector`package:
...@@ -220,7 +220,7 @@ Node.js Connector >= v2.0.6 currently supports node versions >=v12.8.0 <= v12.9. ...@@ -220,7 +220,7 @@ Node.js Connector >= v2.0.6 currently supports node versions >=v12.8.0 <= v12.9.
## Other notes ## Other notes
See [video tutorial](https://www.taosdata.com/blog/2020/11/11/1957.html) for the Node.js connector. See [video tutorial](https://www.taosdata.com/blog/2020/11/11/1957.html) for the Node.js connector usage.
## Frequently Asked Questions ## Frequently Asked Questions
...@@ -230,13 +230,9 @@ See [video tutorial](https://www.taosdata.com/blog/2020/11/11/1957.html) for the ...@@ -230,13 +230,9 @@ See [video tutorial](https://www.taosdata.com/blog/2020/11/11/1957.html) for the
sudo systemctl start taosadapter sudo systemctl start taosadapter
``` ```
2. Node.js version 2. "Unable to establish connection", "Unable to resolve FQDN"
Connector >v2.0.6 Currently compatible Node.js versions are: >=v10.20.0 <= v10.9.0 || >=v12.8.0 <= v12.9.1 Usually, root cause is the FQDN is not configured correctly. You can refer to [How to understand TDengine's FQDN (In Chinese)](https://www.taosdata.com/blog/2021/07/29/2741.html).
3. "Unable to establish connection", "Unable to resolve FQDN"
Usually, it is because the FQDN is not configured correctly. You can refer to [How to understand TDengine's FQDN thoroughly](https://www.taosdata.com/blog/2021/07/29/2741.html).
## Important Updates ## Important Updates
......
...@@ -8,10 +8,10 @@ description: "taospy is the official Python connector for TDengine. taospy provi ...@@ -8,10 +8,10 @@ description: "taospy is the official Python connector for TDengine. taospy provi
import Tabs from "@theme/Tabs"; import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem"; import TabItem from "@theme/TabItem";
`taospy` is the official Python connector for TDengine. `taospy` provides a rich API that makes it easy for Python applications to use TDengine. `taospy` wraps both the [native interface](/reference/connector/cpp) and [REST interface](/reference/rest-api) of TDengine, which correspond to the `taos` and `taosrest` modules of the `taospy` package, respectively. `taospy` is the official Python connector for TDengine. `taospy` provides a rich set of APIs that makes it easy for Python applications to access TDengine. `taospy` wraps both the [native interface](/reference/connector/cpp) and [REST interface](/reference/rest-api) of TDengine, which correspond to the `taos` and `taosrest` modules of the `taospy` package, respectively.
In addition to wrapping the native and REST interfaces, `taospy` also provides a programming interface that conforms to the [Python Data Access Specification (PEP 249)](https://peps.python.org/pep-0249/). It is easy to integrate `taospy` with many third-party tools, such as [SQLAlchemy](https://www.sqlalchemy.org/) and [pandas](https://pandas.pydata.org/). In addition to wrapping the native and REST interfaces, `taospy` also provides a set of programming interfaces that conforms to the [Python Data Access Specification (PEP 249)](https://peps.python.org/pep-0249/). It is easy to integrate `taospy` with many third-party tools, such as [SQLAlchemy](https://www.sqlalchemy.org/) and [pandas](https://pandas.pydata.org/).
The connection to the server directly using the native interface provided by the client driver is referred to hereinafter as a "native connection"; the connection to the server using the REST interface provided by taosAdapter is referred to hereinafter as a "REST connection". ". The connection to the server directly using the native interface provided by the client driver is referred to hereinafter as a "native connection"; the connection to the server using the REST interface provided by taosAdapter is referred to hereinafter as a "REST connection".
The source code for the Python connector is hosted on [GitHub](https://github.com/taosdata/taos-connector-python). The source code for the Python connector is hosted on [GitHub](https://github.com/taosdata/taos-connector-python).
...@@ -22,33 +22,34 @@ The source code for the Python connector is hosted on [GitHub](https://github.co ...@@ -22,33 +22,34 @@ The source code for the Python connector is hosted on [GitHub](https://github.co
## Version selection ## Version selection
We recommend using the latest version of `taospy`, regardless of the version of TDengine used. We recommend using the latest version of `taospy`, regardless what the version of TDengine is.
## Supported features ## Supported features
- Native connections support all the core features of TDeingine, including connection management, SQL execution, parameter binding, subscriptions, and schemaless writing. - Native connections support all the core features of TDeingine, including connection management, SQL execution, bind interface, subscriptions, and schemaless writing.
- REST connections support features such as connection management and SQL execution. (SQL execution allows you to: manage databases, tables, and supertables, write data, query data, create continuous queries, etc.). - REST connections support features such as connection management and SQL execution. (SQL execution allows you to: manage databases, tables, and supertables, write data, query data, create continuous queries, etc.).
## Installation ## Installation
### Preparation ### Preparation
1. Install Python. Python >= 3.6 is recommended. If Python is not available on your system, refer to the [Python BeginnersGuide](https://wiki.python.org/moin/BeginnersGuide/Download) to install it. 2. 1. Install Python. Python >= 3.6 is recommended. If Python is not available on your system, refer to the [Python BeginnersGuide](https://wiki.python.org/moin/BeginnersGuide/Download) to install it.
Install [pip](https://pypi.org/project/pip/). In most cases, the Python installer comes with the pip utility. If not, please refer to [pip docuemntation](https://pip.pypa.io/en/stable/installation/) to install it. 2. Install [pip](https://pypi.org/project/pip/). In most cases, the Python installer comes with the pip utility. If not, please refer to [pip docuemntation](https://pip.pypa.io/en/stable/installation/) to install it.
If you use a native connection, you will also need to [install the client driver](../#install client driver). The client software contains the TDengine client dynamic link library (libtaos.so or taos.dll) and the TDengine CLI.
### Install using pip If you use a native connection, you will also need to [Install Client Driver](/reference/connector#Install-Client-Driver). The client install package includes the TDengine client dynamic link library (`libtaos.so` or `taos.dll`) and the TDengine CLI.
### Install via pip
#### Uninstalling an older version #### Uninstalling an older version
If you have previously installed an older version of the Python Connector, please uninstall it beforehand. If you have installed an older version of the Python Connector, please uninstall it beforehand.
``` ```
pip3 uninstall taos taospy pip3 uninstall taos taospy
``` ```
:::note :::note
Earlier TDengine client software includes the Python connector. If the Python connector is installed from the client software's installation directory, the corresponding Python package name is `taos`. So the above uninstall command includes `taos`, and it doesn't matter if it doesn't exist. Earlier TDengine client software includes the Python connector. If the Python connector is installed from the client package's installation directory, the corresponding Python package name is `taos`. So the above uninstall command includes `taos`, and it doesn't matter if it doesn't exist.
::: :::
...@@ -57,13 +58,13 @@ Earlier TDengine client software includes the Python connector. If the Python co ...@@ -57,13 +58,13 @@ Earlier TDengine client software includes the Python connector. If the Python co
<Tabs> <Tabs>
<TabItem label="Install from PyPI" value="pypi"> <TabItem label="Install from PyPI" value="pypi">
Install the latest version of Install the latest version of:
``` ```
pip3 install taospy pip3 install taospy
``` ```
You can also specify a specific version to install. You can also specify a specific version to install:
``` ```
pip3 install taospy==2.3.0 pip3 install taospy==2.3.0
...@@ -84,7 +85,7 @@ pip3 install git+https://github.com/taosdata/taos-connector-python.git ...@@ -84,7 +85,7 @@ pip3 install git+https://github.com/taosdata/taos-connector-python.git
<Tabs groupId="connect" default="native"> <Tabs groupId="connect" default="native">
<TabItem value="native" label="native connection"> <TabItem value="native" label="native connection">
For native connections, you need to verify that both the client driver and the Python connector itself are installed correctly. The client driver and Python connector have been installed properly if you can successfully import the `taos` module. In the Python Interactive Shell, you can type. For native connection, you need to verify that both the client driver and the Python connector itself are installed correctly. The client driver and Python connector have been installed properly if you can successfully import the `taos` module. In the Python Interactive Shell, you can type.
```python ```python
import taos import taos
...@@ -93,7 +94,7 @@ import taos ...@@ -93,7 +94,7 @@ import taos
</TabItem> </TabItem>
<TabItem value="rest" label="REST connection"> <TabItem value="rest" label="REST connection">
For REST connections, verifying that the ``taosrest`'' module can be imported successfully can be done in the Python Interactive Shell by typing. For REST connections, verifying that the `taosrest` module can be imported successfully can be done in the Python Interactive Shell by typing.
```python ```python
import taosrest import taosrest
...@@ -109,7 +110,6 @@ If you have multiple versions of Python on your system, you may have various `pi ...@@ -109,7 +110,6 @@ If you have multiple versions of Python on your system, you may have various `pi
C:\> pip3 install taospy C:\> pip3 install taospy
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: taospy in c:\users\username\appdata\local\programs\python\python310\lib\site-packages (2.3.0) Requirement already satisfied: taospy in c:\users\username\appdata\local\programs\python\python310\lib\site-packages (2.3.0)
ðŸ™'ðŸ™'
::: :::
...@@ -122,13 +122,13 @@ Before establishing a connection with the connector, we recommend testing the co ...@@ -122,13 +122,13 @@ Before establishing a connection with the connector, we recommend testing the co
<Tabs> <Tabs>
<TabItem value="native" label="native connection"> <TabItem value="native" label="native connection">
Ensure that the TDengine cluster is up and that the FQDN of the machines in the cluster (the FQDN defaults to hostname if you are starting a standalone version) can be resolved locally, by testing with the ping command. Ensure that the TDengine instance is up and that the FQDN of the machines in the cluster (the FQDN defaults to hostname if you are starting a standalone version) can be resolved locally, by testing with the `ping` command.
``` ```
ping <FQDN> ping <FQDN>
``` ```
Then test if the cluster can be appropriately connected with TDengine CLI: ``` ping <FQDN>``` Then test if the cluster can be appropriately connected with TDengine CLI:
``` ```
taos -h <FQDN> -p <PORT> taos -h <FQDN> -p <PORT>
...@@ -145,7 +145,7 @@ For REST connections and making sure the cluster is up, make sure the taosAdapte ...@@ -145,7 +145,7 @@ For REST connections and making sure the cluster is up, make sure the taosAdapte
curl -u root:taosdata http://<FQDN>:<PORT>/rest/sql -d "select server_version()" curl -u root:taosdata http://<FQDN>:<PORT>/rest/sql -d "select server_version()"
``` ```
The FQDN above is the FQDN of the machine running taosAdapter, PORT is the port taosAdapter listening, default is 6041. The FQDN above is the FQDN of the machine running taosAdapter, PORT is the port taosAdapter listening, default is `6041`.
If the test is successful, it will output the server version information, e.g. If the test is successful, it will output the server version information, e.g.
```json ```json
...@@ -172,7 +172,7 @@ The following example code assumes that TDengine is installed locally and that t ...@@ -172,7 +172,7 @@ The following example code assumes that TDengine is installed locally and that t
{{#include docs-examples/python/connect_native_reference.py}} {{#include docs-examples/python/connect_native_reference.py}}
``` ```
All arguments of the ``connect`` function are optional keyword arguments. The following are the connection parameters specified. All arguments of the `connect()` function are optional keyword arguments. The following are the connection parameters specified.
- `host` : The FQDN of the node to connect to. There is no default value. If this parameter is not provided, the firstEP in the client configuration file will be connected. - `host` : The FQDN of the node to connect to. There is no default value. If this parameter is not provided, the firstEP in the client configuration file will be connected.
- `user` : The TDengine user name. The default value is `root`. - `user` : The TDengine user name. The default value is `root`.
...@@ -182,11 +182,11 @@ All arguments of the ``connect`` function are optional keyword arguments. The fo ...@@ -182,11 +182,11 @@ All arguments of the ``connect`` function are optional keyword arguments. The fo
- `timezone` : The timezone used to convert the TIMESTAMP data in the query results to python `datetime` objects. The default is the local timezone. - `timezone` : The timezone used to convert the TIMESTAMP data in the query results to python `datetime` objects. The default is the local timezone.
:::warning :::warning
`config` and `timezone` are both process-level configurations. we recommend that all connections made by a process use the same parameter values. Otherwise, unpredictable errors may occur. `config` and `timezone` are both process-level configurations. We recommend that all connections made by a process use the same parameter values. Otherwise, unpredictable errors may occur.
::: :::
:::tip :::tip
The `connect` function returns a `taos.TaosConnection` instance. In client-side multi-threaded scenarios, we recommend that each thread request a separate connection instance rather than sharing a connection between multiple threads. The `connect()` function returns a `taos.TaosConnection` instance. In client-side multi-threaded scenarios, we recommend that each thread request a separate connection instance rather than sharing a connection between multiple threads.
::: :::
...@@ -197,7 +197,7 @@ The `connect` function returns a `taos.TaosConnection` instance. In client-side ...@@ -197,7 +197,7 @@ The `connect` function returns a `taos.TaosConnection` instance. In client-side
{{#include docs-examples/python/connect_rest_examples.py:connect}} {{#include docs-examples/python/connect_rest_examples.py:connect}}
``` ```
All arguments to the `connect` function are optional keyword arguments. The following are the connection parameters specified. All arguments to the `connect()` function are optional keyword arguments. The following are the connection parameters specified.
- `host`: The host to connect to. The default is localhost. - `host`: The host to connect to. The default is localhost.
- `user`: TDenigne user name. The default is `root`. - `user`: TDenigne user name. The default is `root`.
...@@ -205,23 +205,19 @@ All arguments to the `connect` function are optional keyword arguments. The foll ...@@ -205,23 +205,19 @@ All arguments to the `connect` function are optional keyword arguments. The foll
- `port`: The port on which the taosAdapter REST service listens. Default is 6041. - `port`: The port on which the taosAdapter REST service listens. Default is 6041.
- `timeout`: HTTP request timeout in seconds. The default is `socket._GLOBAL_DEFAULT_TIMEOUT`. Usually, no configuration is needed. - `timeout`: HTTP request timeout in seconds. The default is `socket._GLOBAL_DEFAULT_TIMEOUT`. Usually, no configuration is needed.
:::note
:::
</TabItem> </TabItem>
</Tabs> </Tabs>
## Sample program ## Sample program
### Basic use ### Basic Usage
<Tabs default="native" groupId="connect"> <Tabs default="native" groupId="connect">
<TabItem value="native" label="native connection"> <TabItem value="native" label="native connection">
Use of the ##### TaosConnection class ##### TaosConnection class
The `TaosConnection` class contains both an implementation of the PEP249 Connection interface (e.g., the `cursor` method and the `close` method) and many extensions (e.g., the `execute`, `query`, `schemaless_insert`, and `subscribe` methods). . The `TaosConnection` class contains both an implementation of the PEP249 Connection interface (e.g., the `cursor()` method and the `close()` method) and many extensions (e.g., the `execute()`, `query()`, `schemaless_insert()`, and `subscribe()` methods).
```python title="execute method" ```python title="execute method"
{{#include docs-examples/python/connection_usage_native_reference.py:insert}} {{#include docs-examples/python/connection_usage_native_reference.py:insert}}
...@@ -232,12 +228,12 @@ The `TaosConnection` class contains both an implementation of the PEP249 Connect ...@@ -232,12 +228,12 @@ The `TaosConnection` class contains both an implementation of the PEP249 Connect
``` ```
:::tip :::tip
The queried results can only be fetched once. For example, only one of `featch_all` and `fetch_all_into_dict` can be used in the example above. Repeated fetches will result in an empty list. The queried results can only be fetched once. For example, only one of `fetch_all()` and `fetch_all_into_dict()` can be used in the example above. Repeated fetches will result in an empty list.
::: :::
##### Use of TaosResult class ##### Use of TaosResult class
In the above example of using the `TaosConnection` class, we have shown two ways to get the result of a query: `featch_all` and `fetch_all_into_dict`. In addition, `TaosResult` also provides methods to iterate through the result set by rows (`rows_iter`) or by data blocks (`blocks_iter`). Using these two methods will be more efficient in scenarios where the query has a large amount of data. In the above example of using the `TaosConnection` class, we have shown two ways to get the result of a query: `fetch_all()` and `fetch_all_into_dict()`. In addition, `TaosResult` also provides methods to iterate through the result set by rows (`rows_iter`) or by data blocks (`blocks_iter`). Using these two methods will be more efficient in scenarios where the query has a large amount of data.
```python title="blocks_iter method" ```python title="blocks_iter method"
{{#include docs-examples/python/result_set_examples.py}} {{#include docs-examples/python/result_set_examples.py}}
...@@ -271,7 +267,7 @@ The ``TaosRestCursor`` class is an implementation of the PEP249 Cursor interface ...@@ -271,7 +267,7 @@ The ``TaosRestCursor`` class is an implementation of the PEP249 Cursor interface
##### Use of the RestClient class ##### Use of the RestClient class
The `RestClient` class is a direct wrapper for the [REST API](/reference/rest-api). It contains only a ``sql()` method for executing arbitrary SQL statements and returning the result. The `RestClient` class is a direct wrapper for the [REST API](/reference/rest-api). It contains only a `sql()` method for executing arbitrary SQL statements and returning the result.
```python title="Use of RestClient" ```python title="Use of RestClient"
{{#include docs-examples/python/rest_client_example.py}} {{#include docs-examples/python/rest_client_example.py}}
......
...@@ -15,9 +15,9 @@ import RustOpenTSDBTelnet from "../../04-develop/03-insert-data/_rust_opts_telne ...@@ -15,9 +15,9 @@ import RustOpenTSDBTelnet from "../../04-develop/03-insert-data/_rust_opts_telne
import RustOpenTSDBJson from "../../04-develop/03-insert-data/_rust_opts_json.mdx" import RustOpenTSDBJson from "../../04-develop/03-insert-data/_rust_opts_json.mdx"
import RustQuery from "../../04-develop/04-query-data/_rust.mdx" import RustQuery from "../../04-develop/04-query-data/_rust.mdx"
`libtaos` is the official Rust language connector for TDengine, through which Rust developers can develop applications that access the TDengine database. `libtaos` is the official Rust language connector for TDengine. Rust developers can develop applications to access the TDengine instance data.
`libtaos` provides two ways to establish connections. One is the **Native Connection**, which connects to TDengine runtime instances via the TDengine client driver (taosc). The other is **REST connection**, which connects to TDengine runtime instances via taosAdapter's REST interface. The REST connection supports any platform, but the native connection supports all platforms on which the TDengine client can run. `libtaos` provides two ways to establish connections. One is the **Native Connection**, which connects to TDengine instances via the TDengine client driver (taosc). The other is **REST connection**, which connects to TDengine instances via taosAdapter's REST interface.
The source code for `libtaos` is hosted on [GitHub](https://github.com/taosdata/libtaos-rs). The source code for `libtaos` is hosted on [GitHub](https://github.com/taosdata/libtaos-rs).
...@@ -28,7 +28,7 @@ REST connections are supported on all platforms that can run Rust. ...@@ -28,7 +28,7 @@ REST connections are supported on all platforms that can run Rust.
## Version support ## Version support
Please refer to [version support list](/reference/connector#version support) Please refer to [version support list](/reference/connector#version-support).
The Rust Connector is still under rapid development and is not guaranteed to be backward compatible before 1.0. Recommend to use TDengine version 2.4 or higher to avoid known issues. The Rust Connector is still under rapid development and is not guaranteed to be backward compatible before 1.0. Recommend to use TDengine version 2.4 or higher to avoid known issues.
...@@ -36,7 +36,7 @@ The Rust Connector is still under rapid development and is not guaranteed to be ...@@ -36,7 +36,7 @@ The Rust Connector is still under rapid development and is not guaranteed to be
### Pre-installation ### Pre-installation
* Install the Rust development toolchain * Install the Rust development toolchain
* If using the native connection, please install the TDengine client driver. Please refer to [install client driver](/reference/connector#install client driver) * If using the native connection, please install the TDengine client driver. Please refer to [install client driver](/reference/connector#install-client-driver)
### Adding libtaos dependencies ### Adding libtaos dependencies
...@@ -56,7 +56,7 @@ libtaos = "*" ...@@ -56,7 +56,7 @@ libtaos = "*"
</TabItem </TabItem
<TabItem value="rest" label="REST connection"> <TabItem value="rest" label="REST connection">
Add [libtaos][libtaos] to the ``Cargo.toml`'' file and enable the ``rest`'' feature. Add [libtaos][libtaos] to the `Cargo.toml` file and enable the `rest` feature.
```toml ```toml
[dependencies] [dependencies]
...@@ -180,7 +180,7 @@ async fn demo() -> Result<(), Error> { ...@@ -180,7 +180,7 @@ async fn demo() -> Result<(), Error> {
The [Builder Pattern](https://doc.rust-lang.org/1.0.0/style/ownership/builders.html) constructor pattern is Rust's solution for handling complex data types or optional configuration types. The [libtaos] implementation uses the connection constructor [TaosCfgBuilder] as the entry point for the TDengine Rust connector. The [TaosCfgBuilder] provides optional configuration of servers, ports, databases, usernames, passwords, etc. The [Builder Pattern](https://doc.rust-lang.org/1.0.0/style/ownership/builders.html) constructor pattern is Rust's solution for handling complex data types or optional configuration types. The [libtaos] implementation uses the connection constructor [TaosCfgBuilder] as the entry point for the TDengine Rust connector. The [TaosCfgBuilder] provides optional configuration of servers, ports, databases, usernames, passwords, etc.
Using the ``default()` method, you can construct a [TaosCfg] with default parameters for subsequent connections to the database or establishing connection pools. Using the `default()` method, you can construct a [TaosCfg] with default parameters for subsequent connections to the database or establishing connection pools.
```rust ```rust
let cfg = TaosCfgBuilder::default().build()? ; let cfg = TaosCfgBuilder::default().build()? ;
...@@ -206,7 +206,7 @@ let conn: Taos = cfg.connect(); ...@@ -206,7 +206,7 @@ let conn: Taos = cfg.connect();
### Connection pooling ### Connection pooling
In complex applications, recommand to enable connection pooling. Connection pooling for [libtaos] is implemented using [r2d2]. In complex applications, recommand to enable connection pool. Connection pool for [libtaos] is implemented using [r2d2].
As follows, a connection pool with default parameters can be generated. As follows, a connection pool with default parameters can be generated.
...@@ -226,7 +226,7 @@ You can set the same connection pool parameters using the connection pool's cons ...@@ -226,7 +226,7 @@ You can set the same connection pool parameters using the connection pool's cons
.build(cfg); .build(cfg);
``` ```
In the application code, use ``pool.get()? ` to get a connection object [Taos]. In the application code, use `pool.get()? ` to get a connection object [Taos].
```rust ```rust
let taos = pool.get()? ; let taos = pool.get()? ;
...@@ -234,13 +234,13 @@ let taos = pool.get()? ; ...@@ -234,13 +234,13 @@ let taos = pool.get()? ;
The [Taos] structure is the connection manager in [libtaos] and provides two main APIs. The [Taos] structure is the connection manager in [libtaos] and provides two main APIs.
1. ``exec``: Execute some non-query SQL statements, such as ``CREATE`, ``ALTER`, ``INSERT`, etc. 1. `exec`: Execute some non-query SQL statements, such as `CREATE`, `ALTER`, `INSERT`, etc.
```rust ```rust
taos.exec().await? taos.exec().await?
``` ```
2. ``query``: Execute the query statement and return the [TaosQueryData] object. 2. `query`: Execute the query statement and return the [TaosQueryData] object.
```rust ```rust
let q = taos.query("select * from log.logs").await? let q = taos.query("select * from log.logs").await?
...@@ -277,15 +277,15 @@ Note that Rust asynchronous functions and an asynchronous runtime are required. ...@@ -277,15 +277,15 @@ Note that Rust asynchronous functions and an asynchronous runtime are required.
In addition, this structure is also the entry point for [Parameter Binding](#Parameter Binding Interface) and [Line Protocol Interface](#Line Protocol Interface). Please refer to the specific API descriptions for usage. In addition, this structure is also the entry point for [Parameter Binding](#Parameter Binding Interface) and [Line Protocol Interface](#Line Protocol Interface). Please refer to the specific API descriptions for usage.
### Parameter Binding Interface ### Bind Interface
Similar to the C interface, Rust provides a parameter binding interface. First, create a parameter binding object [Stmt] for a SQL statement from the [Taos] object. Similar to the C interface, Rust provides the bind interface's wraping. First, create a bind object [Stmt] for a SQL command from the [Taos] object.
```rust ```rust
let mut stmt: Stmt = taos.stmt("insert into ? values(? ,?)") ? ; let mut stmt: Stmt = taos.stmt("insert into ? values(? ,?)") ? ;
``` ```
The parameter binding object provides a set of interfaces for implementing parameter binding. The bind object provides a set of interfaces for implementing parameter binding.
##### `.set_tbname(tbname: impl ToCString)` ##### `.set_tbname(tbname: impl ToCString)`
......
...@@ -864,9 +864,9 @@ Query OK, 1 row(s) in set (0.000141s) ...@@ -864,9 +864,9 @@ Query OK, 1 row(s) in set (0.000141s)
请参考:[JDBC example](https://github.com/taosdata/TDengine/tree/develop/examples/JDBC) 请参考:[JDBC example](https://github.com/taosdata/TDengine/tree/develop/examples/JDBC)
## 常见问题 ## 常见问题
* 使用Statement的addBatch和executeBatch来执行“批量写入/更行”,为什么没有带来性能上的提升? * 使用 Statement 的 addBatch() 和 executeBatch() 来执行“批量写入/更新”,为什么没有带来性能上的提升?
**原因**:TDengine的JDBC实现中,通过addBatch方法提交的sql语句,会按照添加的顺序,依次执行,这种方式没有减少与服务端的交互次数,不会带来性能上的提升。 **原因**:TDengine 的 JDBC 实现中,通过 addBatch() 方法提交的sql语句,会按照添加的顺序,依次执行,这种方式没有减少与服务端的交互次数,不会带来性能上的提升。
**解决方法**:1. 在一条insert语句中拼接多个values值;2. 使用多线程的方式并发插入;3. 使用参数绑定的写入方式 **解决方法**:1. 在一条 insert 语句中拼接多个 values 值;2. 使用多线程的方式并发插入;3. 使用参数绑定的写入方式
* java.lang.UnsatisfiedLinkError: no taos in java.library.path * java.lang.UnsatisfiedLinkError: no taos in java.library.path
**原因**:程序没有找到依赖的本地函数库 taos。 **原因**:程序没有找到依赖的本地函数库 taos。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册