@tdengine/websocket 3.0.0 → 3.1.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/example/basicSchemaless.d.ts +2 -0
- package/lib/example/basicSchemaless.d.ts.map +1 -0
- package/lib/example/basicSchemaless.js +47 -0
- package/lib/example/basicSql.d.ts +2 -0
- package/lib/example/basicSql.d.ts.map +1 -0
- package/lib/example/basicSql.js +52 -0
- package/lib/example/basicStmt.d.ts +2 -0
- package/lib/example/basicStmt.d.ts.map +1 -0
- package/lib/example/basicStmt.js +58 -0
- package/lib/example/basicTmq.d.ts +2 -0
- package/lib/example/basicTmq.d.ts.map +1 -0
- package/lib/example/basicTmq.js +71 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +41 -0
- package/lib/src/client/wsClient.d.ts +22 -0
- package/lib/src/client/wsClient.d.ts.map +1 -0
- package/lib/src/client/wsClient.js +253 -0
- package/lib/src/client/wsConnector.d.ts +17 -0
- package/lib/src/client/wsConnector.d.ts.map +1 -0
- package/lib/src/client/wsConnector.js +140 -0
- package/lib/src/client/wsConnectorPool.d.ts +13 -0
- package/lib/src/client/wsConnectorPool.d.ts.map +1 -0
- package/lib/src/client/wsConnectorPool.js +107 -0
- package/lib/src/client/wsEventCallback.d.ts +22 -0
- package/lib/src/client/wsEventCallback.d.ts.map +1 -0
- package/lib/src/client/wsEventCallback.js +97 -0
- package/lib/src/client/wsResponse.d.ts +66 -0
- package/lib/src/client/wsResponse.d.ts.map +1 -0
- package/lib/src/client/wsResponse.js +76 -0
- package/lib/src/common/config.d.ts +22 -0
- package/lib/src/common/config.d.ts.map +1 -0
- package/lib/src/common/config.js +45 -0
- package/lib/src/common/constant.d.ts +13 -0
- package/lib/src/common/constant.d.ts.map +1 -0
- package/{src/constant.ts → lib/src/common/constant.js} +25 -24
- package/lib/src/common/log.d.ts +5 -0
- package/lib/src/common/log.d.ts.map +1 -0
- package/lib/src/common/log.js +40 -0
- package/lib/src/common/reqid.d.ts +8 -0
- package/lib/src/common/reqid.d.ts.map +1 -0
- package/lib/src/common/reqid.js +59 -0
- package/lib/src/common/taosResult.d.ts +51 -0
- package/lib/src/common/taosResult.d.ts.map +1 -0
- package/lib/src/common/taosResult.js +419 -0
- package/lib/src/common/ut8Helper.d.ts +2 -0
- package/lib/src/common/ut8Helper.d.ts.map +1 -0
- package/{src/ut8Helper.ts → lib/src/common/ut8Helper.js} +22 -21
- package/lib/src/common/utils.d.ts +5 -0
- package/lib/src/common/utils.d.ts.map +1 -0
- package/lib/src/common/utils.js +33 -0
- package/lib/src/common/wsError.d.ts +29 -0
- package/lib/src/common/wsError.d.ts.map +1 -0
- package/lib/src/common/wsError.js +51 -0
- package/{src/wsOptions.ts → lib/src/common/wsOptions.d.ts} +4 -2
- package/lib/src/common/wsOptions.d.ts.map +1 -0
- package/lib/src/common/wsOptions.js +2 -0
- package/lib/src/index.d.ts +9 -0
- package/lib/src/index.d.ts.map +1 -0
- package/lib/src/index.js +58 -0
- package/lib/src/sql/wsProto.d.ts +26 -0
- package/lib/src/sql/wsProto.d.ts.map +1 -0
- package/lib/src/sql/wsProto.js +19 -0
- package/lib/src/sql/wsRows.d.ts +16 -0
- package/lib/src/sql/wsRows.d.ts.map +1 -0
- package/lib/src/sql/wsRows.js +76 -0
- package/lib/src/sql/wsSql.d.ts +24 -0
- package/lib/src/sql/wsSql.d.ts.map +1 -0
- package/lib/src/sql/wsSql.js +164 -0
- package/lib/src/stmt/wsParams.d.ts +41 -0
- package/lib/src/stmt/wsParams.d.ts.map +1 -0
- package/lib/src/stmt/wsParams.js +428 -0
- package/lib/src/stmt/wsProto.d.ts +27 -0
- package/lib/src/stmt/wsProto.d.ts.map +1 -0
- package/lib/src/stmt/wsProto.js +67 -0
- package/lib/src/stmt/wsStmt.d.ts +30 -0
- package/lib/src/stmt/wsStmt.d.ts.map +1 -0
- package/lib/src/stmt/wsStmt.js +207 -0
- package/lib/src/tmq/config.d.ts +14 -0
- package/lib/src/tmq/config.d.ts.map +1 -0
- package/lib/src/tmq/config.js +42 -0
- package/lib/src/tmq/constant.d.ts +85 -0
- package/lib/src/tmq/constant.d.ts.map +1 -0
- package/lib/src/tmq/constant.js +89 -0
- package/lib/src/tmq/tmqResponse.d.ts +80 -0
- package/lib/src/tmq/tmqResponse.d.ts.map +1 -0
- package/lib/src/tmq/tmqResponse.js +204 -0
- package/lib/src/tmq/wsTmq.d.ts +32 -0
- package/lib/src/tmq/wsTmq.d.ts.map +1 -0
- package/lib/src/tmq/wsTmq.js +316 -0
- package/lib/test/bulkPulling/queryTables.test.d.ts +2 -0
- package/lib/test/bulkPulling/queryTables.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/queryTables.test.js +297 -0
- package/lib/test/bulkPulling/schemaless.test.d.ts +2 -0
- package/lib/test/bulkPulling/schemaless.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/schemaless.test.js +94 -0
- package/lib/test/bulkPulling/sql.test.d.ts +2 -0
- package/lib/test/bulkPulling/sql.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/sql.test.js +124 -0
- package/lib/test/bulkPulling/stmt.func.test.d.ts +2 -0
- package/lib/test/bulkPulling/stmt.func.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/stmt.func.test.js +381 -0
- package/lib/test/bulkPulling/stmt.type.test.d.ts +2 -0
- package/lib/test/bulkPulling/stmt.type.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/stmt.type.test.js +273 -0
- package/lib/test/bulkPulling/tmq.test.d.ts +2 -0
- package/lib/test/bulkPulling/tmq.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/tmq.test.js +177 -0
- package/lib/test/bulkPulling/wsConnectPool.test.d.ts +2 -0
- package/lib/test/bulkPulling/wsConnectPool.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/wsConnectPool.test.js +129 -0
- package/lib/test/utils.d.ts +18 -0
- package/lib/test/utils.d.ts.map +1 -0
- package/lib/test/utils.js +318 -0
- package/package.json +27 -14
- package/readme.md +302 -0
- package/README.md +0 -59
- package/dist/browser/index.js +0 -778
- package/dist/main/index.js +0 -711
- package/dist/main/index.js.map +0 -1
- package/dist/module/index.mjs +0 -704
- package/dist/module/index.mjs.map +0 -1
- package/dist/types.d.ts +0 -103
- package/dist/types.d.ts.map +0 -1
- package/example/basicUsageAsync.ts +0 -48
- package/example/basicUsagePrimse.ts +0 -43
- package/example/cloudUsage.ts +0 -55
- package/example/continousConnectAndVersion.ts +0 -16
- package/example/test.mjs +0 -51
- package/index.ts +0 -7
- package/jest.config.js +0 -8
- package/src/taosResult.ts +0 -269
- package/src/tdengineWebsocket.ts +0 -39
- package/src/wsClient.ts +0 -196
- package/src/wsError.ts +0 -5
- package/src/wsQuery.ts +0 -30
- package/src/wsQueryInterface.ts +0 -212
- package/src/wsQueryResponse.ts +0 -112
- package/tdengine-websocket-3.0.0.tgz +0 -0
- package/test/bulkPulling/connect.test.ts +0 -27
- package/test/bulkPulling/queryTables.test.ts +0 -274
- package/test/bulkPulling/version.test.ts +0 -19
- package/test/utils.ts +0 -235
- package/tsconfig.json +0 -101
package/package.json
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tdengine/websocket",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": "TDengine
|
|
3
|
+
"version": "3.1.0",
|
|
4
|
+
"description": "TDengine Connector for nodejs and browser using WebSocket.",
|
|
5
5
|
"source": "index.ts",
|
|
6
|
-
"main": "
|
|
7
|
-
"module": "
|
|
8
|
-
"types": "
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"module": "lib/module/index.mjs",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
9
|
"directories": {
|
|
10
10
|
"example": "example",
|
|
11
11
|
"test": "test"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"test": "jest --coverage",
|
|
15
|
-
"example": "tsc && node
|
|
16
|
-
"build": "
|
|
17
|
-
"
|
|
18
|
-
"prepare": "parcel build"
|
|
15
|
+
"example": "tsc && node lib/example/basicSql.js",
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"prepublish": "node ./prepare.js"
|
|
19
18
|
},
|
|
20
19
|
"repository": {
|
|
21
20
|
"type": "git",
|
|
22
21
|
"url": "git+https://github.com/taosdata/taos-connector-node.git"
|
|
23
22
|
},
|
|
24
23
|
"keywords": [
|
|
25
|
-
"WebSocket",
|
|
26
24
|
"taosdata",
|
|
27
25
|
"taos",
|
|
28
26
|
"IOT",
|
|
@@ -35,10 +33,23 @@
|
|
|
35
33
|
"bugs": {
|
|
36
34
|
"url": "https://github.com/taosdata/taos-connector-node/issues"
|
|
37
35
|
},
|
|
38
|
-
"
|
|
36
|
+
"files": [
|
|
37
|
+
"lib"
|
|
38
|
+
],
|
|
39
|
+
"homepage": "https://github.com/taosdata/taos-connector-node#readme",
|
|
39
40
|
"dependencies": {
|
|
41
|
+
"@types/json-bigint": "^1.0.1",
|
|
42
|
+
"@types/node": "^18.0.0",
|
|
43
|
+
"@types/uuid": "^9.0.8",
|
|
44
|
+
"@types/websocket": "^1.0",
|
|
45
|
+
"async-mutex": "^0.5.0",
|
|
40
46
|
"json-bigint": "^1.0.0",
|
|
41
|
-
"
|
|
47
|
+
"moment-timezone": "^0.5.45",
|
|
48
|
+
"typescript": "^5.3.3",
|
|
49
|
+
"uuid": "^9.0.1",
|
|
50
|
+
"websocket": "^1.0.34",
|
|
51
|
+
"winston": "^3.13.0",
|
|
52
|
+
"winston-daily-rotate-file": "^5.0.0"
|
|
42
53
|
},
|
|
43
54
|
"devDependencies": {
|
|
44
55
|
"@parcel/packager-ts": "^2.7.0",
|
|
@@ -46,10 +57,12 @@
|
|
|
46
57
|
"@types/jest": "^29.2.1",
|
|
47
58
|
"@types/json-bigint": "^1.0.1",
|
|
48
59
|
"@types/node": "^18.0.0",
|
|
49
|
-
"@types/websocket": "^1.0
|
|
60
|
+
"@types/websocket": "^1.0",
|
|
61
|
+
"@types/uuid": "^9.0.8",
|
|
50
62
|
"jest": "^29.2.2",
|
|
51
63
|
"parcel": "^2.7.0",
|
|
52
64
|
"ts-jest": "^29.0.3",
|
|
53
|
-
"typescript": "^
|
|
65
|
+
"typescript": "^5.3.3",
|
|
66
|
+
"qingwa": "^1.0.7"
|
|
54
67
|
}
|
|
55
68
|
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
# WebSocket APIs
|
|
2
|
+
|
|
3
|
+
## Bulk Pulling
|
|
4
|
+
|
|
5
|
+
### DSN
|
|
6
|
+
|
|
7
|
+
User can connect to the TDengine by passing DSN to WebSocket client. The description about the DSN like before.
|
|
8
|
+
|
|
9
|
+
```text
|
|
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
|
|
36
|
+
|
|
37
|
+
1. Connection Management
|
|
38
|
+
2. General Query
|
|
39
|
+
3. Continuous Query
|
|
40
|
+
4. Parameter Binding
|
|
41
|
+
5. Subscription
|
|
42
|
+
6. Schemaless
|
|
43
|
+
|
|
44
|
+
### Sql Usage
|
|
45
|
+
|
|
46
|
+
``` typescript
|
|
47
|
+
import { WSConfig } from '../src/common/config';
|
|
48
|
+
import { sqlConnect, destroy, setLogLevel } from '../src'
|
|
49
|
+
|
|
50
|
+
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
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)
|
|
61
|
+
|
|
62
|
+
let version = await wsSql.version();
|
|
63
|
+
console.log(version);
|
|
64
|
+
|
|
65
|
+
let taosResult = await wsSql.exec('show databases', reqId++)
|
|
66
|
+
console.log(taosResult);
|
|
67
|
+
|
|
68
|
+
taosResult = await wsSql.exec('create database if not exists power KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;',reqId++);
|
|
69
|
+
console.log(taosResult);
|
|
70
|
+
|
|
71
|
+
taosResult = await wsSql.exec('use power',reqId++)
|
|
72
|
+
console.log(taosResult);
|
|
73
|
+
|
|
74
|
+
taosResult = await wsSql.exec('CREATE STABLE if not exists meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);', reqId++);
|
|
75
|
+
console.log(taosResult);
|
|
76
|
+
|
|
77
|
+
taosResult = await wsSql.exec('describe meters', reqId++)
|
|
78
|
+
console.log(taosResult);
|
|
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
|
+
})();
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Schemaless Usage
|
|
111
|
+
|
|
112
|
+
``` typescript
|
|
113
|
+
import { WSConfig } from '../src/common/config';
|
|
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}`
|
|
122
|
+
|
|
123
|
+
async function Prepare() {
|
|
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);
|
|
132
|
+
|
|
133
|
+
await wsSql.exec('create database if not exists power KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
|
|
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
|
+
}
|
|
137
|
+
|
|
138
|
+
(async () => {
|
|
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
|
+
})();
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Stmt Usage
|
|
163
|
+
|
|
164
|
+
``` typescript
|
|
165
|
+
import { WSConfig } from '../src/common/config';
|
|
166
|
+
import { destroy, sqlConnect } from '../src';
|
|
167
|
+
|
|
168
|
+
let db = 'power'
|
|
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() {
|
|
179
|
+
|
|
180
|
+
let conf :WSConfig = new WSConfig(dsn)
|
|
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
|
+
}
|
|
186
|
+
|
|
187
|
+
(async () => {
|
|
188
|
+
let stmt = null;
|
|
189
|
+
let connector = null;
|
|
190
|
+
try {
|
|
191
|
+
await Prepare();
|
|
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');
|
|
198
|
+
|
|
199
|
+
let tagParams = stmt.newStmtParam()
|
|
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
|
+
```
|
|
226
|
+
|
|
227
|
+
### Tmq Usage
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import { WSConfig } from "../src/common/config";
|
|
231
|
+
import { TMQConstants } from "../src/tmq/constant";
|
|
232
|
+
import { destroy, sqlConnect, tmqConnect } from "../src";
|
|
233
|
+
|
|
234
|
+
const stable = 'meters';
|
|
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}`
|
|
255
|
+
|
|
256
|
+
let ws = await sqlConnect(conf);
|
|
257
|
+
await ws.exec(createDB);
|
|
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
|
+
}
|
|
267
|
+
|
|
268
|
+
(async () => {
|
|
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
|
+
}
|
|
284
|
+
|
|
285
|
+
let assignment = await consumer.assignment()
|
|
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
|
+
```
|
package/README.md
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# WebSocket APIs
|
|
2
|
-
|
|
3
|
-
## Bulk Pulling
|
|
4
|
-
|
|
5
|
-
### DSN
|
|
6
|
-
|
|
7
|
-
User can connect to the TDengine by passing DSN to WebSocket client. The description about the DSN like before.
|
|
8
|
-
|
|
9
|
-
```text
|
|
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
|
-
### Basic Usage
|
|
28
|
-
|
|
29
|
-
``` typescript
|
|
30
|
-
import {connect} from '@tdengine/websocket'
|
|
31
|
-
let dsn = "ws://host:port/rest/ws/db"
|
|
32
|
-
// create an instance of taoWS, while the returned websocket connection of the returned instance 'ws' may is not in 'OPEN' status
|
|
33
|
-
var ws = connect(dsn)
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
``` typescript
|
|
37
|
-
// build connect with tdengine
|
|
38
|
-
ws.connect().then(connectRes=>console.log(connectRes)).catch(e=>{/*do some thing to handle error*/})
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
``` typescript
|
|
42
|
-
//query data with SQL
|
|
43
|
-
ws.query(sql).then(taosResult=>{console.log(taosResult)}).catch(e=>{/*do some thing to handle error*/})
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
// get client version
|
|
48
|
-
ws.version().then(version=>console.log(version)).catch(e=>{/*do some thing to handle error*/})
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
``` typescript
|
|
52
|
-
// get current WebSocket connection status
|
|
53
|
-
let status:number = ws.status()
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
``` typescript
|
|
57
|
-
// close current WebSocket connection
|
|
58
|
-
ws.close();
|
|
59
|
-
```
|