@tdengine/websocket 3.1.8 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +8 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -1
- package/lib/src/client/wsClient.d.ts +4 -0
- package/lib/src/client/wsClient.d.ts.map +1 -1
- package/lib/src/client/wsClient.js +35 -8
- package/lib/src/client/wsConnector.d.ts.map +1 -1
- package/lib/src/client/wsResponse.d.ts +2 -0
- package/lib/src/client/wsResponse.d.ts.map +1 -1
- package/lib/src/client/wsResponse.js +2 -0
- package/lib/src/common/config.d.ts +6 -1
- package/lib/src/common/config.d.ts.map +1 -1
- package/lib/src/common/config.js +17 -1
- package/lib/src/common/constant.d.ts +20 -2
- package/lib/src/common/constant.d.ts.map +1 -1
- package/lib/src/common/constant.js +30 -13
- package/lib/src/common/taosResult.d.ts +5 -2
- package/lib/src/common/taosResult.d.ts.map +1 -1
- package/lib/src/common/taosResult.js +59 -5
- package/lib/src/common/utils.d.ts +1 -0
- package/lib/src/common/utils.d.ts.map +1 -1
- package/lib/src/common/utils.js +31 -0
- package/lib/src/sql/wsSql.d.ts.map +1 -1
- package/lib/src/sql/wsSql.js +18 -2
- package/lib/src/stmt/FieldBindParams.d.ts +9 -0
- package/lib/src/stmt/FieldBindParams.d.ts.map +1 -0
- package/lib/src/stmt/FieldBindParams.js +13 -0
- package/lib/src/stmt/wsColumnInfo.d.ts +12 -0
- package/lib/src/stmt/wsColumnInfo.d.ts.map +1 -0
- package/lib/src/stmt/wsColumnInfo.js +17 -0
- package/lib/src/stmt/wsParams1.d.ts +14 -0
- package/lib/src/stmt/wsParams1.d.ts.map +1 -0
- package/lib/src/stmt/wsParams1.js +274 -0
- package/lib/src/stmt/wsParams2.d.ts +14 -0
- package/lib/src/stmt/wsParams2.d.ts.map +1 -0
- package/lib/src/stmt/wsParams2.js +188 -0
- package/lib/src/stmt/wsParamsBase.d.ts +45 -0
- package/lib/src/stmt/wsParamsBase.d.ts.map +1 -0
- package/lib/src/stmt/wsParamsBase.js +218 -0
- package/lib/src/stmt/wsProto.d.ts +16 -4
- package/lib/src/stmt/wsProto.d.ts.map +1 -1
- package/lib/src/stmt/wsProto.js +197 -4
- package/lib/src/stmt/wsStmt.d.ts +6 -16
- package/lib/src/stmt/wsStmt.d.ts.map +1 -1
- package/lib/src/stmt/wsStmt.js +0 -200
- package/lib/src/stmt/wsStmt1.d.ts +30 -0
- package/lib/src/stmt/wsStmt1.d.ts.map +1 -0
- package/lib/src/stmt/wsStmt1.js +206 -0
- package/lib/src/stmt/wsStmt2.d.ts +37 -0
- package/lib/src/stmt/wsStmt2.d.ts.map +1 -0
- package/lib/src/stmt/wsStmt2.js +280 -0
- package/lib/src/stmt/wsTableInfo.d.ts +17 -0
- package/lib/src/stmt/wsTableInfo.d.ts.map +1 -0
- package/lib/src/stmt/wsTableInfo.js +54 -0
- package/lib/src/tmq/constant.d.ts +2 -0
- package/lib/src/tmq/constant.d.ts.map +1 -1
- package/lib/src/tmq/constant.js +2 -0
- package/lib/src/tmq/tmqResponse.d.ts +5 -5
- package/lib/src/tmq/tmqResponse.js +8 -8
- package/lib/src/tmq/wsTmq.d.ts +1 -0
- package/lib/src/tmq/wsTmq.d.ts.map +1 -1
- package/lib/src/tmq/wsTmq.js +9 -5
- package/lib/test/bulkPulling/cloud.tmq.test.js +0 -1
- package/lib/test/bulkPulling/decimal.test.d.ts +2 -0
- package/lib/test/bulkPulling/decimal.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/decimal.test.js +129 -0
- package/lib/test/bulkPulling/sql.test.js +36 -9
- package/lib/test/bulkPulling/stmt.func.test.js +99 -11
- package/lib/test/bulkPulling/stmt.type.test.js +49 -6
- package/lib/test/bulkPulling/stmt1.func.test.d.ts +2 -0
- package/lib/test/bulkPulling/stmt1.func.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/stmt1.func.test.js +417 -0
- package/lib/test/bulkPulling/stmt1.type.test.d.ts +2 -0
- package/lib/test/bulkPulling/stmt1.type.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/stmt1.type.test.js +323 -0
- package/lib/test/bulkPulling/stmt2.func.test.d.ts +2 -0
- package/lib/test/bulkPulling/stmt2.func.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/stmt2.func.test.js +539 -0
- package/lib/test/bulkPulling/stmt2.type.test.d.ts +2 -0
- package/lib/test/bulkPulling/stmt2.type.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/stmt2.type.test.js +325 -0
- package/lib/test/bulkPulling/tmq.test.js +2 -0
- package/lib/test/bulkPulling/wsConnectPool.test.js +2 -2
- package/lib/test/utils.d.ts.map +1 -1
- package/lib/test/utils.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const wsConnectorPool_1 = require("../../src/client/wsConnectorPool");
|
|
4
|
+
const config_1 = require("../../src/common/config");
|
|
5
|
+
const wsSql_1 = require("../../src/sql/wsSql");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const log_1 = require("../../src/common/log");
|
|
8
|
+
const constant_1 = require("../../src/tmq/constant");
|
|
9
|
+
const wsTmq_1 = require("../../src/tmq/wsTmq");
|
|
10
|
+
let dns = 'ws://localhost:6041';
|
|
11
|
+
let createTopic = `create topic if not exists topic_decimal_test as select * from power.decimal_test`;
|
|
12
|
+
let dropTopic = `DROP TOPIC IF EXISTS topic_decimal_test;`;
|
|
13
|
+
(0, log_1.setLevel)("debug");
|
|
14
|
+
beforeAll(async () => {
|
|
15
|
+
let conf = new config_1.WSConfig(dns);
|
|
16
|
+
conf.setUser('root');
|
|
17
|
+
conf.setPwd('taosdata');
|
|
18
|
+
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
19
|
+
await wsSql.exec(dropTopic);
|
|
20
|
+
await wsSql.exec('drop database if exists power');
|
|
21
|
+
await wsSql.exec('create database if not exists power KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
|
|
22
|
+
await (0, utils_1.Sleep)(100);
|
|
23
|
+
await wsSql.exec('use power');
|
|
24
|
+
await wsSql.exec('CREATE STABLE if not exists decimal_test (ts timestamp, dec64 decimal(10,6), dec128 decimal(24,10), int1 int) TAGS (location binary(64), groupId int);');
|
|
25
|
+
await wsSql.exec(createTopic);
|
|
26
|
+
await wsSql.close();
|
|
27
|
+
});
|
|
28
|
+
const expectedResultsMap = new Map([
|
|
29
|
+
['-1234.654321', { dec128: '-123456789012.0987654321', int1: 3, location: 'California', groupId: 3 }],
|
|
30
|
+
['-0.000654', { dec128: '-0.0009876543', int1: 2, location: 'California', groupId: 3 }],
|
|
31
|
+
['9876.123456', { dec128: '1234567890.0987654321', int1: 1, location: 'California', groupId: 3 }]
|
|
32
|
+
]);
|
|
33
|
+
describe('TDWebSocket.WsSql()', () => {
|
|
34
|
+
jest.setTimeout(20 * 1000);
|
|
35
|
+
test('insert recoder', async () => {
|
|
36
|
+
let conf = new config_1.WSConfig(dns);
|
|
37
|
+
conf.setUser('root');
|
|
38
|
+
conf.setPwd('taosdata');
|
|
39
|
+
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
40
|
+
let taosResult = await wsSql.exec('use power');
|
|
41
|
+
console.log(taosResult);
|
|
42
|
+
expect(taosResult).toBeTruthy();
|
|
43
|
+
taosResult = await wsSql.exec('describe decimal_test');
|
|
44
|
+
console.log(taosResult);
|
|
45
|
+
taosResult = await wsSql.exec('INSERT INTO d1001 USING decimal_test (location, groupid) TAGS ("California", 3) VALUES (NOW, "9876.123456", "1234567890.0987654321", 1) (NOW + 1a, "-0.000654", "-0.0009876543", 2) (NOW + 2a, "-1234.654321", "-123456789012.0987654321", 3)');
|
|
46
|
+
console.log(taosResult);
|
|
47
|
+
expect(taosResult.getAffectRows()).toBeGreaterThanOrEqual(3);
|
|
48
|
+
let wsRows = await wsSql.query('select * from decimal_test');
|
|
49
|
+
expect(wsRows).toBeTruthy();
|
|
50
|
+
let meta = wsRows.getMeta();
|
|
51
|
+
expect(meta).toBeTruthy();
|
|
52
|
+
console.log("wsRow:meta:=>", meta);
|
|
53
|
+
let count = 0;
|
|
54
|
+
while (await wsRows.next()) {
|
|
55
|
+
let result = wsRows.getData();
|
|
56
|
+
if (result != null && result.length > 0) {
|
|
57
|
+
if (expectedResultsMap.has(result[1])) {
|
|
58
|
+
console.log("result:=>", result);
|
|
59
|
+
const expected = expectedResultsMap.get(result[1]);
|
|
60
|
+
expect(result[2]).toBe(expected?.dec128);
|
|
61
|
+
expect(result[3]).toBe(expected?.int1);
|
|
62
|
+
expect(result[4]).toBe(expected?.location);
|
|
63
|
+
expect(result[5]).toBe(expected?.groupId);
|
|
64
|
+
count++;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
await wsSql.close();
|
|
69
|
+
expect(count).toBe(3);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
test('normal Subscribe', async () => {
|
|
73
|
+
let configMap = new Map([
|
|
74
|
+
[constant_1.TMQConstants.GROUP_ID, "gId"],
|
|
75
|
+
[constant_1.TMQConstants.CONNECT_USER, "root"],
|
|
76
|
+
[constant_1.TMQConstants.CONNECT_PASS, "taosdata"],
|
|
77
|
+
[constant_1.TMQConstants.AUTO_OFFSET_RESET, "earliest"],
|
|
78
|
+
[constant_1.TMQConstants.CLIENT_ID, 'test_tmq_client'],
|
|
79
|
+
[constant_1.TMQConstants.WS_URL, dns],
|
|
80
|
+
[constant_1.TMQConstants.ENABLE_AUTO_COMMIT, 'true'],
|
|
81
|
+
[constant_1.TMQConstants.AUTO_COMMIT_INTERVAL_MS, '1000'],
|
|
82
|
+
["session.timeout.ms", "10000"],
|
|
83
|
+
["max.poll.interval.ms", "30000"],
|
|
84
|
+
["msg.with.table.name", "true"]
|
|
85
|
+
]);
|
|
86
|
+
let consumer = await wsTmq_1.WsConsumer.newConsumer(configMap);
|
|
87
|
+
await consumer.subscribe(['topic_decimal_test']);
|
|
88
|
+
let assignment = await consumer.assignment();
|
|
89
|
+
console.log(assignment);
|
|
90
|
+
let useTime = [];
|
|
91
|
+
let count = 0;
|
|
92
|
+
for (let i = 0; i < 5; i++) {
|
|
93
|
+
let startTime = new Date().getTime();
|
|
94
|
+
let res = await consumer.poll(500);
|
|
95
|
+
let currTime = new Date().getTime();
|
|
96
|
+
useTime.push(Math.abs(currTime - startTime));
|
|
97
|
+
for (let [key, value] of res) {
|
|
98
|
+
console.log(key, value.getMeta());
|
|
99
|
+
let data = value.getData();
|
|
100
|
+
if (data == null || data.length == 0) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
for (let record of data) {
|
|
104
|
+
console.log("record:=----------->", record);
|
|
105
|
+
if (expectedResultsMap.has(record[1])) {
|
|
106
|
+
const expected = expectedResultsMap.get(record[1]);
|
|
107
|
+
expect(record[2]).toBe(expected?.dec128);
|
|
108
|
+
expect(record[3]).toBe(expected?.int1);
|
|
109
|
+
expect(record[4]).toBe(expected?.location);
|
|
110
|
+
expect(record[5]).toBe(expected?.groupId);
|
|
111
|
+
count++;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
await consumer.unsubscribe();
|
|
117
|
+
await consumer.close();
|
|
118
|
+
expect(count).toBe(3);
|
|
119
|
+
});
|
|
120
|
+
afterAll(async () => {
|
|
121
|
+
let conf = new config_1.WSConfig(dns);
|
|
122
|
+
conf.setUser('root');
|
|
123
|
+
conf.setPwd('taosdata');
|
|
124
|
+
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
125
|
+
await wsSql.exec(dropTopic);
|
|
126
|
+
await wsSql.exec('drop database power');
|
|
127
|
+
await wsSql.close();
|
|
128
|
+
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
129
|
+
});
|
|
@@ -14,11 +14,13 @@ beforeAll(async () => {
|
|
|
14
14
|
conf.setUser('root');
|
|
15
15
|
conf.setPwd('taosdata');
|
|
16
16
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
17
|
+
await wsSql.exec('drop database if exists sql_test');
|
|
18
|
+
await wsSql.exec('drop database if exists sql_create');
|
|
17
19
|
await wsSql.exec(`CREATE USER user1 PASS '${password1}'`);
|
|
18
20
|
await wsSql.exec(`CREATE USER user2 PASS '${password2}'`);
|
|
19
|
-
await wsSql.exec('create database if not exists
|
|
21
|
+
await wsSql.exec('create database if not exists sql_test KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
|
|
20
22
|
await (0, utils_1.Sleep)(100);
|
|
21
|
-
await wsSql.exec('use
|
|
23
|
+
await wsSql.exec('use sql_test');
|
|
22
24
|
await wsSql.exec('CREATE STABLE if not exists meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);');
|
|
23
25
|
await wsSql.close();
|
|
24
26
|
});
|
|
@@ -30,10 +32,18 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
30
32
|
conf.setUrl(dns);
|
|
31
33
|
conf.setUser('root');
|
|
32
34
|
conf.setPwd('taosdata');
|
|
33
|
-
conf.setDb('
|
|
35
|
+
conf.setDb('sql_test');
|
|
36
|
+
conf.setTimezone('America/New_York');
|
|
34
37
|
conf.setTimeOut(6000);
|
|
35
38
|
wsSql = await wsSql_1.WsSql.open(conf);
|
|
36
39
|
expect(wsSql.state()).toBeGreaterThan(0);
|
|
40
|
+
let wsRows = await wsSql.query('select timezone()');
|
|
41
|
+
while (await wsRows.next()) {
|
|
42
|
+
let result = wsRows.getData();
|
|
43
|
+
console.log(result);
|
|
44
|
+
expect(result).toBeTruthy();
|
|
45
|
+
expect(JSON.stringify(result)).toContain('America/New_York');
|
|
46
|
+
}
|
|
37
47
|
await wsSql.close();
|
|
38
48
|
});
|
|
39
49
|
test('special characters connect1', async () => {
|
|
@@ -80,6 +90,22 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
80
90
|
}
|
|
81
91
|
}
|
|
82
92
|
});
|
|
93
|
+
test('connect url', async () => {
|
|
94
|
+
let url = 'ws://root:taosdata@localhost:6041/information_schema?timezone=Asia/Shanghai';
|
|
95
|
+
let conf = new config_1.WSConfig(url);
|
|
96
|
+
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
97
|
+
let version = await wsSql.version();
|
|
98
|
+
console.log(version);
|
|
99
|
+
expect(version).toBeTruthy();
|
|
100
|
+
let wsRows = await wsSql.query('select timezone()');
|
|
101
|
+
while (await wsRows.next()) {
|
|
102
|
+
let result = wsRows.getData();
|
|
103
|
+
console.log(result);
|
|
104
|
+
expect(result).toBeTruthy();
|
|
105
|
+
expect(JSON.stringify(result)).toContain('Asia/Shanghai');
|
|
106
|
+
}
|
|
107
|
+
await wsSql.close();
|
|
108
|
+
});
|
|
83
109
|
test('get taosc version', async () => {
|
|
84
110
|
let conf = new config_1.WSConfig(dns);
|
|
85
111
|
conf.setUser('root');
|
|
@@ -105,7 +131,7 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
105
131
|
conf.setUser('root');
|
|
106
132
|
conf.setPwd('taosdata');
|
|
107
133
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
108
|
-
let taosResult = await wsSql.exec('create database if not exists
|
|
134
|
+
let taosResult = await wsSql.exec('create database if not exists sql_create KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
|
|
109
135
|
await wsSql.close();
|
|
110
136
|
console.log(taosResult);
|
|
111
137
|
expect(taosResult).toBeTruthy();
|
|
@@ -115,7 +141,7 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
115
141
|
conf.setUser('root');
|
|
116
142
|
conf.setPwd('taosdata');
|
|
117
143
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
118
|
-
let taosResult = await wsSql.exec('use
|
|
144
|
+
let taosResult = await wsSql.exec('use sql_test');
|
|
119
145
|
console.log(taosResult);
|
|
120
146
|
expect(taosResult).toBeTruthy();
|
|
121
147
|
taosResult = await wsSql.exec('CREATE STABLE if not exists meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);');
|
|
@@ -128,7 +154,7 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
128
154
|
conf.setUser('root');
|
|
129
155
|
conf.setPwd('taosdata');
|
|
130
156
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
131
|
-
let taosResult = await wsSql.exec('use
|
|
157
|
+
let taosResult = await wsSql.exec('use sql_test');
|
|
132
158
|
console.log(taosResult);
|
|
133
159
|
expect(taosResult).toBeTruthy();
|
|
134
160
|
taosResult = await wsSql.exec('describe meters');
|
|
@@ -143,7 +169,7 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
143
169
|
conf.setUser('root');
|
|
144
170
|
conf.setPwd('taosdata');
|
|
145
171
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
146
|
-
let taosResult = await wsSql.exec('use
|
|
172
|
+
let taosResult = await wsSql.exec('use sql_test');
|
|
147
173
|
console.log(taosResult);
|
|
148
174
|
expect(taosResult).toBeTruthy();
|
|
149
175
|
for (let i = 0; i < 10; i++) {
|
|
@@ -165,7 +191,7 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
165
191
|
conf.setUser('root');
|
|
166
192
|
conf.setPwd('taosdata');
|
|
167
193
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
168
|
-
let taosResult = await wsSql.exec('use
|
|
194
|
+
let taosResult = await wsSql.exec('use sql_test');
|
|
169
195
|
console.log(taosResult);
|
|
170
196
|
expect(taosResult).toBeTruthy();
|
|
171
197
|
let wsRows = await wsSql.query('select * from meters');
|
|
@@ -178,7 +204,8 @@ afterAll(async () => {
|
|
|
178
204
|
conf.setUser('root');
|
|
179
205
|
conf.setPwd('taosdata');
|
|
180
206
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
181
|
-
await wsSql.exec('drop database
|
|
207
|
+
await wsSql.exec('drop database sql_test');
|
|
208
|
+
await wsSql.exec('drop database sql_create');
|
|
182
209
|
await wsSql.exec('DROP USER user1;');
|
|
183
210
|
await wsSql.exec('DROP USER user2;');
|
|
184
211
|
await wsSql.close();
|
|
@@ -4,7 +4,7 @@ const wsConnectorPool_1 = require("../../src/client/wsConnectorPool");
|
|
|
4
4
|
const config_1 = require("../../src/common/config");
|
|
5
5
|
const log_1 = require("../../src/common/log");
|
|
6
6
|
const wsSql_1 = require("../../src/sql/wsSql");
|
|
7
|
-
let dns = 'ws://
|
|
7
|
+
let dns = 'ws://192.168.2.156:6041';
|
|
8
8
|
(0, log_1.setLevel)("debug");
|
|
9
9
|
beforeAll(async () => {
|
|
10
10
|
let conf = new config_1.WSConfig(dns);
|
|
@@ -117,7 +117,7 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
117
117
|
}
|
|
118
118
|
catch (e) {
|
|
119
119
|
let err = e;
|
|
120
|
-
expect(err.message).toMatch(
|
|
120
|
+
expect(err.message).toMatch(/keyword INTO is expected|Syntax error in SQL/);
|
|
121
121
|
}
|
|
122
122
|
await stmt.close();
|
|
123
123
|
await connector.close();
|
|
@@ -142,7 +142,7 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
142
142
|
await stmt.close();
|
|
143
143
|
await connector.close();
|
|
144
144
|
});
|
|
145
|
-
test('
|
|
145
|
+
test('Bind supper table', async () => {
|
|
146
146
|
let conf = new config_1.WSConfig(dns);
|
|
147
147
|
conf.setUser('root');
|
|
148
148
|
conf.setPwd('taosdata');
|
|
@@ -150,14 +150,45 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
150
150
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
151
151
|
let stmt = await connector.stmtInit();
|
|
152
152
|
expect(stmt).toBeTruthy();
|
|
153
|
-
await stmt.prepare('INSERT INTO
|
|
154
|
-
|
|
153
|
+
await stmt.prepare('INSERT INTO meters (ts, tbname, current, voltage, phase, location, groupId) VALUES (?, ?, ?, ?, ?, ?, ?)');
|
|
154
|
+
let lastTs = 0;
|
|
155
|
+
for (let i = 0; i < 10; i++) {
|
|
156
|
+
for (let j = 0; j < multi[0].length; j++) {
|
|
157
|
+
multi[0][j] = multi[0][0] + j;
|
|
158
|
+
lastTs = multi[0][j];
|
|
159
|
+
}
|
|
160
|
+
let dataParams = stmt.newStmtParam();
|
|
161
|
+
dataParams.setTimestamp(multi[0]);
|
|
162
|
+
dataParams.setVarchar([`d1001`, `d1002`, `d1003`]);
|
|
163
|
+
dataParams.setFloat(multi[1]);
|
|
164
|
+
dataParams.setInt(multi[2]);
|
|
165
|
+
dataParams.setFloat(multi[3]);
|
|
166
|
+
dataParams.setVarchar(['SanFrancisco_1', 'SanFrancisco_2', 'SanFrancisco_3']);
|
|
167
|
+
dataParams.setInt([1, 2, 3]);
|
|
168
|
+
await stmt.bind(dataParams);
|
|
169
|
+
multi[0][0] = lastTs + 1;
|
|
170
|
+
}
|
|
171
|
+
await stmt.batch();
|
|
172
|
+
await stmt.exec();
|
|
173
|
+
expect(stmt.getLastAffected()).toEqual(30);
|
|
174
|
+
await stmt.close();
|
|
175
|
+
await connector.close();
|
|
176
|
+
});
|
|
177
|
+
test('Bind a single table', async () => {
|
|
178
|
+
let conf = new config_1.WSConfig(dns);
|
|
179
|
+
conf.setUser('root');
|
|
180
|
+
conf.setPwd('taosdata');
|
|
181
|
+
conf.setDb('power_stmt');
|
|
182
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
183
|
+
let stmt = await connector.stmtInit();
|
|
184
|
+
expect(stmt).toBeTruthy();
|
|
185
|
+
await stmt.prepare('INSERT INTO ? USING meters (location, groupId) TAGS (?, ?) (ts, current, voltage, phase) VALUES (?, ?, ?, ?)');
|
|
186
|
+
await stmt.setTableName('power_stmt.d1001');
|
|
155
187
|
let params = stmt.newStmtParam();
|
|
156
188
|
params.setVarchar(['SanFrancisco']);
|
|
157
|
-
params.setInt([
|
|
189
|
+
params.setInt([1]);
|
|
158
190
|
await stmt.setTags(params);
|
|
159
191
|
let lastTs = 0;
|
|
160
|
-
const allp = [];
|
|
161
192
|
for (let i = 0; i < 10; i++) {
|
|
162
193
|
for (let j = 0; j < multi[0].length; j++) {
|
|
163
194
|
multi[0][j] = multi[0][0] + j;
|
|
@@ -168,16 +199,73 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
168
199
|
dataParams.setFloat(multi[1]);
|
|
169
200
|
dataParams.setInt(multi[2]);
|
|
170
201
|
dataParams.setFloat(multi[3]);
|
|
171
|
-
|
|
202
|
+
await stmt.bind(dataParams);
|
|
172
203
|
multi[0][0] = lastTs + 1;
|
|
173
204
|
}
|
|
174
|
-
await Promise.all(allp);
|
|
175
205
|
await stmt.batch();
|
|
176
206
|
await stmt.exec();
|
|
177
207
|
expect(stmt.getLastAffected()).toEqual(30);
|
|
178
208
|
await stmt.close();
|
|
179
209
|
await connector.close();
|
|
180
210
|
});
|
|
211
|
+
test('Bind multiple tables', async () => {
|
|
212
|
+
let conf = new config_1.WSConfig(dns);
|
|
213
|
+
conf.setUser('root');
|
|
214
|
+
conf.setPwd('taosdata');
|
|
215
|
+
conf.setDb('power_stmt');
|
|
216
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
217
|
+
let stmt = await connector.stmtInit();
|
|
218
|
+
expect(stmt).toBeTruthy();
|
|
219
|
+
await stmt.prepare('INSERT INTO ? USING meters (location, groupId) TAGS (?, ?) (ts, current, voltage, phase) VALUES (?, ?, ?, ?)');
|
|
220
|
+
let lastTs = 0;
|
|
221
|
+
for (let i = 0; i < 10; i++) {
|
|
222
|
+
for (let j = 0; j < multi[0].length; j++) {
|
|
223
|
+
multi[0][j] = multi[0][0] + j;
|
|
224
|
+
lastTs = multi[0][j];
|
|
225
|
+
}
|
|
226
|
+
await stmt.setTableName(`power_stmt.d100${i + 1}`);
|
|
227
|
+
let params = stmt.newStmtParam();
|
|
228
|
+
params.setVarchar([`SanFrancisco${i + 1}`]);
|
|
229
|
+
params.setInt([i + 1]);
|
|
230
|
+
await stmt.setTags(params);
|
|
231
|
+
let dataParams = stmt.newStmtParam();
|
|
232
|
+
dataParams.setTimestamp(multi[0]);
|
|
233
|
+
dataParams.setFloat(multi[1]);
|
|
234
|
+
dataParams.setInt(multi[2]);
|
|
235
|
+
dataParams.setFloat(multi[3]);
|
|
236
|
+
await stmt.bind(dataParams);
|
|
237
|
+
multi[0][0] = lastTs + 1;
|
|
238
|
+
}
|
|
239
|
+
await stmt.batch();
|
|
240
|
+
await stmt.exec();
|
|
241
|
+
expect(stmt.getLastAffected()).toEqual(30);
|
|
242
|
+
await stmt.close();
|
|
243
|
+
await connector.close();
|
|
244
|
+
});
|
|
245
|
+
test('query bind', async () => {
|
|
246
|
+
let conf = new config_1.WSConfig(dns);
|
|
247
|
+
conf.setUser('root');
|
|
248
|
+
conf.setPwd('taosdata');
|
|
249
|
+
conf.setDb('power_stmt');
|
|
250
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
251
|
+
let stmt = await connector.stmtInit();
|
|
252
|
+
expect(stmt).toBeTruthy();
|
|
253
|
+
await stmt.prepare('select * from meters where ts > ? and ts < ?');
|
|
254
|
+
let dataParams = stmt.newStmtParam();
|
|
255
|
+
dataParams.setTimestamp([1709183268565]);
|
|
256
|
+
dataParams.setTimestamp([1709183268569]);
|
|
257
|
+
await stmt.bind(dataParams);
|
|
258
|
+
await stmt.exec();
|
|
259
|
+
let wsRows = await stmt.resultSet();
|
|
260
|
+
while (await wsRows.next()) {
|
|
261
|
+
let result = await wsRows.getData();
|
|
262
|
+
console.log(result);
|
|
263
|
+
expect(result).toBeTruthy();
|
|
264
|
+
}
|
|
265
|
+
await wsRows.close();
|
|
266
|
+
await stmt.close();
|
|
267
|
+
await connector.close();
|
|
268
|
+
});
|
|
181
269
|
test('error BindParam', async () => {
|
|
182
270
|
let conf = new config_1.WSConfig(dns);
|
|
183
271
|
conf.setUser('root');
|
|
@@ -211,7 +299,7 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
211
299
|
}
|
|
212
300
|
catch (e) {
|
|
213
301
|
let err = e;
|
|
214
|
-
expect(err.message).toMatch(
|
|
302
|
+
expect(err.message).toMatch(/wrong row length|bind data length error/);
|
|
215
303
|
}
|
|
216
304
|
await stmt.close();
|
|
217
305
|
await connector.close();
|
|
@@ -328,7 +416,7 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
328
416
|
}
|
|
329
417
|
catch (e) {
|
|
330
418
|
let err = e;
|
|
331
|
-
expect(err.message).toMatch(
|
|
419
|
+
expect(err.message).toMatch(/Retry needed|Tags are empty/);
|
|
332
420
|
}
|
|
333
421
|
await stmt.close();
|
|
334
422
|
await connector.close();
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const wsConnectorPool_1 = require("../../src/client/wsConnectorPool");
|
|
4
4
|
const config_1 = require("../../src/common/config");
|
|
5
|
+
const log_1 = require("../../src/common/log");
|
|
5
6
|
const wsSql_1 = require("../../src/sql/wsSql");
|
|
6
7
|
const utils_1 = require("../utils");
|
|
7
8
|
const stable = 'ws_stmt_stb';
|
|
@@ -70,7 +71,8 @@ const selectTable = `select * from ${table}`;
|
|
|
70
71
|
const selectTableCN = `select * from ${tableCN}`;
|
|
71
72
|
const selectJsonTable = `select * from ${jsonTable}`;
|
|
72
73
|
const selectJsonTableCN = `select * from ${jsonTableCN}`;
|
|
73
|
-
let dsn = 'ws://root:taosdata@
|
|
74
|
+
let dsn = 'ws://root:taosdata@192.168.2.156:6041';
|
|
75
|
+
(0, log_1.setLevel)("debug");
|
|
74
76
|
beforeAll(async () => {
|
|
75
77
|
let conf = new config_1.WSConfig(dsn);
|
|
76
78
|
let ws = await wsSql_1.WsSql.open(conf);
|
|
@@ -87,7 +89,7 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
87
89
|
let wsConf = new config_1.WSConfig(dsn);
|
|
88
90
|
wsConf.setDb(db);
|
|
89
91
|
let connector = await wsSql_1.WsSql.open(wsConf);
|
|
90
|
-
let stmt = await
|
|
92
|
+
let stmt = await connector.stmtInit();
|
|
91
93
|
expect(stmt).toBeTruthy();
|
|
92
94
|
expect(connector.state()).toBeGreaterThan(0);
|
|
93
95
|
await stmt.prepare((0, utils_1.getInsertBind)(tableValues.length + 2, stableTags.length, db, stable));
|
|
@@ -264,10 +266,51 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
264
266
|
await connector.close();
|
|
265
267
|
});
|
|
266
268
|
});
|
|
269
|
+
test('test bind exception cases', async () => {
|
|
270
|
+
let wsConf = new config_1.WSConfig(dsn);
|
|
271
|
+
let connector = await wsSql_1.WsSql.open(wsConf);
|
|
272
|
+
let stmt = await connector.stmtInit();
|
|
273
|
+
const params = stmt.newStmtParam();
|
|
274
|
+
const emptyArrayMethods = [
|
|
275
|
+
{ method: 'setBoolean', name: 'SetBooleanColumn' },
|
|
276
|
+
{ method: 'setTinyInt', name: 'SetTinyIntColumn' },
|
|
277
|
+
{ method: 'setUTinyInt', name: 'SetUTinyIntColumn' },
|
|
278
|
+
{ method: 'setSmallInt', name: 'SetSmallIntColumn' },
|
|
279
|
+
{ method: 'setUSmallInt', name: 'SetSmallIntColumn' },
|
|
280
|
+
{ method: 'setInt', name: 'SetIntColumn' },
|
|
281
|
+
{ method: 'setUInt', name: 'SetUIntColumn' },
|
|
282
|
+
{ method: 'setBigint', name: 'SetBigIntColumn' },
|
|
283
|
+
{ method: 'setUBigint', name: 'SetUBigIntColumn' },
|
|
284
|
+
{ method: 'setFloat', name: 'SetFloatColumn' },
|
|
285
|
+
{ method: 'setDouble', name: 'SetDoubleColumn' },
|
|
286
|
+
{ method: 'setTimestamp', name: 'SeTimestampColumn' }
|
|
287
|
+
];
|
|
288
|
+
emptyArrayMethods.forEach(({ method, name }) => {
|
|
289
|
+
expect(() => {
|
|
290
|
+
params[method]([]);
|
|
291
|
+
}).toThrow(`${name} params is invalid!`);
|
|
292
|
+
expect(() => {
|
|
293
|
+
params[method](null);
|
|
294
|
+
}).toThrow(`${name} params is invalid!`);
|
|
295
|
+
expect(() => {
|
|
296
|
+
params[method](undefined);
|
|
297
|
+
}).toThrow(`${name} params is invalid!`);
|
|
298
|
+
});
|
|
299
|
+
expect(() => {
|
|
300
|
+
params.setBoolean(['not boolean']);
|
|
301
|
+
}).toThrow('SetTinyIntColumn params is invalid!');
|
|
302
|
+
expect(() => {
|
|
303
|
+
params.setTinyInt(['not number']);
|
|
304
|
+
}).toThrow('SetTinyIntColumn params is invalid!');
|
|
305
|
+
expect(() => {
|
|
306
|
+
params.setBigint(['not bigint']);
|
|
307
|
+
}).toThrow('SetTinyIntColumn params is invalid!');
|
|
308
|
+
await connector.close();
|
|
309
|
+
});
|
|
267
310
|
afterAll(async () => {
|
|
268
|
-
let conf = new
|
|
269
|
-
let ws = await
|
|
270
|
-
await ws.exec(dropDB);
|
|
271
|
-
await ws.close();
|
|
311
|
+
// let conf :WSConfig = new WSConfig(dsn)
|
|
312
|
+
// let ws = await WsSql.open(conf);
|
|
313
|
+
// await ws.exec(dropDB);
|
|
314
|
+
// await ws.close();
|
|
272
315
|
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
273
316
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stmt1.func.test.d.ts","sourceRoot":"","sources":["../../../test/bulkPulling/stmt1.func.test.ts"],"names":[],"mappings":""}
|