• 应用驱动安装请参考。

    使用 Go 连接器的示例代码请参考 https://github.com/taosdata/TDengine/tree/develop/tests/examples/go 以及。

    建议使用Go版本1.13或以上,并开启模块支持:

    常用API

    • sql.Open(DRIVER_NAME string, dataSourceName string) *DB

      该API用来打开DB,返回一个类型为*DB的对象,一般情况下,DRIVER_NAME设置为字符串taosSql, dataSourceName设置为字符串user:password@/tcp(host:port)/dbname,如果客户想要用多个goroutine并发访问TDengine, 那么需要在各个goroutine中分别创建一个sql.Open对象并用之访问TDengine

      注意: 该API成功创建的时候,并没有做权限等检查,只有在真正执行Query或者Exec的时候才能真正的去创建连接,并同时检查user/password/host/port是不是合法。 另外,由于整个驱动程序大部分实现都下沉到taosSql所依赖的libtaos中。所以,sql.Open本身特别轻量。

    • sql.Open内置的方法,用来执行非查询相关SQL

    • func (db *DB) Prepare(query string) (*Stmt, error)

      sql.Open内置的方法,Prepare creates a prepared statement for later queries or executions.

    • sql.Open内置的方法,executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.

    • func (s *Stmt) Query(args ...interface{}) (*Rows, error)

      sql.Open内置的方法,Query executes a prepared query statement with the given arguments and returns the query results as a *Rows.