Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
de5047f4
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
de5047f4
编写于
12月 02, 2019
作者:
S
slguan
提交者:
GitHub
12月 02, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #821 from taosdata/feature/lihui
Feature/lihui
上级
faca8084
d468cc5e
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
109 addition
and
15 deletion
+109
-15
documentation/webdocs/markdowndocs/connector-ch.md
documentation/webdocs/markdowndocs/connector-ch.md
+52
-3
packaging/deb/makedeb.sh
packaging/deb/makedeb.sh
+1
-1
packaging/rpm/makerpm.sh
packaging/rpm/makerpm.sh
+24
-3
packaging/rpm/tdengine.spec
packaging/rpm/tdengine.spec
+1
-1
packaging/tools/makeclient.sh
packaging/tools/makeclient.sh
+2
-2
packaging/tools/makepkg.sh
packaging/tools/makepkg.sh
+2
-2
src/kit/shell/src/shellEngine.c
src/kit/shell/src/shellEngine.c
+12
-2
src/kit/shell/src/shellLinux.c
src/kit/shell/src/shellLinux.c
+9
-0
src/system/detail/src/dnodeService.c
src/system/detail/src/dnodeService.c
+6
-1
未找到文件。
documentation/webdocs/markdowndocs/connector-ch.md
浏览文件 @
de5047f4
...
...
@@ -392,15 +392,64 @@ curl -u username:password -d '<SQL>' <ip>:<PORT>/rest/sql
## Go Connector
TDengine提供了GO驱动程序“taosSql”包。taosSql驱动包是基于GO的“database/sql/driver”接口的实现。用户可在安装后的/usr/local/taos/connector/go目录获得GO的客户端驱动程序。用户需将驱动包/usr/local/taos/connector/go/src/taosSql目录拷贝到应用程序工程的src目录下。然后在应用程序中导入驱动包,就可以使用“database/sql”中定义的接口访问TDengine:
#### 安装TDengine
Go的链接器使用了到了 libtaos.so 和taos.h,因此,在使用Go连接器之前,需要在程序运行的机器上安装TDengine以获得相关的驱动文件。
#### Go语言引入package
TDengine提供了GO驱动程序“taosSql”包。taosSql驱动包是基于GO的“database/sql/driver”接口的实现。用户可以通过
`go get`
命令来获取驱动包。
```
sh
go get github.com/taosdata/TDengine/src/connector/go/src/taosSql
```
然后在应用程序中导入驱动包,就可以使用“database/sql”中定义的接口访问TDengine:
```
Go
import (
"database/sql"
_ "taosSql"
_ "
github.com/taosdata/TDengine/src/connector/go/src/
taosSql"
)
```
taosSql驱动包内采用cgo模式,调用了TDengine的C/C++同步接口,与TDengine进行交互,因此,在数据库操作执行完成之前,客户端应用将处于阻塞状态。单个数据库连接,在同一时刻只能有一个线程调用API。客户应用可以建立多个连接,进行多线程的数据写入或查询处理。
更多使用的细节,请参考下载目录中的示例源码。
#### Go语言使用参考
在Go程序中使用TDengine写入方法大致可以分为以下几步
1.
打开TDengine数据库链接
首先需要调用sql包中的Open方法,打开数据库,并获得db对象
```
go
db
,
err
:=
sql
.
Open
(
taosDriverName
,
dbuser
+
":"
+
dbpassword
+
"@/tcp("
+
daemonUrl
+
")/"
+
dbname
)
if
err
!=
nil
{
log
.
Fatalf
(
"Open database error: %s
\n
"
,
err
)
}
defer
db
.
Close
()
```
其中参数为
-
taosDataname: 涛思数据库的名称,其值为字符串"taosSql"
-
dbuser和dbpassword: 链接TDengine的用户名和密码,缺省为root和taosdata,类型为字符串
-
daemonUrl: 为TDengine的地址,其形式为
`ip address:port`
形式,port填写缺省值0即可。例如:"116.118.24.71:0"
-
dbname:TDengine中的database名称,通过
`create database`
创建的数据库。如果为空则在后续的写入和查询操作必须通过”数据库名.超级表名或表名“的方式指定数据库名
2.
创建数据库
打开TDengine数据库连接后,首选需要创建数据库。基本用法和直接在TDengine客户端shell下一样,通过create database + 数据库名的方法来创建。
```
go
db
,
err
:=
sql
.
Open
(
taosDriverName
,
dbuser
+
":"
+
dbpassword
+
"@/tcp("
+
daemonUrl
+
")/"
)
if
err
!=
nil
{
log
.
Fatalf
(
"Open database error: %s
\n
"
,
err
)
}
defer
db
.
Close
()
//准备创建数据库语句
sqlcmd
:=
fmt
.
Sprintf
(
"create database if not exists %s"
,
dbname
)
//执行语句并检查错误
_
,
err
=
db
.
Exec
(
sqlcmd
)
if
err
!=
nil
{
log
.
Fatalf
(
"Create database error: %s
\n
"
,
err
)
}
```
3.
创建表、写入和查询数据
在创建好了数据库后,就可以开始创建表和写入查询数据了。这些操作的基本思路都是首先组装SQL语句,然后调用db.Exec执行,并检查错误信息和执行相应的处理。可以参考上面的样例代码
packaging/deb/makedeb.sh
浏览文件 @
de5047f4
...
...
@@ -63,7 +63,7 @@ debver="Version: "$tdengine_ver
sed
-i
"2c
$debver
"
${
pkg_dir
}
/DEBIAN/control
#get taos version, then set deb name
debname
=
"
td
engine-"
${
tdengine_ver
}
".deb"
debname
=
"
TD
engine-"
${
tdengine_ver
}
".deb"
# make deb package
dpkg
-b
${
pkg_dir
}
$debname
...
...
packaging/rpm/makerpm.sh
浏览文件 @
de5047f4
...
...
@@ -2,6 +2,9 @@
#
# Generate rpm package for centos
#set -e
#set -x
#curr_dir=$(pwd)
compile_dir
=
$1
output_dir
=
$2
...
...
@@ -24,8 +27,25 @@ if command -v sudo > /dev/null; then
csudo
=
"sudo"
fi
function
cp_rpm_package
()
{
local
cur_dir
cd
$1
cur_dir
=
$(
pwd
)
for
dirlist
in
$(
ls
${
cur_dir
}
)
;
do
if
test
-d
${
dirlist
}
;
then
cd
${
dirlist
}
cp_rpm_package
${
cur_dir
}
/
${
dirlist
}
cd
..
fi
if
test
-e
${
dirlist
}
;
then
cp
${
cur_dir
}
/
${
dirlist
}
${
output_dir
}
/TDengine-
${
tdengine_ver
}
.rpm
fi
done
}
if
[
-d
${
pkg_dir
}
]
;
then
${
csudo
}
rm
-rf
${
pkg_dir
}
${
csudo
}
rm
-rf
${
pkg_dir
}
fi
${
csudo
}
mkdir
-p
${
pkg_dir
}
cd
${
pkg_dir
}
...
...
@@ -35,7 +55,8 @@ ${csudo} mkdir -p BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
${
csudo
}
rpmbuild
--define
=
"_version
${
tdengine_ver
}
"
--define
=
"_topdir
${
pkg_dir
}
"
--define
=
"_compiledir
${
compile_dir
}
"
-bb
${
spec_file
}
# copy rpm package to output_dir, then clean temp dir
#echo "rmpbuild end, cur_dir: $(pwd) "
${
csudo
}
cp
-rf
RPMS/
*
${
output_dir
}
#${csudo} cp -rf RPMS/* ${output_dir}
cp_rpm_package
${
pkg_dir
}
/RPMS
cd
..
${
csudo
}
rm
-rf
${
pkg_dir
}
packaging/rpm/tdengine.spec
浏览文件 @
de5047f4
...
...
@@ -2,7 +2,7 @@
%define cfg_install_dir /etc/taos
%define __strip /bin/true
Name:
td
engine
Name:
TD
engine
Version: %{_version}
Release: 3%{?dist}
Summary: tdengine from taosdata
...
...
packaging/tools/makeclient.sh
浏览文件 @
de5047f4
...
...
@@ -19,8 +19,8 @@ code_dir="${top_dir}/src"
release_dir
=
"
${
top_dir
}
/release"
community_dir
=
"
${
script_dir
}
/../../../community/src"
package_name
=
'linux'
install_dir
=
"
${
release_dir
}
/
taos-client-
${
version
}
-
${
package_name
}
-
$(
echo
${
build_time
}
|
tr
': '
-
)
"
#
package_name='linux'
install_dir
=
"
${
release_dir
}
/
TDengine-client-
${
version
}
"
# Directories and files.
bin_files
=
"
${
build_dir
}
/bin/taos
${
build_dir
}
/bin/taosdump
${
script_dir
}
/remove_client.sh"
...
...
packaging/tools/makepkg.sh
浏览文件 @
de5047f4
...
...
@@ -16,8 +16,8 @@ build_dir="${compile_dir}/build"
code_dir
=
"
${
top_dir
}
/src"
release_dir
=
"
${
top_dir
}
/release"
package_name
=
'linux'
install_dir
=
"
${
release_dir
}
/
taos-
${
version
}
-
${
package_name
}
-
$(
echo
${
build_time
}
|
tr
': '
-
)
"
#
package_name='linux'
install_dir
=
"
${
release_dir
}
/
TDengine-
${
version
}
"
# Directories and files.
bin_files
=
"
${
build_dir
}
/bin/taosd
${
build_dir
}
/bin/taos
${
build_dir
}
/bin/taosdemo
${
build_dir
}
/bin/taosdump
${
script_dir
}
/remove.sh"
...
...
src/kit/shell/src/shellEngine.c
浏览文件 @
de5047f4
...
...
@@ -29,9 +29,19 @@
#elif defined(DARWIN)
char
CLIENT_VERSION
[]
=
"Welcome to the TDengine shell from mac, client version:%s "
;
#else
char
CLIENT_VERSION
[]
=
"Welcome to the TDengine shell from linux, client version:%s "
;
#ifdef CLUSTER
char
CLIENT_VERSION
[]
=
"Welcome to the TDengine shell from linux, enterprise client version:%s "
;
#else
char
CLIENT_VERSION
[]
=
"Welcome to the TDengine shell from linux, community client version:%s "
;
#endif
#endif
char
SERVER_VERSION
[]
=
"server version:%s
\n
Copyright (c) 2017 by TAOS Data, Inc. All rights reserved.
\n\n
"
;
#ifdef CLUSTER
char
SERVER_VERSION
[]
=
"enterprise server version:%s
\n
Copyright (c) 2017 by TAOS Data, Inc. All rights reserved.
\n\n
"
;
#else
char
SERVER_VERSION
[]
=
"community server version:%s
\n
Copyright (c) 2017 by TAOS Data, Inc. All rights reserved.
\n\n
"
;
#endif
char
PROMPT_HEADER
[]
=
"taos> "
;
char
CONTINUE_PROMPT
[]
=
" -> "
;
int
prompt_size
=
6
;
...
...
src/kit/shell/src/shellLinux.c
浏览文件 @
de5047f4
...
...
@@ -105,6 +105,15 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
static
struct
argp
argp
=
{
options
,
parse_opt
,
args_doc
,
doc
};
void
shellParseArgument
(
int
argc
,
char
*
argv
[],
struct
arguments
*
arguments
)
{
char
verType
[
32
]
=
{
0
};
#ifdef CLUSTER
sprintf
(
verType
,
"enterprise version: %s
\n
"
,
version
);
#else
sprintf
(
verType
,
"community version: %s
\n
"
,
version
);
#endif
argp_program_version
=
verType
;
argp_parse
(
&
argp
,
argc
,
argv
,
0
,
0
,
arguments
);
if
(
arguments
->
abort
)
{
error
(
10
,
0
,
"ABORTED"
);
...
...
src/system/detail/src/dnodeService.c
浏览文件 @
de5047f4
...
...
@@ -55,7 +55,12 @@ int main(int argc, char *argv[]) {
exit
(
EXIT_FAILURE
);
}
}
else
if
(
strcmp
(
argv
[
i
],
"-V"
)
==
0
)
{
printf
(
"version: %s compatible_version: %s
\n
"
,
version
,
compatible_version
);
#ifdef CLUSTER
printf
(
"enterprise version: %s compatible_version: %s
\n
"
,
version
,
compatible_version
);
#else
printf
(
"community version: %s compatible_version: %s
\n
"
,
version
,
compatible_version
);
#endif
printf
(
"gitinfo: %s
\n
"
,
gitinfo
);
printf
(
"buildinfo: %s
\n
"
,
buildinfo
);
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录