Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
哥们要飞
TDengine
提交
2b84d450
T
TDengine
项目概览
哥们要飞
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2b84d450
编写于
7月 30, 2020
作者:
L
liu0x54
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-1001] adapt nodejs connector
上级
d7eafe9c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
25 addition
and
32 deletion
+25
-32
src/connector/nodejs/nodetaos/cinterface.js
src/connector/nodejs/nodetaos/cinterface.js
+11
-19
src/connector/nodejs/nodetaos/cursor.js
src/connector/nodejs/nodetaos/cursor.js
+5
-5
src/connector/nodejs/test/test.js
src/connector/nodejs/test/test.js
+9
-8
未找到文件。
src/connector/nodejs/nodetaos/cinterface.js
浏览文件 @
2b84d450
...
...
@@ -346,7 +346,7 @@ CTaosInterface.prototype.useResult = function useResult(result) {
})
}
}
return
{
fields
:
fields
}
return
fields
;
}
CTaosInterface
.
prototype
.
fetchBlock
=
function
fetchBlock
(
result
,
fields
)
{
let
pblock
=
ref
.
ref
(
ref
.
ref
(
ref
.
NULL
));
// equal to our raw data
...
...
@@ -355,7 +355,6 @@ CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) {
return
{
block
:
null
,
num_of_rows
:
0
};
}
var
fieldL
=
this
.
libtaos
.
taos_fetch_lengths
(
result
);
var
numoffields
=
this
.
libtaos
.
taos_field_count
(
result
);
let
isMicro
=
(
this
.
libtaos
.
taos_result_precision
(
result
)
==
FieldTypes
.
C_TIMESTAMP_MICRO
);
...
...
@@ -363,26 +362,25 @@ CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) {
if
(
ref
.
isNull
(
fieldL
)
==
false
)
{
for
(
let
i
=
0
;
i
<
numoffields
;
i
++
)
{
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
)
{
let
plen
=
ref
.
reinterpret
(
fieldL
,
4
,
i
*
4
);
let
len
=
plen
.
readInt32LE
(
0
);
fieldlens
.
push
(
len
);
}
}
let
blocks
=
new
Array
(
numoffields
);
let
blocks
=
new
Array
(
fields
.
length
);
blocks
.
fill
(
null
);
num_of_rows
=
Math
.
abs
(
num_of_rows
);
let
offset
=
0
;
pblock
=
pblock
.
deref
();
for
(
let
i
=
0
;
i
<
numoffields
;
i
++
)
{
if
(
!
convertFunctions
[
fields
[
'
fields
'
][
i
][
'
type
'
]]
)
{
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
)
{
pdata
=
ref
.
reinterpret
(
pblock
,
8
,
i
*
8
);
pdata
=
ref
.
ref
(
pdata
.
readPointer
());
if
(
!
convertFunctions
[
fields
[
i
][
'
type
'
]]
)
{
throw
new
errors
.
DatabaseError
(
"
Invalid data type returned from database
"
);
}
blocks
[
i
]
=
convertFunctions
[
fields
[
'
fields
'
][
i
][
'
type
'
]](
pblock
,
num_of_rows
,
fieldlens
[
i
],
offset
,
isMicro
);
console
.
log
(
blocks
[
i
]);
offset
+=
fields
[
'
fields
'
][
i
][
'
bytes
'
]
*
num_of_rows
;
blocks
[
i
]
=
convertFunctions
[
fields
[
i
][
'
type
'
]](
pdata
,
1
,
fieldlens
[
i
],
offset
,
isMicro
);
}
return
{
blocks
:
blocks
,
num_of_rows
:
Math
.
abs
(
num_of_rows
)}
}
...
...
@@ -429,9 +427,7 @@ CTaosInterface.prototype.fetch_rows_a = function fetch_rows_a(result, callback,
let
asyncCallbackWrapper
=
function
(
param2
,
result2
,
numOfRows2
)
{
// Data preparation to pass to cursor. Could be bottleneck in query execution callback times.
let
row
=
cti
.
libtaos
.
taos_fetch_row
(
result2
);
console
.
log
(
row
);
let
fields
=
cti
.
fetchFields_a
(
result2
);
let
isMicro
=
(
cti
.
libtaos
.
taos_result_precision
(
result2
)
==
FieldTypes
.
C_TIMESTAMP_MICRO
);
let
blocks
=
new
Array
(
fields
.
length
);
...
...
@@ -446,21 +442,17 @@ CTaosInterface.prototype.fetch_rows_a = function fetch_rows_a(result, callback,
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
){
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
)
{
if
(
!
convertFunctions
[
fields
[
i
][
'
type
'
]]
)
{
throw
new
errors
.
DatabaseError
(
"
Invalid data type returned from database
"
);
}
let
prow
=
ref
.
reinterpret
(
row
,
8
,
i
*
8
);
//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
);
prow
=
prow
.
readPointer
(
);
prow
=
ref
.
ref
(
prow
);
blocks
[
i
]
=
convertFunctions
[
fields
[
i
][
'
type
'
]](
prow
,
1
,
fieldlens
[
i
],
offset
,
isMicro
);
//offset += fields[i]['bytes'] * numOfRows2;
}
}
...
...
src/connector/nodejs/nodetaos/cursor.js
浏览文件 @
2b84d450
...
...
@@ -133,8 +133,6 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback
else
{
this
.
_fields
=
this
.
_chandle
.
useResult
(
this
.
_result
);
this
.
fields
=
this
.
_fields
;
console
.
log
(
'
++++++++++++++++++++++++++
'
);
console
.
log
(
this
.
_result
);
wrapCB
(
callback
);
return
this
.
_result
;
//return a pointer to the result
...
...
@@ -205,10 +203,12 @@ TDengineCursor.prototype.fetchall = function fetchall(options, callback) {
break
;
}
this
.
_rowcount
+=
num_of_rows
;
let
numoffields
=
this
.
_fields
.
length
;
for
(
let
i
=
0
;
i
<
num_of_rows
;
i
++
)
{
data
.
push
([]);
let
rowBlock
=
new
Array
(
this
.
_fields
.
length
);
for
(
let
j
=
0
;
j
<
this
.
_fields
.
length
;
j
++
)
{
let
rowBlock
=
new
Array
(
numoffields
);
for
(
let
j
=
0
;
j
<
numoffields
;
j
++
)
{
rowBlock
[
j
]
=
block
[
j
][
i
];
}
data
[
data
.
length
-
1
]
=
(
rowBlock
);
...
...
@@ -268,7 +268,7 @@ TDengineCursor.prototype.execute_a = function execute_a (operation, options, cal
let
fieldCount
=
cr
.
_chandle
.
numFields
(
res2
);
if
(
fieldCount
==
0
)
{
cr
.
_chandle
.
freeResult
(
res2
);
}
}
else
{
return
res2
;
}
...
...
src/connector/nodejs/test/test.js
浏览文件 @
2b84d450
...
...
@@ -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
// Insert
for
(
let
i
=
0
;
i
<
100
;
i
++
)
{
for
(
let
i
=
0
;
i
<
100
0
;
i
++
)
{
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
)
),
// BigInt
...
...
@@ -40,18 +40,18 @@ for (let i = 0; i < 100; i++) {
randomBool
(),
"
\"
Nchars
\"
"
];
// Bool
c1
.
execute
(
'
insert into td_connector_test.all_types values(
'
+
insertData
.
join
(
'
,
'
)
+
'
);
'
,
{
quiet
:
true
});
if
(
i
%
10
==
0
)
{
if
(
i
%
10
0
==
0
)
{
console
.
log
(
"
Insert #
"
,
i
);
}
}
// Select
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;
'
);
c1
.
execute
(
'
select * from td_connector_test.all_types limit
2
offset 100;
'
);
var
d
=
c1
.
fetchall
();
console
.
log
(
c1
.
fields
);
console
.
log
(
d
);
/*
// 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;
'
);
...
...
@@ -61,12 +61,14 @@ console.log(d);
// Immediate Execution like the Shell
c1.query('select count(*), stddev(_double), min(_tinyint) from all_types where _tinyint > 50 and _int < 0;', true).then(function(result){
result.pretty();
})
//c1.query('select count(*), stddev(_double), min(_tinyint) from all_types where _tinyint > 50 and _int < 0;', true).then(function(result){
// result.pretty();
//})
c1
.
query
(
'
select _tinyint, _bool from all_types where _tinyint > 50 and _int < 0 limit 50;
'
,
true
).
then
(
function
(
result
){
result
.
pretty
();
})
c1
.
query
(
'
select stddev(_double), stddev(_bigint), stddev(_float) from all_types;
'
,
true
).
then
(
function
(
result
){
result
.
pretty
();
})
...
...
@@ -136,4 +138,3 @@ setTimeout(function(){
c1
.
query
(
'
drop database td_connector_test;
'
);
},
2000
);
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录