_taosSql_implementsGo's `database/sql/driver` interface via cgo. You can use the [`database/sql`](https://golang.org/pkg/database/sql/) interface by simply introducing the driver.
_taosSql_implementsGo's `database/sql/driver` interface via cgo. You can use the [`database/sql`](https://golang.org/pkg/database/sql/) interface by simply introducing the driver.
...
@@ -209,340 +220,902 @@ func main() {
...
@@ -209,340 +220,902 @@ func main() {
</TabItem>
</TabItem>
</Tabs>
</Tabs>
## Usage examples
### Specify the URL and Properties to get the connection
### Write data
#### SQL Write
The Go connector does not support this feature
<GoInsert />
### Priority of configuration parameters
#### InfluxDB line protocol write
The Go connector does not support this feature
<GoInfluxLine />
## Usage examples
#### OpenTSDB Telnet line protocol write
### Create database and tables
<GoOpenTSDBTelnet />
```go
var taosDSN = "root:taosdata@tcp(localhost:6030)/"
taos, err := sql.Open("taosSql", taosDSN)
if err != nil {
log.Fatalln("failed to connect TDengine, err:", err)
}
defer taos.Close()
_, err := taos.Exec("CREATE DATABASE power")
if err != nil {
log.Fatalln("failed to create database, err:", err)
}
_, err = taos.Exec("CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)")
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`.
_, err = db.ExecContext(ctx, "create database if not exists example_taos_sql")
if err != nil {
panic(err)
}
```
You can also put the db name in the DSN by changing `root:taosdata@http(localhost:6041)/` to `root:taosdata@http(localhost:6041)/test`. 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.
REST does not support parameter binding related interface. It is recommended to use `db.Exec` and `db.Query`.
2. error `[0x217] Database not specified or available` after executing other statements with `use db` statement
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.
3. 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.
4. `readBufferSize` parameter has no significant effect after being increased
Increasing `readBufferSize` will reduce the number of `syscall` calls when fetching results. If the query result is smaller, modifying this parameter will not improve performance 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 based on the actual situation to achieve the best query performance.
5. `disableCompression` parameter is set to `false` when the query efficiency is reduced
When set `disableCompression` parameter to `false`, the query result will be compressed by `gzip` and then transmitted, so you have to decompress the data by `gzip` after getting it.
REST does not support parameter binding related interface. It is recommended to use `db.Exec` and `db.Query`.
Parameterbindmultiplerowsofdata.
2. error `[0x217] Database not specified or available` after executing other statements with `use db` statement
*`func(s*Stmt)AddBatch()error`
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.
Addtoaparameter-boundbatch.
3. use `taosSql` without error but use `taosRestful` with error `[0x217] Database not specified or available`
*`func(s*Stmt)Exec()error`
Because the REST interface is stateless, using the `use db` statement will not take effect. See the usage restrictions section above.
Executeaparameterbinding.
4. `readBufferSize` parameter has no significant effect after being increased
*`func(s*Stmt)GetAffectedRows()int`
Increasing `readBufferSize` will reduce the number of `syscall` calls when fetching results. If the query result is smaller, modifying this parameter will not improve performance 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 based on the actual situation to achieve the best query performance.
5. `disableCompression` parameter is set to `false` when the query efficiency is reduced
*`func(s*Stmt)Close()error`
When set `disableCompression` parameter to `false`, the query result will be compressed by `gzip` and then transmitted, so you have to decompress the data by `gzip` after getting it.