Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1741d9ab
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
1741d9ab
编写于
7月 28, 2020
作者:
L
liu0x54
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-1001] adapt nodejs connector to TD 2.0
上级
a0ca29dc
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
125 addition
and
70 deletion
+125
-70
src/connector/nodejs/nodetaos/cinterface.js
src/connector/nodejs/nodetaos/cinterface.js
+92
-48
src/connector/nodejs/nodetaos/connection.js
src/connector/nodejs/nodetaos/connection.js
+3
-1
src/connector/nodejs/nodetaos/cursor.js
src/connector/nodejs/nodetaos/cursor.js
+18
-12
src/connector/nodejs/package-lock.json
src/connector/nodejs/package-lock.json
+2
-2
src/connector/nodejs/package.json
src/connector/nodejs/package.json
+2
-2
src/connector/nodejs/test/test.js
src/connector/nodejs/test/test.js
+8
-5
未找到文件。
src/connector/nodejs/nodetaos/cinterface.js
浏览文件 @
1741d9ab
...
@@ -10,6 +10,7 @@ const Struct = require('ref-struct');
...
@@ -10,6 +10,7 @@ const Struct = require('ref-struct');
const
FieldTypes
=
require
(
'
./constants
'
);
const
FieldTypes
=
require
(
'
./constants
'
);
const
errors
=
require
(
'
./error
'
);
const
errors
=
require
(
'
./error
'
);
const
TaosObjects
=
require
(
'
./taosobjects
'
);
const
TaosObjects
=
require
(
'
./taosobjects
'
);
const
{
NULL_POINTER
}
=
require
(
'
ref
'
);
module
.
exports
=
CTaosInterface
;
module
.
exports
=
CTaosInterface
;
...
@@ -25,7 +26,7 @@ function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, micro=false
...
@@ -25,7 +26,7 @@ function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, micro=false
if
(
micro
==
true
)
{
if
(
micro
==
true
)
{
timestampConverter
=
convertMicrosecondsToDatetime
;
timestampConverter
=
convertMicrosecondsToDatetime
;
}
}
data
=
ref
.
reinterpret
(
data
.
deref
()
,
nbytes
*
num_of_rows
,
offset
);
data
=
ref
.
reinterpret
(
data
,
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
res
=
[];
let
currOffset
=
0
;
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
while
(
currOffset
<
data
.
length
)
{
...
@@ -43,7 +44,7 @@ function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, micro=false
...
@@ -43,7 +44,7 @@ function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, micro=false
return
res
;
return
res
;
}
}
function
convertBool
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
function
convertBool
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
data
=
ref
.
reinterpret
(
data
.
deref
()
,
nbytes
*
num_of_rows
,
offset
);
data
=
ref
.
reinterpret
(
data
,
nbytes
*
num_of_rows
,
offset
);
let
res
=
new
Array
(
data
.
length
);
let
res
=
new
Array
(
data
.
length
);
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
if
(
data
[
i
]
==
0
)
{
if
(
data
[
i
]
==
0
)
{
...
@@ -59,7 +60,7 @@ function convertBool(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
...
@@ -59,7 +60,7 @@ function convertBool(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
return
res
;
return
res
;
}
}
function
convertTinyint
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
function
convertTinyint
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
data
=
ref
.
reinterpret
(
data
.
deref
()
,
nbytes
*
num_of_rows
,
offset
);
data
=
ref
.
reinterpret
(
data
,
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
res
=
[];
let
currOffset
=
0
;
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
while
(
currOffset
<
data
.
length
)
{
...
@@ -70,7 +71,7 @@ function convertTinyint(data, num_of_rows, nbytes = 0, offset = 0, micro=false)
...
@@ -70,7 +71,7 @@ function convertTinyint(data, num_of_rows, nbytes = 0, offset = 0, micro=false)
return
res
;
return
res
;
}
}
function
convertSmallint
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
function
convertSmallint
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
data
=
ref
.
reinterpret
(
data
.
deref
()
,
nbytes
*
num_of_rows
,
offset
);
data
=
ref
.
reinterpret
(
data
,
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
res
=
[];
let
currOffset
=
0
;
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
while
(
currOffset
<
data
.
length
)
{
...
@@ -81,7 +82,7 @@ function convertSmallint(data, num_of_rows, nbytes = 0, offset = 0, micro=false)
...
@@ -81,7 +82,7 @@ function convertSmallint(data, num_of_rows, nbytes = 0, offset = 0, micro=false)
return
res
;
return
res
;
}
}
function
convertInt
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
function
convertInt
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
data
=
ref
.
reinterpret
(
data
.
deref
()
,
nbytes
*
num_of_rows
,
offset
);
data
=
ref
.
reinterpret
(
data
,
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
res
=
[];
let
currOffset
=
0
;
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
while
(
currOffset
<
data
.
length
)
{
...
@@ -92,18 +93,18 @@ function convertInt(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
...
@@ -92,18 +93,18 @@ function convertInt(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
return
res
;
return
res
;
}
}
function
convertBigint
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
function
convertBigint
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
data
=
ref
.
reinterpret
(
data
.
deref
()
,
nbytes
*
num_of_rows
,
offset
);
data
=
ref
.
reinterpret
(
data
,
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
res
=
[];
let
currOffset
=
0
;
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
while
(
currOffset
<
data
.
length
)
{
let
d
=
data
.
readInt64LE
(
currOffset
);
let
d
=
data
.
readInt64LE
(
currOffset
);
res
.
push
(
d
==
FieldTypes
.
C_BIGINT_NULL
?
null
:
BigInt
(
d
)
);
res
.
push
(
d
==
FieldTypes
.
C_BIGINT_NULL
?
null
:
d
);
currOffset
+=
nbytes
;
currOffset
+=
nbytes
;
}
}
return
res
;
return
res
;
}
}
function
convertFloat
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
function
convertFloat
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
data
=
ref
.
reinterpret
(
data
.
deref
()
,
nbytes
*
num_of_rows
,
offset
);
data
=
ref
.
reinterpret
(
data
,
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
res
=
[];
let
currOffset
=
0
;
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
while
(
currOffset
<
data
.
length
)
{
...
@@ -114,7 +115,7 @@ function convertFloat(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
...
@@ -114,7 +115,7 @@ function convertFloat(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
return
res
;
return
res
;
}
}
function
convertDouble
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
function
convertDouble
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
data
=
ref
.
reinterpret
(
data
.
deref
()
,
nbytes
*
num_of_rows
,
offset
);
data
=
ref
.
reinterpret
(
data
,
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
res
=
[];
let
currOffset
=
0
;
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
while
(
currOffset
<
data
.
length
)
{
...
@@ -125,7 +126,7 @@ function convertDouble(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
...
@@ -125,7 +126,7 @@ function convertDouble(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
return
res
;
return
res
;
}
}
function
convertBinary
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
function
convertBinary
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
data
=
ref
.
reinterpret
(
data
.
deref
()
,
nbytes
*
num_of_rows
,
offset
);
data
=
ref
.
reinterpret
(
data
,
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
res
=
[];
let
currOffset
=
0
;
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
while
(
currOffset
<
data
.
length
)
{
...
@@ -141,7 +142,7 @@ function convertBinary(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
...
@@ -141,7 +142,7 @@ function convertBinary(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
return
res
;
return
res
;
}
}
function
convertNchar
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
function
convertNchar
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
micro
=
false
)
{
data
=
ref
.
reinterpret
(
data
.
deref
()
,
nbytes
*
num_of_rows
,
offset
);
data
=
ref
.
reinterpret
(
data
,
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
res
=
[];
let
currOffset
=
0
;
let
currOffset
=
0
;
// every 4 bytes, a character is encoded;
// every 4 bytes, a character is encoded;
...
@@ -177,9 +178,10 @@ var char_arr = ArrayType(ref.types.char);
...
@@ -177,9 +178,10 @@ var char_arr = ArrayType(ref.types.char);
var
TaosField
=
Struct
({
var
TaosField
=
Struct
({
'
name
'
:
char_arr
,
'
name
'
:
char_arr
,
});
});
TaosField
.
fields
.
name
.
type
.
size
=
64
;
TaosField
.
fields
.
name
.
type
.
size
=
65
;
TaosField
.
defineProperty
(
'
bytes
'
,
ref
.
types
.
short
);
TaosField
.
defineProperty
(
'
type
'
,
ref
.
types
.
char
);
TaosField
.
defineProperty
(
'
type
'
,
ref
.
types
.
char
);
TaosField
.
defineProperty
(
'
bytes
'
,
ref
.
types
.
short
);
/**
/**
*
*
...
@@ -202,14 +204,14 @@ function CTaosInterface (config = null, pass = false) {
...
@@ -202,14 +204,14 @@ function CTaosInterface (config = null, pass = false) {
'
taos_connect
'
:
[
ref
.
types
.
void_ptr
,
[
ref
.
types
.
char_ptr
,
ref
.
types
.
char_ptr
,
ref
.
types
.
char_ptr
,
ref
.
types
.
char_ptr
,
ref
.
types
.
int
]
],
'
taos_connect
'
:
[
ref
.
types
.
void_ptr
,
[
ref
.
types
.
char_ptr
,
ref
.
types
.
char_ptr
,
ref
.
types
.
char_ptr
,
ref
.
types
.
char_ptr
,
ref
.
types
.
int
]
],
//void taos_close(TAOS *taos)
//void taos_close(TAOS *taos)
'
taos_close
'
:
[
ref
.
types
.
void
,
[
ref
.
types
.
void_ptr
]
],
'
taos_close
'
:
[
ref
.
types
.
void
,
[
ref
.
types
.
void_ptr
]
],
//
TAOS_RES *taos_use_result(TAO
S *taos);
//
int *taos_fetch_lengths(TAOS_RE
S *taos);
'
taos_
use_result
'
:
[
ref
.
types
.
void_ptr
,
[
ref
.
types
.
void_ptr
]
],
'
taos_
fetch_lengths
'
:
[
ref
.
types
.
void_ptr
,
[
ref
.
types
.
void_ptr
]
],
//int taos_query(TAOS *taos, char *sqlstr)
//int taos_query(TAOS *taos, char *sqlstr)
'
taos_query
'
:
[
ref
.
types
.
int
,
[
ref
.
types
.
void_ptr
,
ref
.
types
.
char_ptr
]
],
'
taos_query
'
:
[
ref
.
types
.
void_ptr
,
[
ref
.
types
.
void_ptr
,
ref
.
types
.
char_ptr
]
],
//int taos_affected_rows(TAOS *taos)
//int taos_affected_rows(TAOS *taos)
'
taos_affected_rows
'
:
[
ref
.
types
.
int
,
[
ref
.
types
.
void_ptr
]
],
'
taos_affected_rows
'
:
[
ref
.
types
.
int
,
[
ref
.
types
.
void_ptr
]
],
//int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows)
//int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows)
'
taos_fetch_block
'
:
[
ref
.
types
.
int
,
[
ref
.
types
.
void_ptr
,
ref
.
types
.
void_ptr
]
],
'
taos_fetch_block
'
:
[
ref
.
types
.
int
,
[
ref
.
types
.
void_ptr
,
ref
.
types
.
void_ptr
2
]
],
//int taos_num_fields(TAOS_RES *res);
//int taos_num_fields(TAOS_RES *res);
'
taos_num_fields
'
:
[
ref
.
types
.
int
,
[
ref
.
types
.
void_ptr
]
],
'
taos_num_fields
'
:
[
ref
.
types
.
int
,
[
ref
.
types
.
void_ptr
]
],
//TAOS_ROW taos_fetch_row(TAOS_RES *res)
//TAOS_ROW taos_fetch_row(TAOS_RES *res)
...
@@ -329,44 +331,66 @@ CTaosInterface.prototype.query = function query(connection, sql) {
...
@@ -329,44 +331,66 @@ CTaosInterface.prototype.query = function query(connection, sql) {
CTaosInterface
.
prototype
.
affectedRows
=
function
affectedRows
(
connection
)
{
CTaosInterface
.
prototype
.
affectedRows
=
function
affectedRows
(
connection
)
{
return
this
.
libtaos
.
taos_affected_rows
(
connection
);
return
this
.
libtaos
.
taos_affected_rows
(
connection
);
}
}
CTaosInterface
.
prototype
.
useResult
=
function
useResult
(
connection
)
{
CTaosInterface
.
prototype
.
useResult
=
function
useResult
(
result
)
{
let
result
=
this
.
libtaos
.
taos_use_result
(
connection
);
let
fields
=
[];
let
fields
=
[];
let
pfields
=
this
.
fetchFields
(
result
);
let
pfields
=
this
.
fetchFields
(
result
);
if
(
ref
.
isNull
(
pfields
)
==
false
)
{
if
(
ref
.
isNull
(
pfields
)
==
false
)
{
pfields
=
ref
.
reinterpret
(
pfields
,
this
.
fieldsCount
(
connection
)
*
68
,
0
);
pfields
=
ref
.
reinterpret
(
pfields
,
this
.
fieldsCount
(
result
)
*
68
,
0
);
for
(
let
i
=
0
;
i
<
pfields
.
length
;
i
+=
68
)
{
for
(
let
i
=
0
;
i
<
pfields
.
length
;
i
+=
68
)
{
//0 - 63 = name //64 - 65 = bytes, 66 - 67 = type
//0 - 63 = name //64 - 65 = bytes, 66 - 67 = type
fields
.
push
(
{
fields
.
push
(
{
name
:
ref
.
readCString
(
ref
.
reinterpret
(
pfields
,
6
4
,
i
)),
name
:
ref
.
readCString
(
ref
.
reinterpret
(
pfields
,
6
5
,
i
)),
bytes
:
pfields
[
i
+
64
],
type
:
pfields
[
i
+
65
],
type
:
pfields
[
i
+
66
]
bytes
:
pfields
[
i
+
66
]
})
})
}
}
}
}
return
{
result
:
result
,
fields
:
fields
}
return
{
fields
:
fields
}
}
}
CTaosInterface
.
prototype
.
fetchBlock
=
function
fetchBlock
(
result
,
fields
)
{
CTaosInterface
.
prototype
.
fetchBlock
=
function
fetchBlock
(
result
,
fields
)
{
let
pblock
=
ref
.
ref
(
ref
.
ref
(
ref
.
NULL
));
// equal to our raw data
let
pblock
=
ref
.
ref
(
ref
.
NULL
);
// equal to our raw data
let
num_of_rows
=
this
.
libtaos
.
taos_fetch_block
(
result
,
pblock
)
pblock
=
this
.
libtaos
.
taos_fetch_row
(
result
);
if
(
num_of_rows
==
0
)
{
if
(
pblock
==
0
)
{
return
{
block
:
null
,
num_of_rows
:
0
};
return
{
block
:
null
,
num_of_rows
:
0
};
}
}
let
isMicro
=
(
this
.
libtaos
.
taos_result_precision
(
result
)
==
FieldTypes
.
C_TIMESTAMP_MICRO
)
let
isMicro
=
(
this
.
libtaos
.
taos_result_precision
(
result
)
==
FieldTypes
.
C_TIMESTAMP_MICRO
)
let
blocks
=
new
Array
(
fields
.
length
);
blocks
.
fill
(
null
);
num_of_rows
=
Math
.
abs
(
num_of_rows
);
//
num_of_rows = Math.abs(num_of_rows);
let
offset
=
0
;
let
offset
=
0
;
pblock
=
pblock
.
deref
();
//pblock = pblock.deref();
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
)
{
var
fieldL
=
this
.
libtaos
.
taos_fetch_lengths
(
result
);
var
numoffields
=
this
.
libtaos
.
taos_field_count
(
result
);
if
(
!
convertFunctions
[
fields
[
i
][
'
type
'
]]
)
{
let
blocks
=
new
Array
(
numoffields
);
blocks
.
fill
(
null
);
var
fieldlens
=
[];
if
(
ref
.
isNull
(
fieldL
)
==
false
)
{
for
(
let
i
=
0
;
i
<
numoffields
;
i
++
)
{
let
plen
=
ref
.
reinterpret
(
fieldL
,
4
,
i
*
4
);
//plen = ref.readPointer(plen,0,ref.types.int);
let
len
=
plen
.
readInt32LE
(
0
);
fieldlens
.
push
(
len
);
//console.log(len);
}
}
for
(
let
i
=
0
;
i
<
numoffields
;
i
++
)
{
if
(
!
convertFunctions
[
fields
[
'
fields
'
][
i
][
'
type
'
]]
)
{
throw
new
errors
.
DatabaseError
(
"
Invalid data type returned from database
"
);
throw
new
errors
.
DatabaseError
(
"
Invalid data type returned from database
"
);
}
}
blocks
[
i
]
=
convertFunctions
[
fields
[
i
][
'
type
'
]](
pblock
,
num_of_rows
,
fields
[
i
][
'
bytes
'
],
offset
,
isMicro
);
prow
=
ref
.
reinterpret
(
pblock
,
8
,
i
*
8
);
offset
+=
fields
[
i
][
'
bytes
'
]
*
num_of_rows
;
console
.
log
(
fieldlens
[
i
]);
blocks
[
i
]
=
convertFunctions
[
fields
[
'
fields
'
][
i
][
'
type
'
]](
prow
,
1
,
fieldlens
[
i
],
0
,
isMicro
);
console
.
log
(
'
******************************
'
);
console
.
log
(
blocks
[
i
]);
//offset += fields[i]['bytes'] * num_of_rows;
}
}
return
{
blocks
:
blocks
,
num_of_rows
:
Math
.
abs
(
num_of_rows
)
}
return
{
blocks
:
blocks
,
num_of_rows
:
1
}
}
}
CTaosInterface
.
prototype
.
fetchRow
=
function
fetchRow
(
result
,
fields
)
{
CTaosInterface
.
prototype
.
fetchRow
=
function
fetchRow
(
result
,
fields
)
{
let
row
=
this
.
libtaos
.
taos_fetch_row
(
result
);
let
row
=
this
.
libtaos
.
taos_fetch_row
(
result
);
...
@@ -381,17 +405,17 @@ CTaosInterface.prototype.numFields = function numFields(result) {
...
@@ -381,17 +405,17 @@ CTaosInterface.prototype.numFields = function numFields(result) {
return
this
.
libtaos
.
taos_num_fields
(
result
);
return
this
.
libtaos
.
taos_num_fields
(
result
);
}
}
// Fetch fields count by connection, the latest query
// Fetch fields count by connection, the latest query
CTaosInterface
.
prototype
.
fieldsCount
=
function
fieldsCount
(
connection
)
{
CTaosInterface
.
prototype
.
fieldsCount
=
function
fieldsCount
(
result
)
{
return
this
.
libtaos
.
taos_field_count
(
connection
);
return
this
.
libtaos
.
taos_field_count
(
result
);
}
}
CTaosInterface
.
prototype
.
fetchFields
=
function
fetchFields
(
result
)
{
CTaosInterface
.
prototype
.
fetchFields
=
function
fetchFields
(
result
)
{
return
this
.
libtaos
.
taos_fetch_fields
(
result
);
return
this
.
libtaos
.
taos_fetch_fields
(
result
);
}
}
CTaosInterface
.
prototype
.
errno
=
function
errno
(
connection
)
{
CTaosInterface
.
prototype
.
errno
=
function
errno
(
result
)
{
return
this
.
libtaos
.
taos_errno
(
connection
);
return
this
.
libtaos
.
taos_errno
(
result
);
}
}
CTaosInterface
.
prototype
.
errStr
=
function
errStr
(
connection
)
{
CTaosInterface
.
prototype
.
errStr
=
function
errStr
(
result
)
{
return
ref
.
readCString
(
this
.
libtaos
.
taos_errstr
(
connection
));
return
ref
.
readCString
(
this
.
libtaos
.
taos_errstr
(
result
));
}
}
// Async
// Async
CTaosInterface
.
prototype
.
query_a
=
function
query_a
(
connection
,
sql
,
callback
,
param
=
ref
.
ref
(
ref
.
NULL
))
{
CTaosInterface
.
prototype
.
query_a
=
function
query_a
(
connection
,
sql
,
callback
,
param
=
ref
.
ref
(
ref
.
NULL
))
{
...
@@ -411,19 +435,39 @@ CTaosInterface.prototype.fetch_rows_a = function fetch_rows_a(result, callback,
...
@@ -411,19 +435,39 @@ CTaosInterface.prototype.fetch_rows_a = function fetch_rows_a(result, callback,
let
asyncCallbackWrapper
=
function
(
param2
,
result2
,
numOfRows2
)
{
let
asyncCallbackWrapper
=
function
(
param2
,
result2
,
numOfRows2
)
{
// Data preparation to pass to cursor. Could be bottleneck in query execution callback times.
// Data preparation to pass to cursor. Could be bottleneck in query execution callback times.
let
row
=
cti
.
libtaos
.
taos_fetch_row
(
result2
);
let
row
=
cti
.
libtaos
.
taos_fetch_row
(
result2
);
console
.
log
(
row
);
let
fields
=
cti
.
fetchFields_a
(
result2
);
let
fields
=
cti
.
fetchFields_a
(
result2
);
let
isMicro
=
(
cti
.
libtaos
.
taos_result_precision
(
result2
)
==
FieldTypes
.
C_TIMESTAMP_MICRO
);
let
isMicro
=
(
cti
.
libtaos
.
taos_result_precision
(
result2
)
==
FieldTypes
.
C_TIMESTAMP_MICRO
);
let
blocks
=
new
Array
(
fields
.
length
);
let
blocks
=
new
Array
(
fields
.
length
);
blocks
.
fill
(
null
);
blocks
.
fill
(
null
);
numOfRows2
=
Math
.
abs
(
numOfRows2
);
numOfRows2
=
Math
.
abs
(
numOfRows2
);
let
offset
=
0
;
let
offset
=
0
;
var
fieldL
=
cti
.
libtaos
.
taos_fetch_lengths
(
result
);
var
fieldlens
=
[];
if
(
ref
.
isNull
(
fieldL
)
==
false
)
{
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
)
{
let
plen
=
ref
.
reinterpret
(
fieldL
,
8
,
i
*
8
);
let
len
=
ref
.
get
(
plen
,
0
,
ref
.
types
.
int32
);
fieldlens
.
push
(
len
);
console
.
log
(
'
11111111111111111111
'
);
console
.
log
(
fields
.
length
);
console
.
log
(
len
);
}
}
if
(
numOfRows2
>
0
){
if
(
numOfRows2
>
0
){
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
)
{
if
(
!
convertFunctions
[
fields
[
i
][
'
type
'
]]
)
{
if
(
!
convertFunctions
[
fields
[
i
][
'
type
'
]]
)
{
throw
new
errors
.
DatabaseError
(
"
Invalid data type returned from database
"
);
throw
new
errors
.
DatabaseError
(
"
Invalid data type returned from database
"
);
}
}
blocks
[
i
]
=
convertFunctions
[
fields
[
i
][
'
type
'
]](
row
,
numOfRows2
,
fields
[
i
][
'
bytes
'
],
offset
,
isMicro
);
let
prow
=
ref
.
reinterpret
(
row
,
8
,
i
*
8
);
offset
+=
fields
[
i
][
'
bytes
'
]
*
numOfRows2
;
//blocks[i] = convertFunctions[fields[i]['type']](ref.get(prow,0,ref.types.void_ptr), numOfRows2, fieldlens[i], 0, isMicro);
console
.
log
(
prow
);
blocks
[
i
]
=
convertFunctions
[
fields
[
i
][
'
type
'
]](
ref
.
readPointer
(
prow
),
numOfRows2
,
fieldlens
[
i
],
0
,
isMicro
);
//offset += fields[i]['bytes'] * numOfRows2;
}
}
}
}
callback
(
param2
,
result2
,
numOfRows2
,
blocks
);
callback
(
param2
,
result2
,
numOfRows2
,
blocks
);
...
@@ -440,11 +484,11 @@ CTaosInterface.prototype.fetchFields_a = function fetchFields_a (result) {
...
@@ -440,11 +484,11 @@ CTaosInterface.prototype.fetchFields_a = function fetchFields_a (result) {
if
(
ref
.
isNull
(
pfields
)
==
false
)
{
if
(
ref
.
isNull
(
pfields
)
==
false
)
{
pfields
=
ref
.
reinterpret
(
pfields
,
68
*
pfieldscount
,
0
);
pfields
=
ref
.
reinterpret
(
pfields
,
68
*
pfieldscount
,
0
);
for
(
let
i
=
0
;
i
<
pfields
.
length
;
i
+=
68
)
{
for
(
let
i
=
0
;
i
<
pfields
.
length
;
i
+=
68
)
{
//0 - 6
3 = name //64 - 65 = bytes, 66 - 67 = type
//0 - 6
4 = name //65 = type, 66 - 67 = bytes
fields
.
push
(
{
fields
.
push
(
{
name
:
ref
.
readCString
(
ref
.
reinterpret
(
pfields
,
6
4
,
i
)),
name
:
ref
.
readCString
(
ref
.
reinterpret
(
pfields
,
6
5
,
i
)),
bytes
:
pfields
[
i
+
64
],
type
:
pfields
[
i
+
65
],
type
:
pfields
[
i
+
66
]
bytes
:
pfields
[
i
+
66
]
})
})
}
}
}
}
...
...
src/connector/nodejs/nodetaos/connection.js
浏览文件 @
1741d9ab
...
@@ -74,9 +74,11 @@ TDengineConnection.prototype.rollback = function rollback() {
...
@@ -74,9 +74,11 @@ TDengineConnection.prototype.rollback = function rollback() {
* Clear the results from connector
* Clear the results from connector
* @private
* @private
*/
*/
TDengineConnection
.
prototype
.
_clearResultSet
=
function
_clearResultSet
()
{
/*
TDengineConnection.prototype._clearResultSet = function _clearResultSet() {
var result = this._chandle.useResult(this._conn).result;
var result = this._chandle.useResult(this._conn).result;
if (result) {
if (result) {
this._chandle.freeResult(result)
this._chandle.freeResult(result)
}
}
}
}
*/
src/connector/nodejs/nodetaos/cursor.js
浏览文件 @
1741d9ab
...
@@ -98,7 +98,7 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback
...
@@ -98,7 +98,7 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback
if
(
this
.
_connection
==
null
)
{
if
(
this
.
_connection
==
null
)
{
throw
new
errors
.
ProgrammingError
(
'
Cursor is not connected
'
);
throw
new
errors
.
ProgrammingError
(
'
Cursor is not connected
'
);
}
}
this
.
_connection
.
_clearResultSet
();
this
.
_reset_result
();
this
.
_reset_result
();
let
stmt
=
operation
;
let
stmt
=
operation
;
...
@@ -111,18 +111,18 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback
...
@@ -111,18 +111,18 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback
});
});
obs
.
observe
({
entryTypes
:
[
'
measure
'
]
});
obs
.
observe
({
entryTypes
:
[
'
measure
'
]
});
performance
.
mark
(
'
A
'
);
performance
.
mark
(
'
A
'
);
res
=
this
.
_chandle
.
query
(
this
.
_connection
.
_conn
,
stmt
);
this
.
_result
=
this
.
_chandle
.
query
(
this
.
_connection
.
_conn
,
stmt
);
performance
.
mark
(
'
B
'
);
performance
.
mark
(
'
B
'
);
performance
.
measure
(
'
query
'
,
'
A
'
,
'
B
'
);
performance
.
measure
(
'
query
'
,
'
A
'
,
'
B
'
);
}
}
else
{
else
{
res
=
this
.
_chandle
.
query
(
this
.
_connection
.
_conn
,
stmt
);
this
.
_result
=
this
.
_chandle
.
query
(
this
.
_connection
.
_conn
,
stmt
);
}
}
res
=
this
.
_chandle
.
errno
(
this
.
_result
);
if
(
res
==
0
)
{
if
(
res
==
0
)
{
let
fieldCount
=
this
.
_chandle
.
fieldsCount
(
this
.
_
connection
.
_conn
);
let
fieldCount
=
this
.
_chandle
.
fieldsCount
(
this
.
_
result
);
if
(
fieldCount
==
0
)
{
if
(
fieldCount
==
0
)
{
let
affectedRowCount
=
this
.
_chandle
.
affectedRows
(
this
.
_
connection
.
_conn
);
let
affectedRowCount
=
this
.
_chandle
.
affectedRows
(
this
.
_
result
);
let
response
=
this
.
_createAffectedResponse
(
affectedRowCount
,
time
)
let
response
=
this
.
_createAffectedResponse
(
affectedRowCount
,
time
)
if
(
options
[
'
quiet
'
]
!=
true
)
{
if
(
options
[
'
quiet
'
]
!=
true
)
{
console
.
log
(
response
);
console
.
log
(
response
);
...
@@ -131,16 +131,17 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback
...
@@ -131,16 +131,17 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback
return
affectedRowCount
;
//return num of affected rows, common with insert, use statements
return
affectedRowCount
;
//return num of affected rows, common with insert, use statements
}
}
else
{
else
{
let
resAndField
=
this
.
_chandle
.
useResult
(
this
.
_connection
.
_conn
,
fieldCount
)
this
.
_fields
=
this
.
_chandle
.
useResult
(
this
.
_result
);
this
.
_result
=
resAndField
.
result
;
this
.
fields
=
this
.
_fields
;
this
.
_fields
=
resAndField
.
fields
;
console
.
log
(
'
++++++++++++++++++++++++++
'
)
;
this
.
fields
=
resAndField
.
fields
;
console
.
log
(
this
.
_result
)
;
wrapCB
(
callback
);
wrapCB
(
callback
);
return
this
.
_result
;
//return a pointer to the result
return
this
.
_result
;
//return a pointer to the result
}
}
}
}
else
{
else
{
throw
new
errors
.
ProgrammingError
(
this
.
_chandle
.
errStr
(
this
.
_
connection
.
_conn
))
throw
new
errors
.
ProgrammingError
(
this
.
_chandle
.
errStr
(
this
.
_
result
))
}
}
}
}
...
@@ -195,6 +196,8 @@ TDengineCursor.prototype.fetchall = function fetchall(options, callback) {
...
@@ -195,6 +196,8 @@ TDengineCursor.prototype.fetchall = function fetchall(options, callback) {
*/
*/
obs
.
observe
({
entryTypes
:
[
'
measure
'
]
});
obs
.
observe
({
entryTypes
:
[
'
measure
'
]
});
performance
.
mark
(
'
A
'
);
performance
.
mark
(
'
A
'
);
console
.
log
(
'
fetchall ----------------
'
);
while
(
true
)
{
while
(
true
)
{
let
blockAndRows
=
this
.
_chandle
.
fetchBlock
(
this
.
_result
,
this
.
_fields
);
let
blockAndRows
=
this
.
_chandle
.
fetchBlock
(
this
.
_result
,
this
.
_fields
);
...
@@ -221,7 +224,7 @@ TDengineCursor.prototype.fetchall = function fetchall(options, callback) {
...
@@ -221,7 +224,7 @@ TDengineCursor.prototype.fetchall = function fetchall(options, callback) {
let
response
=
this
.
_createSetResponse
(
this
.
_rowcount
,
time
)
let
response
=
this
.
_createSetResponse
(
this
.
_rowcount
,
time
)
console
.
log
(
response
);
console
.
log
(
response
);
this
.
_connection
.
_clearResultSet
();
//
this._connection._clearResultSet();
let
fields
=
this
.
fields
;
let
fields
=
this
.
fields
;
this
.
_reset_result
();
this
.
_reset_result
();
this
.
data
=
data
;
this
.
data
=
data
;
...
@@ -381,6 +384,9 @@ TDengineCursor.prototype.stopQuery = function stopQuery(result) {
...
@@ -381,6 +384,9 @@ TDengineCursor.prototype.stopQuery = function stopQuery(result) {
}
}
TDengineCursor
.
prototype
.
_reset_result
=
function
_reset_result
()
{
TDengineCursor
.
prototype
.
_reset_result
=
function
_reset_result
()
{
this
.
_rowcount
=
-
1
;
this
.
_rowcount
=
-
1
;
if
(
this
.
_result
!=
null
)
{
this
.
_chandle
.
freeResult
(
this
.
_result
);
}
this
.
_result
=
null
;
this
.
_result
=
null
;
this
.
_fields
=
null
;
this
.
_fields
=
null
;
this
.
data
=
[];
this
.
data
=
[];
...
...
src/connector/nodejs/package-lock.json
浏览文件 @
1741d9ab
{
{
"name"
:
"td-connector"
,
"name"
:
"td
2.0
-connector"
,
"version"
:
"
1.6
.1"
,
"version"
:
"
0.0
.1"
,
"lockfileVersion"
:
1
,
"lockfileVersion"
:
1
,
"requires"
:
true
,
"requires"
:
true
,
"dependencies"
:
{
"dependencies"
:
{
...
...
src/connector/nodejs/package.json
浏览文件 @
1741d9ab
{
{
"name"
:
"td-connector"
,
"name"
:
"td
2.0
-connector"
,
"version"
:
"
2.0.0
"
,
"version"
:
"
0.0.1
"
,
"description"
:
"A Node.js connector for TDengine."
,
"description"
:
"A Node.js connector for TDengine."
,
"main"
:
"tdengine.js"
,
"main"
:
"tdengine.js"
,
"scripts"
:
{
"scripts"
:
{
...
...
src/connector/nodejs/test/test.js
浏览文件 @
1741d9ab
...
@@ -19,7 +19,7 @@ function randomBool() {
...
@@ -19,7 +19,7 @@ function randomBool() {
}
}
// Initialize
// Initialize
//c1.execute('drop database td_connector_test;');
c1
.
execute
(
'
create database if not exists td_connector_test;
'
);
c1
.
execute
(
'
create database if not exists td_connector_test;
'
);
c1
.
execute
(
'
use td_connector_test;
'
)
c1
.
execute
(
'
use td_connector_test;
'
)
c1
.
execute
(
'
create table if not exists all_types (ts timestamp, _int int, _bigint bigint, _float float, _double double, _binary binary(40), _smallint smallint, _tinyint tinyint, _bool bool, _nchar nchar(40));
'
);
c1
.
execute
(
'
create table if not exists all_types (ts timestamp, _int int, _bigint bigint, _float float, _double double, _binary binary(40), _smallint smallint, _tinyint tinyint, _bool bool, _nchar nchar(40));
'
);
...
@@ -28,7 +28,7 @@ c1.execute('create table if not exists stabletest (ts timestamp, v1 int, v2 int,
...
@@ -28,7 +28,7 @@ c1.execute('create table if not exists stabletest (ts timestamp, v1 int, v2 int,
// Shell Test : The following uses the cursor to imitate the taos shell
// Shell Test : The following uses the cursor to imitate the taos shell
// Insert
// Insert
for
(
let
i
=
0
;
i
<
100
00
;
i
++
)
{
for
(
let
i
=
0
;
i
<
100
;
i
++
)
{
let
insertData
=
[
"
now+
"
+
i
+
"
s
"
,
// Timestamp
let
insertData
=
[
"
now+
"
+
i
+
"
s
"
,
// Timestamp
parseInt
(
R
(
-
Math
.
pow
(
2
,
31
)
+
1
,
Math
.
pow
(
2
,
31
)
-
1
)
),
// Int
parseInt
(
R
(
-
Math
.
pow
(
2
,
31
)
+
1
,
Math
.
pow
(
2
,
31
)
-
1
)
),
// Int
parseInt
(
R
(
-
Math
.
pow
(
2
,
31
)
+
1
,
Math
.
pow
(
2
,
31
)
-
1
)
),
// BigInt
parseInt
(
R
(
-
Math
.
pow
(
2
,
31
)
+
1
,
Math
.
pow
(
2
,
31
)
-
1
)
),
// BigInt
...
@@ -40,18 +40,20 @@ for (let i = 0; i < 10000; i++) {
...
@@ -40,18 +40,20 @@ for (let i = 0; i < 10000; i++) {
randomBool
(),
randomBool
(),
"
\"
Nchars
\"
"
];
// Bool
"
\"
Nchars
\"
"
];
// Bool
c1
.
execute
(
'
insert into td_connector_test.all_types values(
'
+
insertData
.
join
(
'
,
'
)
+
'
);
'
,
{
quiet
:
true
});
c1
.
execute
(
'
insert into td_connector_test.all_types values(
'
+
insertData
.
join
(
'
,
'
)
+
'
);
'
,
{
quiet
:
true
});
if
(
i
%
10
00
==
0
)
{
if
(
i
%
10
==
0
)
{
console
.
log
(
"
Insert #
"
,
i
);
console
.
log
(
"
Insert #
"
,
i
);
}
}
}
}
// Select
// Select
c1
.
execute
(
'
select * from td_connector_test.all_types limit 10 offset 1000;
'
);
console
.
log
(
'
select * from td_connector_test.all_types limit 3 offset 100;
'
);
c1
.
execute
(
'
select * from td_connector_test.all_types limit 1 offset 100;
'
);
var
d
=
c1
.
fetchall
();
var
d
=
c1
.
fetchall
();
console
.
log
(
c1
.
fields
);
console
.
log
(
c1
.
fields
);
console
.
log
(
d
);
console
.
log
(
d
);
/*
// Functions
// Functions
console.log('select count(*), avg(_int), sum(_float), max(_bigint), min(_double) from td_connector_test.all_types;')
c1.execute('select count(*), avg(_int), sum(_float), max(_bigint), min(_double) from td_connector_test.all_types;');
c1.execute('select count(*), avg(_int), sum(_float), max(_bigint), min(_double) from td_connector_test.all_types;');
var d = c1.fetchall();
var d = c1.fetchall();
console.log(c1.fields);
console.log(c1.fields);
...
@@ -134,3 +136,4 @@ setTimeout(function(){
...
@@ -134,3 +136,4 @@ setTimeout(function(){
c1.query('drop database td_connector_test;');
c1.query('drop database td_connector_test;');
},2000);
},2000);
conn.close();
conn.close();
*/
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录