Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4fae4c96
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
未验证
提交
4fae4c96
编写于
11月 08, 2021
作者:
X
xiaolei li
提交者:
GitHub
11月 08, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-3340]<feature>:nodejs support unsigned type (#8548)
上级
7d734c2c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
99 addition
and
4 deletion
+99
-4
src/connector/nodejs/nodetaos/cinterface.js
src/connector/nodejs/nodetaos/cinterface.js
+58
-1
src/connector/nodejs/nodetaos/constants.js
src/connector/nodejs/nodetaos/constants.js
+13
-1
src/connector/nodejs/package.json
src/connector/nodejs/package.json
+1
-1
src/connector/nodejs/test/test.js
src/connector/nodejs/test/test.js
+1
-1
src/connector/nodejs/test/testUnsignedType.js
src/connector/nodejs/test/testUnsignedType.js
+26
-0
未找到文件。
src/connector/nodejs/nodetaos/cinterface.js
浏览文件 @
4fae4c96
...
...
@@ -12,6 +12,7 @@ const FieldTypes = require('./constants');
const
errors
=
require
(
'
./error
'
);
const
TaosObjects
=
require
(
'
./taosobjects
'
);
const
{
NULL_POINTER
}
=
require
(
'
ref-napi
'
);
const
{
Console
}
=
require
(
'
console
'
);
module
.
exports
=
CTaosInterface
;
...
...
@@ -53,6 +54,18 @@ function convertTinyint(data, num_of_rows, nbytes = 0, offset = 0, precision = 0
}
return
res
;
}
function
convertTinyintUnsigned
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
precision
=
0
)
{
data
=
ref
.
reinterpret
(
data
.
deref
(),
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
let
d
=
data
.
readUIntLE
(
currOffset
,
1
);
res
.
push
(
d
==
FieldTypes
.
C_TINYINT_UNSIGNED_NULL
?
null
:
d
);
currOffset
+=
nbytes
;
}
return
res
;
}
function
convertSmallint
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
precision
=
0
)
{
data
=
ref
.
reinterpret
(
data
.
deref
(),
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
...
...
@@ -64,6 +77,18 @@ function convertSmallint(data, num_of_rows, nbytes = 0, offset = 0, precision =
}
return
res
;
}
function
convertSmallintUnsigned
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
precision
=
0
)
{
data
=
ref
.
reinterpret
(
data
.
deref
(),
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
let
d
=
data
.
readUIntLE
(
currOffset
,
2
);
res
.
push
(
d
==
FieldTypes
.
C_SMALLINT_UNSIGNED_NULL
?
null
:
d
);
currOffset
+=
nbytes
;
}
return
res
;
}
function
convertInt
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
precision
=
0
)
{
data
=
ref
.
reinterpret
(
data
.
deref
(),
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
...
...
@@ -75,6 +100,19 @@ function convertInt(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) {
}
return
res
;
}
function
convertIntUnsigned
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
precision
=
0
)
{
data
=
ref
.
reinterpret
(
data
.
deref
(),
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
let
d
=
data
.
readUInt32LE
(
currOffset
);
res
.
push
(
d
==
FieldTypes
.
C_INT_UNSIGNED_NULL
?
null
:
d
);
currOffset
+=
nbytes
;
}
return
res
;
}
function
convertBigint
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
precision
=
0
)
{
data
=
ref
.
reinterpret
(
data
.
deref
(),
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
...
...
@@ -86,6 +124,19 @@ function convertBigint(data, num_of_rows, nbytes = 0, offset = 0, precision = 0)
}
return
res
;
}
function
convertBigintUnsigned
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
precision
=
0
)
{
data
=
ref
.
reinterpret
(
data
.
deref
(),
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
let
d
=
data
.
readUInt64LE
(
currOffset
);
res
.
push
(
d
==
FieldTypes
.
C_BIGINT_UNSIGNED_NULL
?
null
:
BigInt
(
d
));
currOffset
+=
nbytes
;
}
return
res
;
}
function
convertFloat
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
precision
=
0
)
{
data
=
ref
.
reinterpret
(
data
.
deref
(),
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
...
...
@@ -156,7 +207,11 @@ let convertFunctions = {
[
FieldTypes
.
C_DOUBLE
]:
convertDouble
,
[
FieldTypes
.
C_BINARY
]:
convertBinary
,
[
FieldTypes
.
C_TIMESTAMP
]:
convertTimestamp
,
[
FieldTypes
.
C_NCHAR
]:
convertNchar
[
FieldTypes
.
C_NCHAR
]:
convertNchar
,
[
FieldTypes
.
C_TINYINT_UNSIGNED
]:
convertTinyintUnsigned
,
[
FieldTypes
.
C_SMALLINT_UNSIGNED
]:
convertSmallintUnsigned
,
[
FieldTypes
.
C_INT_UNSIGNED
]:
convertIntUnsigned
,
[
FieldTypes
.
C_BIGINT_UNSIGNED
]:
convertBigintUnsigned
}
// Define TaosField structure
...
...
@@ -321,6 +376,7 @@ CTaosInterface.prototype.close = function close(connection) {
CTaosInterface
.
prototype
.
query
=
function
query
(
connection
,
sql
)
{
return
this
.
libtaos
.
taos_query
(
connection
,
ref
.
allocCString
(
sql
));
}
CTaosInterface
.
prototype
.
affectedRows
=
function
affectedRows
(
result
)
{
return
this
.
libtaos
.
taos_affected_rows
(
result
);
}
...
...
@@ -413,6 +469,7 @@ CTaosInterface.prototype.query_a = function query_a(connection, sql, callback, p
this
.
libtaos
.
taos_query_a
(
connection
,
ref
.
allocCString
(
sql
),
callback
,
param
);
return
param
;
}
/** Asynchrnously fetches the next block of rows. Wraps callback and transfers a 4th argument to the cursor, the row data as blocks in javascript form
* Note: This isn't a recursive function, in order to fetch all data either use the TDengine cursor object, TaosQuery object, or implement a recrusive
* function yourself using the libtaos.taos_fetch_rows_a function
...
...
src/connector/nodejs/nodetaos/constants.js
浏览文件 @
4fae4c96
...
...
@@ -36,13 +36,21 @@ module.exports = {
C_BINARY
:
8
,
C_TIMESTAMP
:
9
,
C_NCHAR
:
10
,
C_TINYINT_UNSIGNED
:
11
,
C_SMALLINT_UNSIGNED
:
12
,
C_INT_UNSIGNED
:
13
,
C_BIGINT_UNSIGNED
:
14
,
// NULL value definition
// NOTE: These values should change according to C definition in tsdb.h
C_BOOL_NULL
:
2
,
C_TINYINT_NULL
:
-
128
,
C_TINYINT_UNSIGNED_NULL
:
255
,
C_SMALLINT_NULL
:
-
32768
,
C_SMALLINT_UNSIGNED_NULL
:
65535
,
C_INT_NULL
:
-
2147483648
,
C_BIGINT_NULL
:
-
9223372036854775808
,
C_INT_UNSIGNED_NULL
:
4294967295
,
C_BIGINT_NULL
:
-
9223372036854775808
n
,
C_BIGINT_UNSIGNED_NULL
:
18446744073709551615
n
,
C_FLOAT_NULL
:
2146435072
,
C_DOUBLE_NULL
:
-
9223370937343148032
,
C_NCHAR_NULL
:
4294967295
,
...
...
@@ -64,6 +72,10 @@ const typeCodesToName = {
8
:
'
Binary
'
,
9
:
'
Timestamp
'
,
10
:
'
Nchar
'
,
11
:
'
TINYINT_UNSIGNED
'
,
12
:
'
SMALLINT_UNSIGNED
'
,
13
:
'
INT_UNSIGNED
'
,
14
:
'
BIGINT_UNSIGNED
'
,
}
/**
...
...
src/connector/nodejs/package.json
浏览文件 @
4fae4c96
...
...
@@ -7,7 +7,7 @@
"test"
:
"test"
},
"scripts"
:
{
"test"
:
"node test/test.js && node test/testMicroseconds.js && node test/testNanoseconds.js"
"test"
:
"node test/test.js && node test/testMicroseconds.js && node test/testNanoseconds.js
&& node test/testUnsignedType.js
"
},
"repository"
:
{
"type"
:
"git"
,
...
...
src/connector/nodejs/test/test.js
浏览文件 @
4fae4c96
...
...
@@ -90,7 +90,7 @@ c1.execute("create table if not exists td_connector_test.weather(ts timestamp, t
c1
.
execute
(
"
insert into t1 using weather tags('北京') values(now, 11.11, 11)
"
);
c1
.
execute
(
"
insert into t1(ts, temperature) values(now, 22.22)
"
);
c1
.
execute
(
"
insert into t1(ts, humidity) values(now, 33)
"
);
c1
.
query
(
'
select * from test.t1
'
,
true
).
then
(
function
(
result
)
{
c1
.
query
(
'
select * from t
d_connector_t
est.t1
'
,
true
).
then
(
function
(
result
)
{
result
.
pretty
();
});
...
...
src/connector/nodejs/test/testUnsignedType.js
0 → 100644
浏览文件 @
4fae4c96
const
taos
=
require
(
'
../tdengine
'
);
var
conn
=
taos
.
connect
({
host
:
"
127.0.0.1
"
,
user
:
"
root
"
,
password
:
"
taosdata
"
,
config
:
"
/etc/taos
"
,
port
:
10
});
var
c1
=
conn
.
cursor
();
executeUpdate
(
"
create database nodedb;
"
);
executeUpdate
(
"
use nodedb;
"
);
executeUpdate
(
"
create table unsigntest(ts timestamp,ut tinyint unsigned,us smallint unsigned,ui int unsigned,ub bigint unsigned,bi bigint);
"
);
executeUpdate
(
"
insert into unsigntest values (now, 254,65534,4294967294,18446744073709551614,9223372036854775807);
"
);
executeUpdate
(
"
insert into unsigntest values (now, 0,0,0,0,-9223372036854775807);
"
);
executeQuery
(
"
select * from unsigntest;
"
);
executeUpdate
(
"
drop database nodedb;
"
);
function
executeUpdate
(
sql
)
{
console
.
log
(
sql
);
c1
.
execute
(
sql
);
}
function
executeQuery
(
sql
)
{
c1
.
execute
(
sql
)
var
data
=
c1
.
fetchall
();
// Latest query's Field metadata is stored in cursor.fields
console
.
log
(
c1
.
fields
);
// Latest query's result data is stored in cursor.data, also returned by fetchall.
console
.
log
(
c1
.
data
);
}
setTimeout
(()
=>
conn
.
close
(),
2000
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录