@tdengine/websocket 3.1.0 → 3.1.2
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/example/all_type_query.d.ts +2 -0
- package/lib/example/all_type_query.d.ts.map +1 -0
- package/lib/example/all_type_query.js +89 -0
- package/lib/example/all_type_stmt.d.ts +2 -0
- package/lib/example/all_type_stmt.d.ts.map +1 -0
- package/lib/example/all_type_stmt.js +130 -0
- package/lib/example/basicBatchTmq.d.ts +2 -0
- package/lib/example/basicBatchTmq.d.ts.map +1 -0
- package/lib/example/basicBatchTmq.js +129 -0
- package/lib/example/basicSql.js +9 -7
- package/lib/example/basicStmt.js +34 -20
- package/lib/example/basicTmq.js +22 -20
- package/lib/example/logs/.007e668bb78549e9a304b8466671945ab2a1553e-audit.json +15 -0
- package/lib/example/logs/app-2024-10-12.log.gz +0 -0
- package/lib/example/logs/app-2024-11-06.log +542 -0
- package/lib/example/test.d.ts +2 -0
- package/lib/example/test.d.ts.map +1 -0
- package/lib/example/test.js +88 -0
- package/lib/src/client/wsClient.d.ts +2 -5
- package/lib/src/client/wsClient.d.ts.map +1 -1
- package/lib/src/client/wsClient.js +4 -54
- package/lib/src/client/wsConnector.js +3 -3
- package/lib/src/client/wsResponse.d.ts +10 -15
- package/lib/src/client/wsResponse.d.ts.map +1 -1
- package/lib/src/client/wsResponse.js +31 -19
- package/lib/src/common/constant.d.ts +23 -1
- package/lib/src/common/constant.d.ts.map +1 -1
- package/lib/src/common/constant.js +25 -22
- package/lib/src/common/log.js +1 -1
- package/lib/src/common/taosResult.d.ts +11 -5
- package/lib/src/common/taosResult.d.ts.map +1 -1
- package/lib/src/common/taosResult.js +106 -76
- package/lib/src/common/utils.d.ts +2 -0
- package/lib/src/common/utils.d.ts.map +1 -1
- package/lib/src/common/utils.js +34 -1
- package/lib/src/sql/wsRows.d.ts.map +1 -1
- package/lib/src/sql/wsRows.js +21 -10
- package/lib/src/sql/wsSql.d.ts.map +1 -1
- package/lib/src/sql/wsSql.js +29 -19
- package/lib/src/stmt/wsParams.js +40 -40
- package/lib/src/tmq/constant.d.ts +15 -0
- package/lib/src/tmq/constant.d.ts.map +1 -1
- package/lib/src/tmq/constant.js +17 -1
- package/lib/src/tmq/tmqResponse.d.ts +20 -8
- package/lib/src/tmq/tmqResponse.d.ts.map +1 -1
- package/lib/src/tmq/tmqResponse.js +214 -89
- package/lib/src/tmq/wsTmq.d.ts +0 -1
- package/lib/src/tmq/wsTmq.d.ts.map +1 -1
- package/lib/src/tmq/wsTmq.js +18 -32
- package/lib/test/bulkPulling/log.test.d.ts +2 -0
- package/lib/test/bulkPulling/log.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/log.test.js +44 -0
- package/lib/test/bulkPulling/schemaless.test.js +7 -6
- package/lib/test/bulkPulling/sql.test.js +38 -18
- package/lib/test/bulkPulling/stmt.func.test.js +72 -56
- package/lib/test/bulkPulling/stmt.type.test.js +1 -5
- package/lib/test/bulkPulling/tmq.test.js +22 -15
- package/lib/test/bulkPulling/wsConnectPool.test.js +9 -2
- package/lib/test/utils.d.ts +0 -1
- package/lib/test/utils.d.ts.map +1 -1
- package/lib/test/utils.js +17 -17
- package/package.json +2 -2
package/lib/src/tmq/wsTmq.d.ts
CHANGED
|
@@ -22,7 +22,6 @@ export declare class WsConsumer {
|
|
|
22
22
|
seekToBeginning(partitions: Array<TopicPartition>): Promise<void>;
|
|
23
23
|
seekToEnd(partitions: Array<TopicPartition>): Promise<void>;
|
|
24
24
|
close(): Promise<void>;
|
|
25
|
-
private fetch;
|
|
26
25
|
private fetchBlockData;
|
|
27
26
|
private pollData;
|
|
28
27
|
private sendAssignmentReq;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsTmq.d.ts","sourceRoot":"","sources":["../../../src/tmq/wsTmq.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAkF,cAAc,
|
|
1
|
+
{"version":3,"file":"wsTmq.d.ts","sourceRoot":"","sources":["../../../src/tmq/wsTmq.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAkF,cAAc,EAA0D,MAAM,eAAe,CAAC;AAKvL,qBAAa,UAAU;IACnB,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,OAAO,CAAC,CAAU;IAC1B,OAAO,CAAC,WAAW,CAAC,CAAQ;IAC5B,OAAO;YAMO,IAAI;WAML,WAAW,CAAC,QAAQ,EAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAE,OAAO,CAAC,UAAU,CAAC;IAUjE,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,EAAC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB9D,WAAW,CAAC,KAAK,CAAC,EAAC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUzC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAC,MAAM,GAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAgBvE,YAAY,CAAC,KAAK,CAAC,EAAC,MAAM,GAAE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAYlD,MAAM,CAAC,KAAK,CAAC,EAAC,MAAM,GAAE,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;YAK5C,QAAQ;IAYhB,SAAS,CAAC,UAAU,EAAC,KAAK,CAAC,cAAc,CAAC,EAAE,KAAK,CAAC,EAAC,MAAM,GAAE,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IA0BzF,aAAa,CAAC,UAAU,EAAC,KAAK,CAAC,cAAc,CAAC,GAAE,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAc9E,YAAY,CAAC,SAAS,EAAC,cAAc,EAAE,KAAK,CAAC,EAAC,MAAM,GAAE,OAAO,CAAC,IAAI,CAAC;IAkBnE,SAAS,CAAC,UAAU,EAAC,KAAK,CAAC,cAAc,CAAC,EAAE,KAAK,CAAC,EAAC,MAAM,GAAE,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IA0BzF,IAAI,CAAC,SAAS,EAAC,cAAc,EAAE,KAAK,CAAC,EAAC,MAAM,GAAE,OAAO,CAAC,IAAI,CAAC;IAkB3D,eAAe,CAAC,UAAU,EAAC,KAAK,CAAC,cAAc,CAAC,GAAE,OAAO,CAAC,IAAI,CAAC;IAQ/D,SAAS,CAAC,UAAU,EAAC,KAAK,CAAC,cAAc,CAAC,GAAE,OAAO,CAAC,IAAI,CAAC;IASzD,KAAK,IAAG,OAAO,CAAC,IAAI,CAAC;YAIb,cAAc;YAwBd,QAAQ;YA4BR,iBAAiB;IAczB,UAAU,CAAC,MAAM,CAAC,EAAC,MAAM,EAAE,GAAE,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;YAoBnD,gBAAgB;CA6BjC"}
|
package/lib/src/tmq/wsTmq.js
CHANGED
|
@@ -11,6 +11,7 @@ const wsError_1 = require("../common/wsError");
|
|
|
11
11
|
const tmqResponse_1 = require("./tmqResponse");
|
|
12
12
|
const reqid_1 = require("../common/reqid");
|
|
13
13
|
const log_1 = __importDefault(require("../common/log"));
|
|
14
|
+
const wsResponse_1 = require("../client/wsResponse");
|
|
14
15
|
class WsConsumer {
|
|
15
16
|
constructor(wsConfig) {
|
|
16
17
|
this._wsConfig = new config_1.TmqConfig(wsConfig);
|
|
@@ -198,9 +199,9 @@ class WsConsumer {
|
|
|
198
199
|
async close() {
|
|
199
200
|
await this._wsClient.close();
|
|
200
201
|
}
|
|
201
|
-
async
|
|
202
|
+
async fetchBlockData(pollResp, taosResult) {
|
|
202
203
|
let fetchMsg = {
|
|
203
|
-
action: '
|
|
204
|
+
action: 'fetch_raw_data',
|
|
204
205
|
args: {
|
|
205
206
|
req_id: reqid_1.ReqId.getReqID(),
|
|
206
207
|
message_id: pollResp.message_id,
|
|
@@ -208,22 +209,16 @@ class WsConsumer {
|
|
|
208
209
|
};
|
|
209
210
|
let jsonStr = JSON.stringify(fetchMsg);
|
|
210
211
|
log_1.default.debug('[wsQueryInterface.fetch.fetchMsg]===>' + jsonStr);
|
|
211
|
-
let result = await this._wsClient.exec(jsonStr, false);
|
|
212
|
-
return new tmqResponse_1.WsTmqQueryResponse(result);
|
|
213
|
-
}
|
|
214
|
-
async fetchBlockData(fetchResponse, taosResult) {
|
|
215
|
-
let fetchMsg = {
|
|
216
|
-
action: 'fetch_block',
|
|
217
|
-
args: {
|
|
218
|
-
req_id: fetchResponse.req_id,
|
|
219
|
-
message_id: fetchResponse.message_id,
|
|
220
|
-
},
|
|
221
|
-
};
|
|
222
|
-
let jsonStr = JSON.stringify(fetchMsg);
|
|
223
|
-
log_1.default.debug('[wsQueryInterface.fetch.fetchMsg]===>' + jsonStr);
|
|
224
212
|
let result = await this._wsClient.sendMsg(jsonStr);
|
|
225
|
-
|
|
226
|
-
|
|
213
|
+
let wsResponse = new wsResponse_1.WSFetchBlockResponse(result.msg);
|
|
214
|
+
if (wsResponse && wsResponse.data && wsResponse.blockLen > 0) {
|
|
215
|
+
let wsTmqResponse = new tmqResponse_1.WSTmqFetchBlockInfo(wsResponse.data, taosResult);
|
|
216
|
+
log_1.default.debug('[WSTmqFetchBlockInfo.fetchBlockData]===>' + wsTmqResponse.taosResult);
|
|
217
|
+
if (wsTmqResponse.rows > 0) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
227
222
|
}
|
|
228
223
|
async pollData(timeoutMs, reqId) {
|
|
229
224
|
let queryMsg = {
|
|
@@ -233,26 +228,17 @@ class WsConsumer {
|
|
|
233
228
|
blocking_time: timeoutMs
|
|
234
229
|
},
|
|
235
230
|
};
|
|
236
|
-
var taosResults = new Map();
|
|
237
231
|
let resp = await this._wsClient.exec(JSON.stringify(queryMsg), false);
|
|
238
232
|
let pollResp = new tmqResponse_1.WsPollResponse(resp);
|
|
233
|
+
let taosResult = new tmqResponse_1.TaosTmqResult(pollResp);
|
|
234
|
+
var taosResults = new Map();
|
|
235
|
+
taosResults.set(pollResp.topic, taosResult);
|
|
239
236
|
if (!pollResp.have_message || pollResp.message_type != constant_1.TMQMessageType.ResDataType) {
|
|
240
237
|
return taosResults;
|
|
241
238
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
let taosResult = taosResults.get(pollResp.topic + pollResp.vgroup_id);
|
|
248
|
-
if (taosResult == null) {
|
|
249
|
-
taosResult = new tmqResponse_1.TaosTmqResult(fetchResp, pollResp);
|
|
250
|
-
taosResults.set(pollResp.topic + pollResp.vgroup_id, taosResult);
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
taosResult.setRowsAndTime(fetchResp.rows);
|
|
254
|
-
}
|
|
255
|
-
await this.fetchBlockData(fetchResp, taosResult);
|
|
239
|
+
let finish = false;
|
|
240
|
+
while (!finish) {
|
|
241
|
+
finish = await this.fetchBlockData(pollResp, taosResult);
|
|
256
242
|
}
|
|
257
243
|
return taosResults;
|
|
258
244
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.test.d.ts","sourceRoot":"","sources":["../../../test/bulkPulling/log.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const log_1 = __importStar(require("../../src/common/log"));
|
|
27
|
+
describe('log level print', () => {
|
|
28
|
+
test('normal connect', async () => {
|
|
29
|
+
log_1.default.info('log level is info');
|
|
30
|
+
log_1.default.debug('log level is debug');
|
|
31
|
+
log_1.default.error('log level is error');
|
|
32
|
+
let isLevel = log_1.default.isLevelEnabled("info");
|
|
33
|
+
expect(isLevel).toEqual(true);
|
|
34
|
+
(0, log_1.setLevel)("debug");
|
|
35
|
+
log_1.default.debug('log level is debug');
|
|
36
|
+
isLevel = log_1.default.isLevelEnabled("debug");
|
|
37
|
+
expect(isLevel).toEqual(true);
|
|
38
|
+
(0, log_1.setLevel)("error");
|
|
39
|
+
log_1.default.error('log level is error');
|
|
40
|
+
log_1.default.debug('log level is debug');
|
|
41
|
+
isLevel = log_1.default.isLevelEnabled("error");
|
|
42
|
+
expect(isLevel).toEqual(true);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -10,8 +10,9 @@ beforeAll(async () => {
|
|
|
10
10
|
conf.setUser('root');
|
|
11
11
|
conf.setPwd('taosdata');
|
|
12
12
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
13
|
-
await wsSql.exec('
|
|
14
|
-
await wsSql.exec('
|
|
13
|
+
await wsSql.exec('drop database if exists power_schemaless;');
|
|
14
|
+
await wsSql.exec('create database if not exists power_schemaless KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
|
|
15
|
+
await wsSql.exec('CREATE STABLE if not exists power_schemaless.meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);');
|
|
15
16
|
await wsSql.close();
|
|
16
17
|
});
|
|
17
18
|
describe('TDWebSocket.WsSchemaless()', () => {
|
|
@@ -23,7 +24,7 @@ describe('TDWebSocket.WsSchemaless()', () => {
|
|
|
23
24
|
let conf = new config_1.WSConfig(dns);
|
|
24
25
|
conf.setUser('root');
|
|
25
26
|
conf.setPwd('taosdata');
|
|
26
|
-
conf.setDb('
|
|
27
|
+
conf.setDb('power_schemaless');
|
|
27
28
|
let wsSchemaless = await wsSql_1.WsSql.open(conf);
|
|
28
29
|
expect(wsSchemaless.state()).toBeGreaterThan(0);
|
|
29
30
|
await wsSchemaless.close();
|
|
@@ -52,7 +53,7 @@ describe('TDWebSocket.WsSchemaless()', () => {
|
|
|
52
53
|
let conf = new config_1.WSConfig(dns);
|
|
53
54
|
conf.setUser('root');
|
|
54
55
|
conf.setPwd('taosdata');
|
|
55
|
-
conf.setDb('
|
|
56
|
+
conf.setDb('power_schemaless');
|
|
56
57
|
let wsSchemaless = await wsSql_1.WsSql.open(conf);
|
|
57
58
|
expect(wsSchemaless.state()).toBeGreaterThan(0);
|
|
58
59
|
await wsSchemaless.schemalessInsert([influxdbData], wsProto_1.SchemalessProto.InfluxDBLineProtocol, wsProto_1.Precision.NANO_SECONDS, 0);
|
|
@@ -64,7 +65,7 @@ describe('TDWebSocket.WsSchemaless()', () => {
|
|
|
64
65
|
let conf = new config_1.WSConfig(dns);
|
|
65
66
|
conf.setUser('root');
|
|
66
67
|
conf.setPwd('taosdata');
|
|
67
|
-
conf.setDb('
|
|
68
|
+
conf.setDb('power_schemaless');
|
|
68
69
|
let wsSchemaless = await wsSql_1.WsSql.open(conf);
|
|
69
70
|
expect(wsSchemaless.state()).toBeGreaterThan(0);
|
|
70
71
|
await wsSchemaless.schemalessInsert([influxdbData], wsProto_1.SchemalessProto.InfluxDBLineProtocol, wsProto_1.Precision.NOT_CONFIGURED, 0);
|
|
@@ -77,7 +78,7 @@ describe('TDWebSocket.WsSchemaless()', () => {
|
|
|
77
78
|
let conf = new config_1.WSConfig(dns);
|
|
78
79
|
conf.setUser('root');
|
|
79
80
|
conf.setPwd('taosdata');
|
|
80
|
-
conf.setDb('
|
|
81
|
+
conf.setDb('power_schemaless');
|
|
81
82
|
let wsSchemaless = await wsSql_1.WsSql.open(conf);
|
|
82
83
|
expect(wsSchemaless.state()).toBeGreaterThan(0);
|
|
83
84
|
try {
|
|
@@ -3,8 +3,8 @@ 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
5
|
const wsSql_1 = require("../../src/sql/wsSql");
|
|
6
|
+
let dns = 'ws://localhost:6041';
|
|
6
7
|
beforeAll(async () => {
|
|
7
|
-
let dns = 'ws://localhost:6041';
|
|
8
8
|
let conf = new config_1.WSConfig(dns);
|
|
9
9
|
conf.setUser('root');
|
|
10
10
|
conf.setPwd('taosdata');
|
|
@@ -17,9 +17,10 @@ beforeAll(async () => {
|
|
|
17
17
|
describe('TDWebSocket.WsSql()', () => {
|
|
18
18
|
jest.setTimeout(20 * 1000);
|
|
19
19
|
test('normal connect', async () => {
|
|
20
|
-
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
21
20
|
let wsSql = null;
|
|
22
|
-
let conf = new config_1.WSConfig(
|
|
21
|
+
let conf = new config_1.WSConfig(dns);
|
|
22
|
+
conf.setUser('root');
|
|
23
|
+
conf.setPwd('taosdata');
|
|
23
24
|
conf.setDb('power');
|
|
24
25
|
wsSql = await wsSql_1.WsSql.open(conf);
|
|
25
26
|
expect(wsSql.state()).toBeGreaterThan(0);
|
|
@@ -29,8 +30,9 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
29
30
|
expect.assertions(1);
|
|
30
31
|
let wsSql = null;
|
|
31
32
|
try {
|
|
32
|
-
let
|
|
33
|
-
|
|
33
|
+
let conf = new config_1.WSConfig(dns);
|
|
34
|
+
conf.setUser('root');
|
|
35
|
+
conf.setPwd('taosdata');
|
|
34
36
|
conf.setDb('jest');
|
|
35
37
|
wsSql = await wsSql_1.WsSql.open(conf);
|
|
36
38
|
}
|
|
@@ -45,8 +47,9 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
45
47
|
}
|
|
46
48
|
});
|
|
47
49
|
test('get taosc version', async () => {
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
+
let conf = new config_1.WSConfig(dns);
|
|
51
|
+
conf.setUser('root');
|
|
52
|
+
conf.setPwd('taosdata');
|
|
50
53
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
51
54
|
let version = await wsSql.version();
|
|
52
55
|
await wsSql.close();
|
|
@@ -54,8 +57,9 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
54
57
|
expect(version).toBeTruthy();
|
|
55
58
|
});
|
|
56
59
|
test('show databases', async () => {
|
|
57
|
-
let
|
|
58
|
-
|
|
60
|
+
let conf = new config_1.WSConfig(dns);
|
|
61
|
+
conf.setUser('root');
|
|
62
|
+
conf.setPwd('taosdata');
|
|
59
63
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
60
64
|
let taosResult = await wsSql.exec('show databases');
|
|
61
65
|
await wsSql.close();
|
|
@@ -63,8 +67,9 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
63
67
|
expect(taosResult).toBeTruthy();
|
|
64
68
|
});
|
|
65
69
|
test('create databases', async () => {
|
|
66
|
-
let
|
|
67
|
-
|
|
70
|
+
let conf = new config_1.WSConfig(dns);
|
|
71
|
+
conf.setUser('root');
|
|
72
|
+
conf.setPwd('taosdata');
|
|
68
73
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
69
74
|
let taosResult = await wsSql.exec('create database if not exists power KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
|
|
70
75
|
await wsSql.close();
|
|
@@ -72,8 +77,9 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
72
77
|
expect(taosResult).toBeTruthy();
|
|
73
78
|
});
|
|
74
79
|
test('create stable', async () => {
|
|
75
|
-
let
|
|
76
|
-
|
|
80
|
+
let conf = new config_1.WSConfig(dns);
|
|
81
|
+
conf.setUser('root');
|
|
82
|
+
conf.setPwd('taosdata');
|
|
77
83
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
78
84
|
let taosResult = await wsSql.exec('use power');
|
|
79
85
|
console.log(taosResult);
|
|
@@ -84,22 +90,24 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
84
90
|
expect(taosResult).toBeTruthy();
|
|
85
91
|
});
|
|
86
92
|
test('insert recoder', async () => {
|
|
87
|
-
let
|
|
88
|
-
|
|
93
|
+
let conf = new config_1.WSConfig(dns);
|
|
94
|
+
conf.setUser('root');
|
|
95
|
+
conf.setPwd('taosdata');
|
|
89
96
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
90
97
|
let taosResult = await wsSql.exec('use power');
|
|
91
98
|
console.log(taosResult);
|
|
92
99
|
expect(taosResult).toBeTruthy();
|
|
93
100
|
taosResult = await wsSql.exec('describe meters');
|
|
94
101
|
console.log(taosResult);
|
|
95
|
-
taosResult = await wsSql.exec('INSERT INTO d1001 USING meters (location, groupid) TAGS ("California
|
|
102
|
+
taosResult = await wsSql.exec('INSERT INTO d1001 USING meters (location, groupid) TAGS ("California", 3) VALUES (NOW, 10.2, 219, 0.32)');
|
|
96
103
|
console.log(taosResult);
|
|
97
104
|
expect(taosResult.getAffectRows()).toBeGreaterThanOrEqual(1);
|
|
98
105
|
await wsSql.close();
|
|
99
106
|
});
|
|
100
107
|
test('query sql', async () => {
|
|
101
|
-
let
|
|
102
|
-
|
|
108
|
+
let conf = new config_1.WSConfig(dns);
|
|
109
|
+
conf.setUser('root');
|
|
110
|
+
conf.setPwd('taosdata');
|
|
103
111
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
104
112
|
let taosResult = await wsSql.exec('use power');
|
|
105
113
|
console.log(taosResult);
|
|
@@ -118,6 +126,18 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
118
126
|
}
|
|
119
127
|
await wsSql.close();
|
|
120
128
|
});
|
|
129
|
+
test('query sql no getdata', async () => {
|
|
130
|
+
let conf = new config_1.WSConfig(dns);
|
|
131
|
+
conf.setUser('root');
|
|
132
|
+
conf.setPwd('taosdata');
|
|
133
|
+
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
134
|
+
let taosResult = await wsSql.exec('use power');
|
|
135
|
+
console.log(taosResult);
|
|
136
|
+
expect(taosResult).toBeTruthy();
|
|
137
|
+
let wsRows = await wsSql.query('select * from meters');
|
|
138
|
+
await wsRows.close();
|
|
139
|
+
await wsSql.close();
|
|
140
|
+
});
|
|
121
141
|
});
|
|
122
142
|
afterAll(async () => {
|
|
123
143
|
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
@@ -3,8 +3,8 @@ 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
5
|
const wsSql_1 = require("../../src/sql/wsSql");
|
|
6
|
+
let dns = 'ws://localhost:6041';
|
|
6
7
|
beforeAll(async () => {
|
|
7
|
-
let dns = 'ws://localhost:6041';
|
|
8
8
|
let conf = new config_1.WSConfig(dns);
|
|
9
9
|
conf.setUser('root');
|
|
10
10
|
conf.setPwd('taosdata');
|
|
@@ -15,7 +15,7 @@ beforeAll(async () => {
|
|
|
15
15
|
});
|
|
16
16
|
describe('TDWebSocket.Stmt()', () => {
|
|
17
17
|
jest.setTimeout(20 * 1000);
|
|
18
|
-
let tags = ['California
|
|
18
|
+
let tags = ['California', 3];
|
|
19
19
|
let multi = [
|
|
20
20
|
// [1709183268567],
|
|
21
21
|
// [10.2],
|
|
@@ -27,10 +27,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
27
27
|
[0.32, 0.33, 0.34],
|
|
28
28
|
];
|
|
29
29
|
test('normal connect', async () => {
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
let conf = new config_1.WSConfig(dns);
|
|
31
|
+
conf.setUser('root');
|
|
32
|
+
conf.setPwd('taosdata');
|
|
33
|
+
conf.setDb('power');
|
|
34
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
34
35
|
let stmt = await connector.stmtInit();
|
|
35
36
|
expect(stmt).toBeTruthy();
|
|
36
37
|
expect(connector.state()).toBeGreaterThan(0);
|
|
@@ -41,10 +42,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
41
42
|
expect.assertions(1);
|
|
42
43
|
let connector = null;
|
|
43
44
|
try {
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
let conf = new config_1.WSConfig(dns);
|
|
46
|
+
conf.setUser('root');
|
|
47
|
+
conf.setPwd('taosdata');
|
|
48
|
+
conf.setDb('jest');
|
|
49
|
+
connector = await wsSql_1.WsSql.open(conf);
|
|
48
50
|
let stmt = await connector.stmtInit();
|
|
49
51
|
await stmt.close();
|
|
50
52
|
}
|
|
@@ -59,10 +61,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
59
61
|
}
|
|
60
62
|
});
|
|
61
63
|
test('normal Prepare', async () => {
|
|
62
|
-
let
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
let conf = new config_1.WSConfig(dns);
|
|
65
|
+
conf.setUser('root');
|
|
66
|
+
conf.setPwd('taosdata');
|
|
67
|
+
conf.setDb('power');
|
|
68
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
66
69
|
let stmt = await connector.stmtInit();
|
|
67
70
|
expect(stmt).toBeTruthy();
|
|
68
71
|
expect(connector.state()).toBeGreaterThan(0);
|
|
@@ -76,10 +79,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
76
79
|
await connector.close();
|
|
77
80
|
});
|
|
78
81
|
test('set tag error', async () => {
|
|
79
|
-
let
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
let conf = new config_1.WSConfig(dns);
|
|
83
|
+
conf.setUser('root');
|
|
84
|
+
conf.setPwd('taosdata');
|
|
85
|
+
conf.setDb('power');
|
|
86
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
83
87
|
let stmt = await connector.stmtInit();
|
|
84
88
|
expect(stmt).toBeTruthy();
|
|
85
89
|
expect(connector.state()).toBeGreaterThan(0);
|
|
@@ -97,10 +101,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
97
101
|
await connector.close();
|
|
98
102
|
});
|
|
99
103
|
test('error Prepare table', async () => {
|
|
100
|
-
let
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
+
let conf = new config_1.WSConfig(dns);
|
|
105
|
+
conf.setUser('root');
|
|
106
|
+
conf.setPwd('taosdata');
|
|
107
|
+
conf.setDb('power');
|
|
108
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
104
109
|
let stmt = await connector.stmtInit();
|
|
105
110
|
expect(stmt).toBeTruthy();
|
|
106
111
|
expect(connector.state()).toBeGreaterThan(0);
|
|
@@ -116,10 +121,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
116
121
|
await connector.close();
|
|
117
122
|
});
|
|
118
123
|
test('error Prepare tag', async () => {
|
|
119
|
-
let
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
let conf = new config_1.WSConfig(dns);
|
|
125
|
+
conf.setUser('root');
|
|
126
|
+
conf.setPwd('taosdata');
|
|
127
|
+
conf.setDb('power');
|
|
128
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
123
129
|
let stmt = await connector.stmtInit();
|
|
124
130
|
expect(stmt).toBeTruthy();
|
|
125
131
|
expect(connector.state()).toBeGreaterThan(0);
|
|
@@ -135,12 +141,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
135
141
|
await connector.close();
|
|
136
142
|
});
|
|
137
143
|
test('normal BindParam', async () => {
|
|
138
|
-
let
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
let connector = await wsSql_1.WsSql.open(wsConf);
|
|
144
|
+
let conf = new config_1.WSConfig(dns);
|
|
145
|
+
conf.setUser('root');
|
|
146
|
+
conf.setPwd('taosdata');
|
|
147
|
+
conf.setDb('power');
|
|
148
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
144
149
|
let stmt = await connector.stmtInit();
|
|
145
150
|
expect(stmt).toBeTruthy();
|
|
146
151
|
await stmt.prepare('INSERT INTO ? USING power.meters (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)');
|
|
@@ -172,10 +177,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
172
177
|
await connector.close();
|
|
173
178
|
});
|
|
174
179
|
test('error BindParam', async () => {
|
|
175
|
-
let
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
180
|
+
let conf = new config_1.WSConfig(dns);
|
|
181
|
+
conf.setUser('root');
|
|
182
|
+
conf.setPwd('taosdata');
|
|
183
|
+
conf.setDb('power');
|
|
184
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
179
185
|
let stmt = await connector.stmtInit();
|
|
180
186
|
expect(stmt).toBeTruthy();
|
|
181
187
|
expect(connector.state()).toBeGreaterThan(0);
|
|
@@ -209,10 +215,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
209
215
|
await connector.close();
|
|
210
216
|
});
|
|
211
217
|
test('no Batch', async () => {
|
|
212
|
-
let
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
218
|
+
let conf = new config_1.WSConfig(dns);
|
|
219
|
+
conf.setUser('root');
|
|
220
|
+
conf.setPwd('taosdata');
|
|
221
|
+
conf.setDb('power');
|
|
222
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
216
223
|
let stmt = await connector.stmtInit();
|
|
217
224
|
expect(stmt).toBeTruthy();
|
|
218
225
|
expect(connector.state()).toBeGreaterThan(0);
|
|
@@ -245,10 +252,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
245
252
|
await connector.close();
|
|
246
253
|
});
|
|
247
254
|
test('Batch after BindParam', async () => {
|
|
248
|
-
let
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
255
|
+
let conf = new config_1.WSConfig(dns);
|
|
256
|
+
conf.setUser('root');
|
|
257
|
+
conf.setPwd('taosdata');
|
|
258
|
+
conf.setDb('power');
|
|
259
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
252
260
|
let stmt = await connector.stmtInit();
|
|
253
261
|
expect(stmt).toBeTruthy();
|
|
254
262
|
expect(connector.state()).toBeGreaterThan(0);
|
|
@@ -277,6 +285,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
277
285
|
dataParams.setFloat(multi1[3]);
|
|
278
286
|
await stmt.bind(dataParams);
|
|
279
287
|
await stmt.batch();
|
|
288
|
+
await stmt.setTableName('d1002');
|
|
289
|
+
params = stmt.newStmtParam();
|
|
290
|
+
params.setVarchar(['SanFrancisco']);
|
|
291
|
+
params.setInt([5]);
|
|
292
|
+
await stmt.setTags(params);
|
|
280
293
|
dataParams = stmt.newStmtParam();
|
|
281
294
|
dataParams.setTimestamp(multi2[0]);
|
|
282
295
|
dataParams.setFloat(multi2[1]);
|
|
@@ -290,10 +303,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
290
303
|
await connector.close();
|
|
291
304
|
});
|
|
292
305
|
test('no set tag', async () => {
|
|
293
|
-
let
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
306
|
+
let conf = new config_1.WSConfig(dns);
|
|
307
|
+
conf.setUser('root');
|
|
308
|
+
conf.setPwd('taosdata');
|
|
309
|
+
conf.setDb('power');
|
|
310
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
297
311
|
let stmt = await connector.stmtInit();
|
|
298
312
|
expect(stmt).toBeTruthy();
|
|
299
313
|
expect(connector.state()).toBeGreaterThan(0);
|
|
@@ -318,10 +332,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
318
332
|
await connector.close();
|
|
319
333
|
});
|
|
320
334
|
test('normal binary BindParam', async () => {
|
|
321
|
-
let
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
335
|
+
let conf = new config_1.WSConfig(dns);
|
|
336
|
+
conf.setUser('root');
|
|
337
|
+
conf.setPwd('taosdata');
|
|
338
|
+
conf.setDb('power');
|
|
339
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
325
340
|
let stmt = await connector.stmtInit();
|
|
326
341
|
expect(stmt).toBeTruthy();
|
|
327
342
|
expect(connector.state()).toBeGreaterThan(0);
|
|
@@ -345,10 +360,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
345
360
|
await connector.close();
|
|
346
361
|
});
|
|
347
362
|
test('normal json BindParam', async () => {
|
|
348
|
-
let
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
363
|
+
let conf = new config_1.WSConfig(dns);
|
|
364
|
+
conf.setUser('root');
|
|
365
|
+
conf.setPwd('taosdata');
|
|
366
|
+
conf.setDb('power');
|
|
367
|
+
let connector = await wsSql_1.WsSql.open(conf);
|
|
352
368
|
let stmt = await connector.stmtInit();
|
|
353
369
|
expect(stmt).toBeTruthy();
|
|
354
370
|
expect(connector.state()).toBeGreaterThan(0);
|
|
@@ -70,8 +70,8 @@ const selectTable = `select * from ${table}`;
|
|
|
70
70
|
const selectTableCN = `select * from ${tableCN}`;
|
|
71
71
|
const selectJsonTable = `select * from ${jsonTable}`;
|
|
72
72
|
const selectJsonTableCN = `select * from ${jsonTableCN}`;
|
|
73
|
+
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
73
74
|
beforeAll(async () => {
|
|
74
|
-
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
75
75
|
let conf = new config_1.WSConfig(dsn);
|
|
76
76
|
let ws = await wsSql_1.WsSql.open(conf);
|
|
77
77
|
await ws.exec(dropDB);
|
|
@@ -84,7 +84,6 @@ beforeAll(async () => {
|
|
|
84
84
|
describe('TDWebSocket.Stmt()', () => {
|
|
85
85
|
jest.setTimeout(20 * 1000);
|
|
86
86
|
test('normal BindParam', async () => {
|
|
87
|
-
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
88
87
|
let wsConf = new config_1.WSConfig(dsn);
|
|
89
88
|
wsConf.setDb(db);
|
|
90
89
|
let connector = await wsSql_1.WsSql.open(wsConf);
|
|
@@ -136,7 +135,6 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
136
135
|
await connector.close();
|
|
137
136
|
});
|
|
138
137
|
test('normal CN BindParam', async () => {
|
|
139
|
-
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
140
138
|
let wsConf = new config_1.WSConfig(dsn);
|
|
141
139
|
wsConf.setDb(db);
|
|
142
140
|
let connector = await wsSql_1.WsSql.open(wsConf);
|
|
@@ -188,7 +186,6 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
188
186
|
await connector.close();
|
|
189
187
|
});
|
|
190
188
|
test('normal json tag BindParam', async () => {
|
|
191
|
-
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
192
189
|
let wsConf = new config_1.WSConfig(dsn);
|
|
193
190
|
wsConf.setDb(db);
|
|
194
191
|
let connector = await wsSql_1.WsSql.open(wsConf);
|
|
@@ -228,7 +225,6 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
228
225
|
await connector.close();
|
|
229
226
|
});
|
|
230
227
|
test('normal json cn tag BindParam', async () => {
|
|
231
|
-
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
232
228
|
let wsConf = new config_1.WSConfig(dsn);
|
|
233
229
|
wsConf.setDb(db);
|
|
234
230
|
let connector = await wsSql_1.WsSql.open(wsConf);
|