@tdengine/websocket 3.1.3 → 3.1.4
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/logs/.007e668bb78549e9a304b8466671945ab2a1553e-audit.json +15 -0
- package/lib/example/logs/app-2025-01-24.log +5580 -0
- package/lib/src/client/wsConnectorPool.d.ts.map +1 -1
- package/lib/src/client/wsConnectorPool.js +2 -1
- package/lib/src/common/log.js +1 -2
- package/lib/src/common/taosResult.js +12 -12
- package/lib/src/common/ut8Helper.js +1 -2
- package/lib/src/common/utils.d.ts +0 -1
- package/lib/src/common/utils.d.ts.map +1 -1
- package/lib/src/common/utils.js +4 -9
- package/lib/src/index.d.ts.map +1 -1
- package/lib/src/index.js +17 -7
- package/lib/src/stmt/wsProto.js +2 -2
- package/lib/test/bulkPulling/log.test.js +17 -7
- package/lib/test/bulkPulling/queryTables.test.js +3 -0
- package/lib/test/bulkPulling/schemaless.test.js +6 -0
- package/lib/test/bulkPulling/sql.test.js +9 -1
- package/lib/test/bulkPulling/stmt.func.test.js +34 -28
- package/lib/test/bulkPulling/stmt.type.test.js +4 -0
- package/lib/test/bulkPulling/tmq.test.js +6 -0
- package/lib/test/bulkPulling/wsConnectPool.test.js +17 -5
- package/lib/test/utils.d.ts +1 -0
- package/lib/test/utils.d.ts.map +1 -1
- package/lib/test/utils.js +17 -13
- package/package.json +1 -1
- package/readme.md +82 -270
package/lib/test/utils.d.ts
CHANGED
|
@@ -14,4 +14,5 @@ export declare function createTable(table: string): string;
|
|
|
14
14
|
export declare function expectStableData(rows: Array<Array<any>>, tags: Array<any>): Array<Array<any>>;
|
|
15
15
|
export declare function hexToBytes(hex: string): ArrayBuffer;
|
|
16
16
|
export declare function compareUint8Arrays(arr1: Uint8Array, arr2: Uint8Array): boolean;
|
|
17
|
+
export declare function Sleep(ms: number): Promise<void>;
|
|
17
18
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/test/utils.d.ts.map
CHANGED
|
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AY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGnD;AACD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGvD;AACD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjD;AAID,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAM7F;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAQnD;AAqBD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAY9E;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C"}
|
package/lib/test/utils.js
CHANGED
|
@@ -3,7 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.tagMeta = exports.jsonMeta = exports.tableMeta = void 0;
|
|
7
|
+
exports.getInsertBind = getInsertBind;
|
|
8
|
+
exports.insertStable = insertStable;
|
|
9
|
+
exports.insertNTable = insertNTable;
|
|
10
|
+
exports.createBaseSTable = createBaseSTable;
|
|
11
|
+
exports.createBaseSTableJSON = createBaseSTableJSON;
|
|
12
|
+
exports.createBaseTable = createBaseTable;
|
|
13
|
+
exports.createSTable = createSTable;
|
|
14
|
+
exports.createSTableJSON = createSTableJSON;
|
|
15
|
+
exports.createTable = createTable;
|
|
16
|
+
exports.expectStableData = expectStableData;
|
|
17
|
+
exports.hexToBytes = hexToBytes;
|
|
18
|
+
exports.compareUint8Arrays = compareUint8Arrays;
|
|
19
|
+
exports.Sleep = Sleep;
|
|
7
20
|
const log_1 = __importDefault(require("../src/common/log"));
|
|
8
21
|
function getInsertBind(valuesLen, tagsLen, db, stable) {
|
|
9
22
|
let sql = `insert into ? using ${db}.${stable} tags ( ?`;
|
|
@@ -17,7 +30,6 @@ function getInsertBind(valuesLen, tagsLen, db, stable) {
|
|
|
17
30
|
sql += ')';
|
|
18
31
|
return sql;
|
|
19
32
|
}
|
|
20
|
-
exports.getInsertBind = getInsertBind;
|
|
21
33
|
function insertStable(values, tags, stable, table = 'empty') {
|
|
22
34
|
let childTable = table == 'empty' ? stable + '_s_01' : table;
|
|
23
35
|
let sql = `insert into ${childTable} using ${stable} tags (`;
|
|
@@ -54,7 +66,6 @@ function insertStable(values, tags, stable, table = 'empty') {
|
|
|
54
66
|
});
|
|
55
67
|
return sql;
|
|
56
68
|
}
|
|
57
|
-
exports.insertStable = insertStable;
|
|
58
69
|
function insertNTable(values, table) {
|
|
59
70
|
let sql = `insert into ${table} values `;
|
|
60
71
|
values.forEach(value => {
|
|
@@ -78,7 +89,6 @@ function insertNTable(values, table) {
|
|
|
78
89
|
});
|
|
79
90
|
return sql;
|
|
80
91
|
}
|
|
81
|
-
exports.insertNTable = insertNTable;
|
|
82
92
|
exports.tableMeta = [
|
|
83
93
|
{
|
|
84
94
|
name: 'ts',
|
|
@@ -244,30 +254,24 @@ function createBaseSTable(stable) {
|
|
|
244
254
|
return `create table if not exists ${stable}( ts timestamp,i1 tinyint,i2 smallint,i4 int,i8 bigint,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,f4 float,d8 double,bnr binary(200),nchr nchar(200),b bool,nilcol int, g1 geometry(512), c4 varbinary(100))` +
|
|
245
255
|
'tags( tb bool,ti1 tinyint,ti2 smallint,ti4 int,ti8 bigint,tu1 tinyint unsigned,tu2 smallint unsigned,tu4 int unsigned,tu8 bigint unsigned,tf4 float,td8 double,tbnr binary(200),tnchr nchar(200));';
|
|
246
256
|
}
|
|
247
|
-
exports.createBaseSTable = createBaseSTable;
|
|
248
257
|
function createBaseSTableJSON(stable) {
|
|
249
258
|
return `create table if not exists ${stable}(ts timestamp,i1 tinyint,i2 smallint,i4 int,i8 bigint,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,f4 float,d8 double,bnr binary(200),nchr nchar(200),b bool,nilcol int)` +
|
|
250
259
|
'tags(json_tag json);';
|
|
251
260
|
}
|
|
252
|
-
exports.createBaseSTableJSON = createBaseSTableJSON;
|
|
253
261
|
function createBaseTable(table) {
|
|
254
262
|
return `create table if not exists ${table}(ts timestamp,i1 tinyint,i2 smallint,i4 int,i8 bigint,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,f4 float,d8 double,bnr binary(200),nchr nchar(200),b bool,nilcol int)`;
|
|
255
263
|
}
|
|
256
|
-
exports.createBaseTable = createBaseTable;
|
|
257
264
|
function createSTable(stable) {
|
|
258
265
|
return `create table if not exists ${stable}( ts timestamp,i1 tinyint,i2 smallint,i4 int,i8 bigint,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,f4 float,d8 double,bnr binary(200),nchr nchar(200),b bool,nilcol int, geo geometry(512), vbinary varbinary(32))` +
|
|
259
266
|
'tags( tb bool,ti1 tinyint,ti2 smallint,ti4 int,ti8 bigint,tu1 tinyint unsigned,tu2 smallint unsigned,tu4 int unsigned,tu8 bigint unsigned,tf4 float,td8 double,tbnr binary(200),tnchr nchar(200));';
|
|
260
267
|
}
|
|
261
|
-
exports.createSTable = createSTable;
|
|
262
268
|
function createSTableJSON(stable) {
|
|
263
269
|
return `create table if not exists ${stable}(ts timestamp,i1 tinyint,i2 smallint,i4 int,i8 bigint,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,f4 float,d8 double,bnr binary(200),nchr nchar(200),b bool,nilcol int, geo geometry(512), vbinary varbinary(32))` +
|
|
264
270
|
'tags(json_tag json);';
|
|
265
271
|
}
|
|
266
|
-
exports.createSTableJSON = createSTableJSON;
|
|
267
272
|
function createTable(table) {
|
|
268
273
|
return `create table if not exists ${table}(ts timestamp,i1 tinyint,i2 smallint,i4 int,i8 bigint,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,f4 float,d8 double,bnr binary(200),nchr nchar(200),b bool,nilcol int, geo geometry(512), vbinary varbinary(32))`;
|
|
269
274
|
}
|
|
270
|
-
exports.createTable = createTable;
|
|
271
275
|
function expectStableData(rows, tags) {
|
|
272
276
|
let resArr = [];
|
|
273
277
|
rows.forEach((row, index, rows) => {
|
|
@@ -275,7 +279,6 @@ function expectStableData(rows, tags) {
|
|
|
275
279
|
});
|
|
276
280
|
return resArr;
|
|
277
281
|
}
|
|
278
|
-
exports.expectStableData = expectStableData;
|
|
279
282
|
function hexToBytes(hex) {
|
|
280
283
|
let byteLen = hex.length / 2;
|
|
281
284
|
let a = new Uint8Array(byteLen);
|
|
@@ -285,7 +288,6 @@ function hexToBytes(hex) {
|
|
|
285
288
|
}
|
|
286
289
|
return a.buffer;
|
|
287
290
|
}
|
|
288
|
-
exports.hexToBytes = hexToBytes;
|
|
289
291
|
// export function createStmtData(varbinary:string = "ab",
|
|
290
292
|
// geoHex:string = "0101000020E6100000000000000000F03F0000000000000040"):Array<Array<any>> {
|
|
291
293
|
// let multi:any[][] = [
|
|
@@ -315,4 +317,6 @@ function compareUint8Arrays(arr1, arr2) {
|
|
|
315
317
|
}
|
|
316
318
|
return true;
|
|
317
319
|
}
|
|
318
|
-
|
|
320
|
+
function Sleep(ms) {
|
|
321
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
322
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tdengine/websocket",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "The websocket Node.js connector for TDengine. TDengine versions 3.3.2.0 and above are recommended to use this connector.",
|
|
5
5
|
"source": "index.ts",
|
|
6
6
|
"main": "lib/index.js",
|
package/readme.md
CHANGED
|
@@ -1,302 +1,114 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- omit in toc -->
|
|
2
|
+
# TDengine Node.js Connector
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
[](https://github.com/taosdata/taos-connector-node/actions/workflows/build.yaml)
|
|
5
|
+
[](https://codecov.io/gh/taosdata/taos-connector-node)
|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
[](https://www.npmjs.com/package/@tdengine/websocket)
|
|
9
|
+
<br />
|
|
10
|
+
[](https://twitter.com/tdenginedb)
|
|
11
|
+
[](https://www.youtube.com/@tdengine)
|
|
12
|
+
[](https://discord.com/invite/VZdSuUg4pS)
|
|
13
|
+
[](https://www.linkedin.com/company/tdengine)
|
|
14
|
+
[](https://stackoverflow.com/questions/tagged/tdengine)
|
|
4
15
|
|
|
5
|
-
|
|
16
|
+
English | [简体中文](README-CN.md)
|
|
17
|
+
<!-- omit in toc -->
|
|
18
|
+
## Table of Contents
|
|
19
|
+
<!-- omit in toc -->
|
|
6
20
|
|
|
7
|
-
|
|
21
|
+
- [1. Introduction](#1-introduction)
|
|
22
|
+
- [2. Documentation](#2-documentation)
|
|
23
|
+
- [3. Prerequisites](#3-prerequisites)
|
|
24
|
+
- [4. Build](#4-build)
|
|
25
|
+
- [5. Testing](#5-testing)
|
|
26
|
+
- [5.1 Test Execution](#51-test-execution)
|
|
27
|
+
- [5.2 Test Case Addition](#52-test-case-addition)
|
|
28
|
+
- [5.3 Performance Testing](#53-performance-testing)
|
|
29
|
+
- [6. CI/CD](#6-cicd)
|
|
30
|
+
- [7. Submitting Issues](#7-submitting-issues)
|
|
31
|
+
- [8. Submitting PRs](#8-submitting-prs)
|
|
32
|
+
- [9. References](#9-references)
|
|
33
|
+
- [10. License](#10-license)
|
|
8
34
|
|
|
9
|
-
|
|
10
|
-
[+<protocol>]://[[<username>:<password>@]<host>:<port>][/<database>][?<p1>=<v1>[&<p2>=<v2>]]
|
|
11
|
-
|------------|---|-----------|-----------|------|------|------------|-----------------------|
|
|
12
|
-
| protocol | | username | password | host | port | database | params |
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
- **protocol**: Display using websocket protocol to establish connection. eg. `ws://localhost:6041`
|
|
16
|
-
- **username/password**: Database's username and password.
|
|
17
|
-
- **host/port**: Declare host and port. eg. `localhost:6041`
|
|
18
|
-
- **database**: Optional, use to specify database name.
|
|
19
|
-
- **params**: Other parameters. Like cloud Token.
|
|
20
|
-
|
|
21
|
-
A complete DSN string example:
|
|
22
|
-
|
|
23
|
-
```text
|
|
24
|
-
ws://localhost:6041/test
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Connection types
|
|
28
|
-
|
|
29
|
-
**Node.js websocket connector** which is implemented through taosAdapter.
|
|
30
|
-
|
|
31
|
-
## Supported platforms
|
|
32
|
-
|
|
33
|
-
Node.js client library supports Node.js 14 or higher.
|
|
34
|
-
|
|
35
|
-
## Supported features
|
|
35
|
+
## 1. Introduction
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
2. General Query
|
|
39
|
-
3. Continuous Query
|
|
40
|
-
4. Parameter Binding
|
|
41
|
-
5. Subscription
|
|
42
|
-
6. Schemaless
|
|
37
|
+
@tdengine/websocket is an efficient connector specially designed by TDengine for Node.js developers. It uses the WebSocket API provided by the taosAdapter component to establish a connection with TDengine, eliminating the dependence on TDengine client drivers and opening up a convenient development path for developers. With this powerful tool, developers can easily build applications for TDengine clusters. Whether it is performing complex SQL write and query tasks, implementing flexible schemaless write operations, or achieving highly real-time subscription functionality, this connector can easily and perfectly meet diverse data interaction needs in all aspects.
|
|
43
38
|
|
|
44
|
-
|
|
39
|
+
## 2. Documentation
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
- To use Node.js connector, please refer to the [Developer Guide](https://docs.tdengine.com/developer-guide/), which includes instructions on how to integrate `@tdengine/websocket` into an application, along with examples of data writing, querying, schemaless writing, parameter binding, and data subscription.
|
|
42
|
+
- For other reference information, please check [Reference Manual](https://docs.tdengine.com/tdengine-reference/client-libraries/node/), which includes version history, data types, example programs, API descriptions, and FAQs.
|
|
43
|
+
- This quick guide is primarily for developers who wish to contribute, build, and test the Node.js connector on their own. To learn about TDengine, you can visit the [official documentation](https://docs.tdengine.com).
|
|
49
44
|
|
|
50
|
-
|
|
51
|
-
(async () => {
|
|
52
|
-
let wsSql = null;
|
|
53
|
-
let wsRows = null;
|
|
54
|
-
let reqId = 0;
|
|
55
|
-
try {
|
|
56
|
-
setLogLevel("debug")
|
|
57
|
-
let conf :WSConfig = new WSConfig(dsn)
|
|
58
|
-
conf.setUser('root')
|
|
59
|
-
conf.setPwd('taosdata')
|
|
60
|
-
wsSql = await sqlConnect(conf)
|
|
45
|
+
## 3. Prerequisites
|
|
61
46
|
|
|
62
|
-
|
|
63
|
-
|
|
47
|
+
- Install the Node.js development environment, using version 14 or above. Download link: [https://nodejs.org/en/download/](https://nodejs.org/en/download/)
|
|
48
|
+
- Install the Node.js connector dependencies using npm, execute the 'npm install' command in the `nodejs` directory of the project for installation.
|
|
49
|
+
- Install TypeScript 5.3.3 and above using npm.
|
|
50
|
+
- TDengine has been deployed locally. For specific steps, please refer to [Deploy TDengine](https://docs.tdengine.com/get-started/deploy-from-package/). Please make sure `taosd` and `taosAdapter` have been started.
|
|
64
51
|
|
|
65
|
-
|
|
66
|
-
console.log(taosResult);
|
|
52
|
+
## 4. Build
|
|
67
53
|
|
|
68
|
-
|
|
69
|
-
console.log(taosResult);
|
|
54
|
+
Execute `tsc` to build the project in the 'nodejs' directory.
|
|
70
55
|
|
|
71
|
-
|
|
72
|
-
console.log(taosResult);
|
|
56
|
+
## 5. Testing
|
|
73
57
|
|
|
74
|
-
|
|
75
|
-
console.log(taosResult);
|
|
58
|
+
### 5.1 Test Execution
|
|
76
59
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
taosResult = await wsSql.exec('INSERT INTO d1001 USING meters TAGS ("California.SanFrancisco", 3) VALUES (NOW, 10.2, 219, 0.32)', reqId++)
|
|
81
|
-
console.log(taosResult);
|
|
82
|
-
|
|
83
|
-
wsRows = await wsSql.query('select * from meters', reqId++);
|
|
84
|
-
let meta = wsRows.getMeta()
|
|
85
|
-
console.log("wsRow:meta:=>", meta);
|
|
86
|
-
|
|
87
|
-
while (await wsRows.next()) {
|
|
88
|
-
let result = wsRows.getData();
|
|
89
|
-
console.log('queryRes.Scan().then=>', result);
|
|
90
|
-
}
|
|
91
|
-
wsRows.close()
|
|
92
|
-
|
|
93
|
-
} catch (err: any) {
|
|
94
|
-
console.error(err.code, err.message);
|
|
95
|
-
|
|
96
|
-
} finally {
|
|
97
|
-
if (wsRows) {
|
|
98
|
-
await wsRows.close();
|
|
99
|
-
}
|
|
100
|
-
if (wsSql) {
|
|
101
|
-
await wsSql.close();
|
|
102
|
-
}
|
|
103
|
-
destroy()
|
|
104
|
-
console.log("finish!")
|
|
105
|
-
}
|
|
106
|
-
})();
|
|
60
|
+
Execute `npm run test` in the project directory to run the tests. The test cases will connect to the local TDengine server and taosAdapter for testing.
|
|
61
|
+
After running the tests, the result similar to the following will be printed eventually. If all test cases pass, without any failures or errors.
|
|
107
62
|
|
|
63
|
+
```text
|
|
64
|
+
Test Suites: 8 passed, 8 total
|
|
65
|
+
Tests: 1 skipped, 44 passed, 45 total
|
|
66
|
+
Snapshots: 0 total
|
|
67
|
+
Time: 20.373 s
|
|
68
|
+
Ran all test suites.
|
|
108
69
|
```
|
|
109
70
|
|
|
110
|
-
###
|
|
71
|
+
### 5.2 Test Case Addition
|
|
111
72
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
import { Precision, SchemalessProto } from '../src/sql/wsProto';
|
|
115
|
-
import { sqlConnect, destroy, setLogLevel } from '../src';
|
|
116
|
-
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
117
|
-
let db = 'power'
|
|
118
|
-
let influxdbData = "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000"
|
|
119
|
-
let telnetData = "stb0_0 1626006833 4 host=host0 interface=eth0"
|
|
120
|
-
let jsonData = "{\"metric\": \"meter_current\",\"timestamp\": 1626846400,\"value\": 10.3, \"tags\": {\"groupid\": 2, \"location\": \"California.SanFrancisco\", \"id\": \"d1001\"}}"
|
|
121
|
-
const dropDB = `drop database if exists ${db}`
|
|
73
|
+
All tests are located in the `nodejs/test/bulkPulling` directory of the project. You can add new test files or add test cases in existing test files.
|
|
74
|
+
The test cases use the jest framework. Generally, a connection is established and a database is created in the `beforeAll` method, and the database is droped and the connection is released in the `afterAll` method.
|
|
122
75
|
|
|
123
|
-
|
|
124
|
-
let conf :WSConfig = new WSConfig(dsn)
|
|
125
|
-
conf.setUser('root')
|
|
126
|
-
conf.setPwd('taosdata')
|
|
127
|
-
let wsSql = await sqlConnect(conf)
|
|
128
|
-
const topics:string[] = ['pwer_meters_topic']
|
|
129
|
-
let dropTopic = `DROP TOPIC IF EXISTS ${topics[0]};`
|
|
130
|
-
await wsSql.exec(dropTopic);
|
|
131
|
-
await wsSql.exec(dropDB);
|
|
76
|
+
### 5.3 Performance Testing
|
|
132
77
|
|
|
133
|
-
|
|
134
|
-
await wsSql.exec('CREATE STABLE if not exists power.meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);');
|
|
135
|
-
wsSql.close();
|
|
136
|
-
}
|
|
78
|
+
Performance testing is in progress.
|
|
137
79
|
|
|
138
|
-
|
|
139
|
-
let wsSchemaless = null
|
|
140
|
-
try {
|
|
141
|
-
let conf :WSConfig = new WSConfig(dsn)
|
|
142
|
-
conf.setUser('root')
|
|
143
|
-
conf.setPwd('taosdata')
|
|
144
|
-
conf.setDb('power')
|
|
145
|
-
wsSchemaless = await sqlConnect(conf)
|
|
146
|
-
await wsSchemaless.schemalessInsert([influxdbData], SchemalessProto.InfluxDBLineProtocol, Precision.NANO_SECONDS, 0);
|
|
147
|
-
await wsSchemaless.schemalessInsert([telnetData], SchemalessProto.OpenTSDBTelnetLineProtocol, Precision.SECONDS, 0);
|
|
148
|
-
await wsSchemaless.schemalessInsert([jsonData], SchemalessProto.OpenTSDBJsonFormatProtocol, Precision.SECONDS, 0);
|
|
149
|
-
wsSchemaless.close();
|
|
150
|
-
} catch (e) {
|
|
151
|
-
console.error(e);
|
|
152
|
-
}finally {
|
|
153
|
-
if (wsSchemaless) {
|
|
154
|
-
await wsSchemaless.close();
|
|
155
|
-
}
|
|
156
|
-
destroy()
|
|
157
|
-
}
|
|
158
|
-
})();
|
|
80
|
+
## 6. CI/CD
|
|
159
81
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
### Stmt Usage
|
|
163
|
-
|
|
164
|
-
``` typescript
|
|
165
|
-
import { WSConfig } from '../src/common/config';
|
|
166
|
-
import { destroy, sqlConnect } from '../src';
|
|
82
|
+
- [Build Workflow](https://github.com/taosdata/taos-connector-node/actions/workflows/build.yaml)
|
|
83
|
+
- [Code Coverage](https://app.codecov.io/gh/taosdata/taos-connector-node)
|
|
167
84
|
|
|
168
|
-
|
|
169
|
-
let stable = 'meters'
|
|
170
|
-
let tags = ['California.SanFrancisco', 3];
|
|
171
|
-
let multi = [
|
|
172
|
-
[1706786044994, 1706786044995, 1706786044996],
|
|
173
|
-
[10.2, 10.3, 10.4],
|
|
174
|
-
[292, 293, 294],
|
|
175
|
-
[0.32, 0.33, 0.34],
|
|
176
|
-
];
|
|
177
|
-
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
178
|
-
async function Prepare() {
|
|
85
|
+
## 7. Submitting Issues
|
|
179
86
|
|
|
180
|
-
|
|
181
|
-
let wsSql = await sqlConnect(conf)
|
|
182
|
-
await wsSql.exec(`create database if not exists ${db} KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;`)
|
|
183
|
-
await wsSql.exec(`CREATE STABLE if not exists ${db}.${stable} (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);`);
|
|
184
|
-
wsSql.close()
|
|
185
|
-
}
|
|
87
|
+
We welcome the submission of [GitHub Issue](https://github.com/taosdata/taos-connector-node/issues/new?template=Blank+issue). When submitting, please provide the following information:
|
|
186
88
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
let wsConf = new WSConfig(dsn);
|
|
193
|
-
wsConf.setDb(db)
|
|
194
|
-
connector = await sqlConnect(wsConf);
|
|
195
|
-
stmt = await connector.stmtInit()
|
|
196
|
-
await stmt.prepare(`INSERT INTO ? USING ${db}.${stable} (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)`);
|
|
197
|
-
await stmt.setTableName('d1001');
|
|
89
|
+
- Problem description, is it necessary to present it.
|
|
90
|
+
- Nodejs version.
|
|
91
|
+
- @tdengine/websocket version.
|
|
92
|
+
- Connection parameters (no username or password required).
|
|
93
|
+
- TDengine Server Version.
|
|
198
94
|
|
|
199
|
-
|
|
200
|
-
tagParams.setVarchar([tags[0]])
|
|
201
|
-
tagParams.setInt([tags[1]])
|
|
202
|
-
await stmt.setTags(tagParams);
|
|
203
|
-
|
|
204
|
-
let bindParams = stmt.newStmtParam()
|
|
205
|
-
bindParams.setTimestamp(multi[0]);
|
|
206
|
-
bindParams.setFloat(multi[1])
|
|
207
|
-
bindParams.setInt(multi[2])
|
|
208
|
-
bindParams.setFloat(multi[3])
|
|
209
|
-
await stmt.bind(bindParams);
|
|
210
|
-
await stmt.batch();
|
|
211
|
-
await stmt.exec();
|
|
212
|
-
} catch (e) {
|
|
213
|
-
console.error(e);
|
|
214
|
-
}finally {
|
|
215
|
-
if (stmt) {
|
|
216
|
-
await stmt.close();
|
|
217
|
-
}
|
|
218
|
-
if (connector) {
|
|
219
|
-
await connector.close();
|
|
220
|
-
}
|
|
221
|
-
destroy()
|
|
222
|
-
}
|
|
223
|
-
})();
|
|
224
|
-
|
|
225
|
-
```
|
|
95
|
+
## 8. Submitting PRs
|
|
226
96
|
|
|
227
|
-
|
|
97
|
+
We welcome developers to contribute to this project. When submitting PRs, please follow these steps:
|
|
228
98
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
99
|
+
1. Fork this project, refer to ([how to fork a repo](https://docs.github.com/en/get-started/quickstart/fork-a-repo)).
|
|
100
|
+
1. Create a new branch from the main branch with a meaningful branch name (`git checkout -b my_branch`). Do not modify the main branch directly.
|
|
101
|
+
1. Modify the code, ensure all unit tests pass, and add new unit tests to verify the changes.
|
|
102
|
+
1. Push the changes to the remote branch (`git push origin my_branch`).
|
|
103
|
+
1. Create a Pull Request on GitHub ([how to create a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)).
|
|
104
|
+
1. After submitting the PR, you can find your PR through the [Pull Request](https://github.com/taosdata/taos-connector-node/pulls). Click on the corresponding link to see if the CI for your PR has passed. If it has passed, it will display "All checks have passed". Regardless of whether the CI passes or not, you can click "Show all checks" -> "Details" to view the detailed test case logs.
|
|
105
|
+
1. After submitting the PR, if CI passes, you can find your PR on the [codecov](https://app.codecov.io/gh/taosdata/taos-connector-node/pulls) page to check the test coverage.
|
|
233
106
|
|
|
234
|
-
|
|
235
|
-
const db = 'power'
|
|
236
|
-
const topics:string[] = ['pwer_meters_topic']
|
|
237
|
-
let dropTopic = `DROP TOPIC IF EXISTS ${topics[0]};`
|
|
238
|
-
let configMap = new Map([
|
|
239
|
-
[TMQConstants.GROUP_ID, "gId"],
|
|
240
|
-
[TMQConstants.CONNECT_USER, "root"],
|
|
241
|
-
[TMQConstants.CONNECT_PASS, "taosdata"],
|
|
242
|
-
[TMQConstants.AUTO_OFFSET_RESET, "earliest"],
|
|
243
|
-
[TMQConstants.CLIENT_ID, 'test_tmq_client'],
|
|
244
|
-
[TMQConstants.WS_URL, 'ws://localhost:6041'],
|
|
245
|
-
[TMQConstants.ENABLE_AUTO_COMMIT, 'true'],
|
|
246
|
-
[TMQConstants.AUTO_COMMIT_INTERVAL_MS, '1000']
|
|
247
|
-
]);
|
|
248
|
-
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
249
|
-
async function Prepare() {
|
|
250
|
-
let conf :WSConfig = new WSConfig(dsn)
|
|
251
|
-
const createDB = `create database if not exists ${db} KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;`
|
|
252
|
-
const createStable = `CREATE STABLE if not exists ${db}.${stable} (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);`
|
|
253
|
-
let createTopic = `create topic if not exists ${topics[0]} as select * from ${db}.${stable}`
|
|
254
|
-
const useDB = `use ${db}`
|
|
107
|
+
## 9. References
|
|
255
108
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
await ws.exec(useDB);
|
|
259
|
-
await ws.exec(createStable);
|
|
260
|
-
await ws.exec(createTopic);
|
|
261
|
-
for (let i = 0; i < 10; i++) {
|
|
262
|
-
await ws.exec(`INSERT INTO d1001 USING ${stable} (location, groupId) TAGS ("California.SanFrancisco", 3) VALUES (NOW, ${10+i}, ${200+i}, ${0.32 + i})`)
|
|
263
|
-
}
|
|
264
|
-
ws.close()
|
|
265
|
-
|
|
266
|
-
}
|
|
109
|
+
- [TDengine Official Website](https://www.tdengine.com/)
|
|
110
|
+
- [TDengine GitHub](https://github.com/taosdata/TDengine)
|
|
267
111
|
|
|
268
|
-
|
|
269
|
-
let consumer = null
|
|
270
|
-
try {
|
|
271
|
-
await Prepare()
|
|
272
|
-
consumer = await tmqConnect(configMap);
|
|
273
|
-
await consumer.subscribe(topics);
|
|
274
|
-
for (let i = 0; i < 5; i++) {
|
|
275
|
-
let res = await consumer.poll(500);
|
|
276
|
-
for (let [key, value] of res) {
|
|
277
|
-
console.log(key, value);
|
|
278
|
-
}
|
|
279
|
-
if (res.size == 0) {
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
await consumer.commit();
|
|
283
|
-
}
|
|
112
|
+
## 10. License
|
|
284
113
|
|
|
285
|
-
|
|
286
|
-
console.log(assignment)
|
|
287
|
-
await consumer.seekToBeginning(assignment)
|
|
288
|
-
assignment = await consumer.assignment()
|
|
289
|
-
for(let i in assignment) {
|
|
290
|
-
console.log("seek after:", assignment[i])
|
|
291
|
-
}
|
|
292
|
-
await consumer.unsubscribe()
|
|
293
|
-
} catch (e) {
|
|
294
|
-
console.error(e);
|
|
295
|
-
} finally {
|
|
296
|
-
if (consumer) {
|
|
297
|
-
await consumer.close();
|
|
298
|
-
}
|
|
299
|
-
destroy()
|
|
300
|
-
}
|
|
301
|
-
})();
|
|
302
|
-
```
|
|
114
|
+
[MIT License](./LICENSE)
|