@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,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StmtBindParams = void 0;
|
|
4
|
+
const constant_1 = require("../common/constant");
|
|
5
|
+
const wsError_1 = require("../common/wsError");
|
|
6
|
+
class StmtBindParams {
|
|
7
|
+
constructor(precision, paramsCount) {
|
|
8
|
+
this.precisionLength = constant_1.PrecisionLength['ms'];
|
|
9
|
+
this._dataTotalLen = 0;
|
|
10
|
+
this.paramsCount = 0;
|
|
11
|
+
this._rows = 0;
|
|
12
|
+
this._bindCount = 0;
|
|
13
|
+
if (precision) {
|
|
14
|
+
this.precisionLength = precision;
|
|
15
|
+
}
|
|
16
|
+
this._params = [];
|
|
17
|
+
if (paramsCount && paramsCount > 0) {
|
|
18
|
+
this.paramsCount = paramsCount;
|
|
19
|
+
this._fieldParams = new Array(paramsCount);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this.paramsCount = 0;
|
|
23
|
+
this._fieldParams = [];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
addBindFieldParams(fieldParams) {
|
|
27
|
+
if (!fieldParams || !fieldParams.params || fieldParams.params.length == 0) {
|
|
28
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "StmtBindParams params is invalid!");
|
|
29
|
+
}
|
|
30
|
+
if (!this._fieldParams) {
|
|
31
|
+
this._fieldParams = [];
|
|
32
|
+
}
|
|
33
|
+
this.addParams(fieldParams.params, fieldParams.dataType, fieldParams.typeLen, fieldParams.columnType);
|
|
34
|
+
}
|
|
35
|
+
getBindCount() {
|
|
36
|
+
return this._bindCount;
|
|
37
|
+
}
|
|
38
|
+
getDataRows() {
|
|
39
|
+
return this._rows;
|
|
40
|
+
}
|
|
41
|
+
getDataTotalLen() {
|
|
42
|
+
return this._dataTotalLen;
|
|
43
|
+
}
|
|
44
|
+
getParams() {
|
|
45
|
+
return this._params;
|
|
46
|
+
}
|
|
47
|
+
setBoolean(params) {
|
|
48
|
+
if (!params || params.length == 0) {
|
|
49
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetBooleanColumn params is invalid!");
|
|
50
|
+
}
|
|
51
|
+
this.addParams(params, "boolean", constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.BOOL], constant_1.TDengineTypeCode.BOOL);
|
|
52
|
+
}
|
|
53
|
+
setTinyInt(params) {
|
|
54
|
+
if (!params || params.length == 0) {
|
|
55
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetTinyIntColumn params is invalid!");
|
|
56
|
+
}
|
|
57
|
+
this.addParams(params, "number", constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.TINYINT], constant_1.TDengineTypeCode.TINYINT);
|
|
58
|
+
}
|
|
59
|
+
setUTinyInt(params) {
|
|
60
|
+
if (!params || params.length == 0) {
|
|
61
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetUTinyIntColumn params is invalid!");
|
|
62
|
+
}
|
|
63
|
+
this.addParams(params, "number", constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.TINYINT_UNSIGNED], constant_1.TDengineTypeCode.TINYINT_UNSIGNED);
|
|
64
|
+
}
|
|
65
|
+
setSmallInt(params) {
|
|
66
|
+
if (!params || params.length == 0) {
|
|
67
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetSmallIntColumn params is invalid!");
|
|
68
|
+
}
|
|
69
|
+
this.addParams(params, "number", constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.SMALLINT], constant_1.TDengineTypeCode.SMALLINT);
|
|
70
|
+
}
|
|
71
|
+
setUSmallInt(params) {
|
|
72
|
+
if (!params || params.length == 0) {
|
|
73
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetSmallIntColumn params is invalid!");
|
|
74
|
+
}
|
|
75
|
+
this.addParams(params, "number", constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.SMALLINT_UNSIGNED], constant_1.TDengineTypeCode.SMALLINT_UNSIGNED);
|
|
76
|
+
}
|
|
77
|
+
setInt(params) {
|
|
78
|
+
if (!params || params.length == 0) {
|
|
79
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetIntColumn params is invalid!");
|
|
80
|
+
}
|
|
81
|
+
this.addParams(params, "number", constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT], constant_1.TDengineTypeCode.INT);
|
|
82
|
+
}
|
|
83
|
+
setUInt(params) {
|
|
84
|
+
if (!params || params.length == 0) {
|
|
85
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetUIntColumn params is invalid!");
|
|
86
|
+
}
|
|
87
|
+
this.addParams(params, "number", constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT_UNSIGNED], constant_1.TDengineTypeCode.INT_UNSIGNED);
|
|
88
|
+
}
|
|
89
|
+
setBigint(params) {
|
|
90
|
+
if (!params || params.length == 0) {
|
|
91
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetBigIntColumn params is invalid!");
|
|
92
|
+
}
|
|
93
|
+
this.addParams(params, "bigint", constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.BIGINT], constant_1.TDengineTypeCode.BIGINT);
|
|
94
|
+
}
|
|
95
|
+
setUBigint(params) {
|
|
96
|
+
if (!params || params.length == 0) {
|
|
97
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetUBigIntColumn params is invalid!");
|
|
98
|
+
}
|
|
99
|
+
this.addParams(params, "bigint", constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.BIGINT_UNSIGNED], constant_1.TDengineTypeCode.BIGINT_UNSIGNED);
|
|
100
|
+
}
|
|
101
|
+
setFloat(params) {
|
|
102
|
+
if (!params || params.length == 0) {
|
|
103
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetFloatColumn params is invalid!");
|
|
104
|
+
}
|
|
105
|
+
this.addParams(params, "number", constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.FLOAT], constant_1.TDengineTypeCode.FLOAT);
|
|
106
|
+
}
|
|
107
|
+
setDouble(params) {
|
|
108
|
+
if (!params || params.length == 0) {
|
|
109
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetDoubleColumn params is invalid!");
|
|
110
|
+
}
|
|
111
|
+
this.addParams(params, "number", constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.DOUBLE], constant_1.TDengineTypeCode.DOUBLE);
|
|
112
|
+
}
|
|
113
|
+
setVarchar(params) {
|
|
114
|
+
if (!params || params.length == 0) {
|
|
115
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetVarcharColumn params is invalid!");
|
|
116
|
+
}
|
|
117
|
+
this.addParams(params, constant_1.TDengineTypeName[8], 0, constant_1.TDengineTypeCode.VARCHAR);
|
|
118
|
+
}
|
|
119
|
+
setBinary(params) {
|
|
120
|
+
if (!params || params.length == 0) {
|
|
121
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetBinaryColumn params is invalid!");
|
|
122
|
+
}
|
|
123
|
+
this.addParams(params, constant_1.TDengineTypeName[8], 0, constant_1.TDengineTypeCode.BINARY);
|
|
124
|
+
}
|
|
125
|
+
setNchar(params) {
|
|
126
|
+
if (!params || params.length == 0) {
|
|
127
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetNcharColumn params is invalid!");
|
|
128
|
+
}
|
|
129
|
+
this.addParams(params, constant_1.TDengineTypeName[10], 0, constant_1.TDengineTypeCode.NCHAR);
|
|
130
|
+
}
|
|
131
|
+
setJson(params) {
|
|
132
|
+
if (!params || params.length == 0) {
|
|
133
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetJsonColumn params is invalid!");
|
|
134
|
+
}
|
|
135
|
+
this.addParams(params, constant_1.TDengineTypeName[15], 0, constant_1.TDengineTypeCode.JSON);
|
|
136
|
+
}
|
|
137
|
+
setVarBinary(params) {
|
|
138
|
+
if (!params || params.length == 0) {
|
|
139
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetVarBinaryColumn params is invalid!");
|
|
140
|
+
}
|
|
141
|
+
this.addParams(params, constant_1.TDengineTypeName[16], 0, constant_1.TDengineTypeCode.VARBINARY);
|
|
142
|
+
}
|
|
143
|
+
setGeometry(params) {
|
|
144
|
+
if (!params || params.length == 0) {
|
|
145
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetGeometryColumn params is invalid!");
|
|
146
|
+
}
|
|
147
|
+
this.addParams(params, constant_1.TDengineTypeName[20], 0, constant_1.TDengineTypeCode.GEOMETRY);
|
|
148
|
+
}
|
|
149
|
+
setTimestamp(params) {
|
|
150
|
+
if (!params || params.length == 0) {
|
|
151
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SeTimestampColumn params is invalid!");
|
|
152
|
+
}
|
|
153
|
+
this.addParams(params, constant_1.TDengineTypeName[9], constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.TIMESTAMP], constant_1.TDengineTypeCode.TIMESTAMP);
|
|
154
|
+
}
|
|
155
|
+
writeDataToBuffer(dataBuffer, params, dataType = 'number', typeLen, columnType, i) {
|
|
156
|
+
if (typeof params == dataType) {
|
|
157
|
+
switch (columnType) {
|
|
158
|
+
case constant_1.TDengineTypeCode.BOOL: {
|
|
159
|
+
if (params) {
|
|
160
|
+
dataBuffer.setInt8(i, 1);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
dataBuffer.setInt8(i, 0);
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
case constant_1.TDengineTypeCode.TINYINT: {
|
|
168
|
+
dataBuffer.setInt8(i, params);
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case constant_1.TDengineTypeCode.TINYINT_UNSIGNED: {
|
|
172
|
+
dataBuffer.setUint8(i, params);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
case constant_1.TDengineTypeCode.SMALLINT: {
|
|
176
|
+
dataBuffer.setInt16(i * 2, params, true);
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case constant_1.TDengineTypeCode.SMALLINT_UNSIGNED: {
|
|
180
|
+
dataBuffer.setUint16(i * 2, params, true);
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
case constant_1.TDengineTypeCode.INT: {
|
|
184
|
+
dataBuffer.setInt32(i * 4, params, true);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case constant_1.TDengineTypeCode.INT_UNSIGNED: {
|
|
188
|
+
dataBuffer.setUint32(i * 4, params, true);
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case constant_1.TDengineTypeCode.BIGINT:
|
|
192
|
+
case constant_1.TDengineTypeCode.TIMESTAMP: {
|
|
193
|
+
dataBuffer.setBigInt64(i * 8, params, true);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case constant_1.TDengineTypeCode.BIGINT_UNSIGNED: {
|
|
197
|
+
dataBuffer.setBigUint64(i * 8, params, true);
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
case constant_1.TDengineTypeCode.FLOAT: {
|
|
201
|
+
dataBuffer.setFloat32(i * 4, params, true);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case constant_1.TDengineTypeCode.DOUBLE: {
|
|
205
|
+
dataBuffer.setFloat64(i * 8, params, true);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
default: {
|
|
209
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_UNSUPPORTED_TDENGINE_TYPE, "unsupported type for column" + columnType);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetTinyIntColumn params is invalid! param:=" + params);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.StmtBindParams = StmtBindParams;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WSQueryResponse } from "../client/wsResponse";
|
|
2
2
|
import { MessageResp } from "../common/taosResult";
|
|
3
|
-
import { StmtBindParams } from "./
|
|
3
|
+
import { StmtBindParams } from "./wsParamsBase";
|
|
4
|
+
import { TableInfo } from "./wsTableInfo";
|
|
4
5
|
export interface StmtMessageInfo {
|
|
5
6
|
action: string;
|
|
6
7
|
args: StmtParamsInfo;
|
|
@@ -8,20 +9,31 @@ export interface StmtMessageInfo {
|
|
|
8
9
|
interface StmtParamsInfo {
|
|
9
10
|
req_id: number;
|
|
10
11
|
sql?: string | undefined | null;
|
|
11
|
-
stmt_id?:
|
|
12
|
+
stmt_id?: bigint | undefined | null;
|
|
12
13
|
name?: string | undefined | null;
|
|
13
14
|
tags?: Array<any> | undefined | null;
|
|
14
15
|
paramArray?: Array<Array<any>> | undefined | null;
|
|
15
16
|
}
|
|
17
|
+
export interface StmtFieldInfo {
|
|
18
|
+
name: string | undefined | null;
|
|
19
|
+
field_type: number | undefined | null;
|
|
20
|
+
precision: number | undefined | null;
|
|
21
|
+
scale: number | undefined | null;
|
|
22
|
+
bytes: number | undefined | null;
|
|
23
|
+
bind_type: number | undefined | null;
|
|
24
|
+
}
|
|
16
25
|
export declare class WsStmtQueryResponse extends WSQueryResponse {
|
|
17
26
|
affected: number | undefined | null;
|
|
18
|
-
stmt_id?:
|
|
27
|
+
stmt_id?: bigint | undefined | null;
|
|
28
|
+
is_insert?: boolean | undefined | null;
|
|
29
|
+
fields?: Array<StmtFieldInfo> | undefined | null;
|
|
19
30
|
constructor(resp: MessageResp);
|
|
20
31
|
}
|
|
21
32
|
export declare const enum StmtBindType {
|
|
22
33
|
STMT_TYPE_TAG = 1,
|
|
23
34
|
STMT_TYPE_BIND = 2
|
|
24
35
|
}
|
|
25
|
-
export declare function binaryBlockEncode(bindParams: StmtBindParams, bindType: StmtBindType, stmtId:
|
|
36
|
+
export declare function binaryBlockEncode(bindParams: StmtBindParams, bindType: StmtBindType, stmtId: bigint, reqId: bigint, row: number): ArrayBuffer;
|
|
37
|
+
export declare function stmt2BinaryBlockEncode(reqId: bigint, stmtTableInfoList: TableInfo[], stmt_id: bigint | undefined | null, toBeBindTableNameIndex: number | undefined | null, toBeBindTagCount: number, toBeBindColCount: number): ArrayBuffer;
|
|
26
38
|
export {};
|
|
27
39
|
//# sourceMappingURL=wsProto.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsProto.d.ts","sourceRoot":"","sources":["../../../src/stmt/wsProto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wsProto.d.ts","sourceRoot":"","sources":["../../../src/stmt/wsProto.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,cAAc,CAAC;CACxB;AAED,UAAU,cAAc;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACpC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACjC,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC;IACrC,UAAU,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC;CACrD;AAGD,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAChC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACtC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACrC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACjC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACjC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CACxC;AAED,qBAAa,mBAAoB,SAAQ,eAAe;IACpD,QAAQ,EAAC,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACpC,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC;IACvC,MAAM,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC;gBACrC,IAAI,EAAC,WAAW;CAO/B;AAED,0BAAkB,YAAY;IAC1B,aAAa,IAAE;IACf,cAAc,IAAE;CACnB;AAGD,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAC,YAAY,EAAE,MAAM,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,EAAE,GAAG,EAAC,MAAM,GAAG,WAAW,CAwDzI;AAyCD,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,MAAM,EACb,iBAAiB,EAAE,SAAS,EAAE,EAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAClC,sBAAsB,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EACjD,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,MAAM,GACzB,WAAW,CAsKb"}
|
package/lib/src/stmt/wsProto.js
CHANGED
|
@@ -2,27 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WsStmtQueryResponse = void 0;
|
|
4
4
|
exports.binaryBlockEncode = binaryBlockEncode;
|
|
5
|
+
exports.stmt2BinaryBlockEncode = stmt2BinaryBlockEncode;
|
|
5
6
|
const wsResponse_1 = require("../client/wsResponse");
|
|
6
7
|
const constant_1 = require("../common/constant");
|
|
8
|
+
const wsError_1 = require("../common/wsError");
|
|
7
9
|
class WsStmtQueryResponse extends wsResponse_1.WSQueryResponse {
|
|
8
10
|
constructor(resp) {
|
|
9
11
|
super(resp);
|
|
10
|
-
this.stmt_id = resp.msg.stmt_id;
|
|
12
|
+
this.stmt_id = BigInt(resp.msg.stmt_id);
|
|
11
13
|
this.affected = resp.msg.affected;
|
|
14
|
+
this.is_insert = resp.msg.is_insert;
|
|
15
|
+
this.fields = resp.msg.fields;
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
exports.WsStmtQueryResponse = WsStmtQueryResponse;
|
|
15
19
|
function binaryBlockEncode(bindParams, bindType, stmtId, reqId, row) {
|
|
16
20
|
//Computing the length of data
|
|
17
21
|
let columns = bindParams.getParams().length;
|
|
18
|
-
let length = constant_1.TDengineTypeLength[
|
|
19
|
-
length += constant_1.TDengineTypeLength[
|
|
22
|
+
let length = constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.BIGINT] * 4;
|
|
23
|
+
length += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT] * 5;
|
|
20
24
|
length += columns * 5 + columns * 4;
|
|
21
25
|
length += bindParams.getDataTotalLen();
|
|
22
26
|
let arrayBuffer = new ArrayBuffer(length);
|
|
23
27
|
let arrayView = new DataView(arrayBuffer);
|
|
24
28
|
arrayView.setBigUint64(0, reqId, true);
|
|
25
|
-
arrayView.setBigUint64(8,
|
|
29
|
+
arrayView.setBigUint64(8, stmtId, true);
|
|
26
30
|
arrayView.setBigUint64(16, BigInt(bindType), true);
|
|
27
31
|
//version int32
|
|
28
32
|
arrayView.setUint32(24, 1, true);
|
|
@@ -65,3 +69,192 @@ function binaryBlockEncode(bindParams, bindType, stmtId, reqId, row) {
|
|
|
65
69
|
}
|
|
66
70
|
return arrayBuffer;
|
|
67
71
|
}
|
|
72
|
+
function writeColumnToView(column, view, offset) {
|
|
73
|
+
let currentOffset = offset;
|
|
74
|
+
// length, type, _rows
|
|
75
|
+
view.setInt32(currentOffset, column.length, true);
|
|
76
|
+
currentOffset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
77
|
+
view.setInt32(currentOffset, column.type, true);
|
|
78
|
+
currentOffset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
79
|
+
view.setInt32(currentOffset, column._rows, true);
|
|
80
|
+
currentOffset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
81
|
+
// isNull bitmap
|
|
82
|
+
if (column.isNull && column.isNull.length > 0) {
|
|
83
|
+
const isNullBuffer = new Uint8Array(column.isNull);
|
|
84
|
+
new Uint8Array(view.buffer, view.byteOffset + currentOffset).set(isNullBuffer);
|
|
85
|
+
currentOffset += isNullBuffer.length;
|
|
86
|
+
}
|
|
87
|
+
// _haveLength and _dataLengths
|
|
88
|
+
view.setUint8(currentOffset, column._haveLength);
|
|
89
|
+
currentOffset += 1;
|
|
90
|
+
if (column._haveLength === 1 && column._dataLengths) {
|
|
91
|
+
for (const length of column._dataLengths) {
|
|
92
|
+
view.setInt32(currentOffset, length, true);
|
|
93
|
+
currentOffset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// data
|
|
97
|
+
view.setInt32(currentOffset, column.data.byteLength, true);
|
|
98
|
+
currentOffset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
99
|
+
if (column.data.byteLength > 0) {
|
|
100
|
+
new Uint8Array(view.buffer, view.byteOffset + currentOffset).set(new Uint8Array(column.data));
|
|
101
|
+
currentOffset += column.data.byteLength;
|
|
102
|
+
}
|
|
103
|
+
return currentOffset - offset; // Return the total number of bytes written
|
|
104
|
+
}
|
|
105
|
+
function stmt2BinaryBlockEncode(reqId, stmtTableInfoList, stmt_id, toBeBindTableNameIndex, toBeBindTagCount, toBeBindColCount) {
|
|
106
|
+
if (!stmt_id) {
|
|
107
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "stmt_id is invalid");
|
|
108
|
+
}
|
|
109
|
+
const listLength = stmtTableInfoList.length;
|
|
110
|
+
const result = {
|
|
111
|
+
totalTableNameSize: 0,
|
|
112
|
+
totalTagSize: 0,
|
|
113
|
+
totalColSize: 0,
|
|
114
|
+
tableNameSizeList: new Array(listLength),
|
|
115
|
+
tagSizeList: new Array(listLength),
|
|
116
|
+
colSizeList: new Array(listLength)
|
|
117
|
+
};
|
|
118
|
+
const hasTableName = toBeBindTableNameIndex != null && toBeBindTableNameIndex >= 0;
|
|
119
|
+
const hasTags = toBeBindTagCount > 0;
|
|
120
|
+
for (let i = 0; i < listLength; i++) {
|
|
121
|
+
const tableInfo = stmtTableInfoList[i];
|
|
122
|
+
if (hasTableName) {
|
|
123
|
+
const tableName = tableInfo.getTableName();
|
|
124
|
+
if (!tableName)
|
|
125
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "Table name is empty");
|
|
126
|
+
const size = tableInfo.getTableNameLength();
|
|
127
|
+
if (size > 0) {
|
|
128
|
+
result.tableNameSizeList[i] = size + 1;
|
|
129
|
+
result.totalTableNameSize += size + 1;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "Table name len is empty");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (hasTags) {
|
|
136
|
+
const tagParams = tableInfo.getTags();
|
|
137
|
+
if (!tagParams)
|
|
138
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "Bind tags is empty!");
|
|
139
|
+
tagParams.encode();
|
|
140
|
+
const size = tagParams.getDataTotalLen();
|
|
141
|
+
result.tagSizeList[i] = size;
|
|
142
|
+
result.totalTagSize += size;
|
|
143
|
+
}
|
|
144
|
+
const params = tableInfo.getParams();
|
|
145
|
+
if (!params)
|
|
146
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "Bind params is empty!");
|
|
147
|
+
params.encode();
|
|
148
|
+
const size = params.getDataTotalLen();
|
|
149
|
+
result.colSizeList[i] = size;
|
|
150
|
+
result.totalColSize += size;
|
|
151
|
+
}
|
|
152
|
+
let totalSize = result.totalTableNameSize + result.totalTagSize + result.totalColSize;
|
|
153
|
+
let toBeBindTableNameCount = (toBeBindTableNameIndex != null && toBeBindTableNameIndex >= 0) ? 1 : 0;
|
|
154
|
+
totalSize += stmtTableInfoList.length * (toBeBindTableNameCount * 2
|
|
155
|
+
+ (toBeBindTagCount > 0 ? 1 : 0) * 4
|
|
156
|
+
+ (toBeBindColCount > 0 ? 1 : 0) * 4);
|
|
157
|
+
let headerSize = 28; // Fixed header size
|
|
158
|
+
let msgHeaderSize = 30; // Fixed msg header size
|
|
159
|
+
const buffer = new ArrayBuffer(headerSize + msgHeaderSize + totalSize);
|
|
160
|
+
const view = new DataView(buffer);
|
|
161
|
+
let offset = 0;
|
|
162
|
+
view.setBigUint64(offset, reqId, true);
|
|
163
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.BIGINT];
|
|
164
|
+
view.setBigUint64(offset, stmt_id, true);
|
|
165
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.BIGINT];
|
|
166
|
+
view.setBigUint64(offset, 9n, true);
|
|
167
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.BIGINT]; // action: bind
|
|
168
|
+
view.setInt16(offset, 1, true);
|
|
169
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.SMALLINT]; // version
|
|
170
|
+
view.setInt32(offset, -1, true);
|
|
171
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
172
|
+
view.setInt32(offset, totalSize + headerSize, true);
|
|
173
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT]; // total length
|
|
174
|
+
view.setInt32(offset, stmtTableInfoList.length, true);
|
|
175
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
176
|
+
view.setInt32(offset, toBeBindTagCount, true);
|
|
177
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
178
|
+
view.setInt32(offset, toBeBindColCount, true);
|
|
179
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
180
|
+
view.setInt32(offset, toBeBindTableNameCount > 0 ? 0x1C : 0, true);
|
|
181
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
182
|
+
if (toBeBindTagCount) {
|
|
183
|
+
if (toBeBindTableNameCount > 0) {
|
|
184
|
+
view.setInt32(offset, headerSize + result.totalTableNameSize + 2 * stmtTableInfoList.length, true);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
view.setInt32(offset, headerSize, true);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
view.setInt32(offset, 0, true);
|
|
192
|
+
}
|
|
193
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
194
|
+
if (toBeBindColCount > 0) {
|
|
195
|
+
let skipSize = 0;
|
|
196
|
+
if (toBeBindTableNameCount > 0) {
|
|
197
|
+
skipSize += result.totalTableNameSize + 2 * stmtTableInfoList.length;
|
|
198
|
+
}
|
|
199
|
+
if (toBeBindTagCount > 0) {
|
|
200
|
+
skipSize += result.totalTagSize + 4 * stmtTableInfoList.length;
|
|
201
|
+
}
|
|
202
|
+
// colOffset = 28 + skipSize
|
|
203
|
+
view.setInt32(offset, skipSize + headerSize, true);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
view.setInt32(offset, 0, true);
|
|
207
|
+
}
|
|
208
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
209
|
+
if (toBeBindTableNameCount > 0) {
|
|
210
|
+
let dataOffset = offset + result.tableNameSizeList.length * constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.SMALLINT];
|
|
211
|
+
for (let i = 0; i < listLength; i++) {
|
|
212
|
+
view.setInt16(offset, result.tableNameSizeList[i], true);
|
|
213
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.SMALLINT];
|
|
214
|
+
let tableName = stmtTableInfoList[i].getTableName();
|
|
215
|
+
if (tableName && tableName.length > 0) {
|
|
216
|
+
new Uint8Array(buffer, dataOffset).set(tableName);
|
|
217
|
+
dataOffset += tableName.length;
|
|
218
|
+
view.setUint8(dataOffset, 0);
|
|
219
|
+
dataOffset += 1;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "Table name is empty");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
offset = dataOffset;
|
|
226
|
+
}
|
|
227
|
+
if (toBeBindTagCount > 0) {
|
|
228
|
+
let dataOffset = offset + result.tagSizeList.length * constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
229
|
+
for (let i = 0; i < listLength; i++) {
|
|
230
|
+
view.setInt32(offset, result.tagSizeList[i], true);
|
|
231
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
232
|
+
let tags = stmtTableInfoList[i].getTags();
|
|
233
|
+
if (tags && tags.getParams().length > 0) {
|
|
234
|
+
for (const col of tags.getParams()) {
|
|
235
|
+
dataOffset += writeColumnToView(col, new DataView(buffer, dataOffset), 0);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "Tags are empty");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
offset = dataOffset;
|
|
243
|
+
}
|
|
244
|
+
// ColumnDataLength
|
|
245
|
+
if (toBeBindColCount > 0) {
|
|
246
|
+
let dataOffset = offset + result.colSizeList.length * constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
247
|
+
for (let i = 0; i < listLength; i++) {
|
|
248
|
+
view.setInt32(offset, result.colSizeList[i], true);
|
|
249
|
+
offset += constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT];
|
|
250
|
+
let params = stmtTableInfoList[i].getParams();
|
|
251
|
+
if (!params) {
|
|
252
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "Bind params is empty!");
|
|
253
|
+
}
|
|
254
|
+
for (const col of params.getParams()) {
|
|
255
|
+
dataOffset += writeColumnToView(col, new DataView(buffer, dataOffset), 0);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return buffer;
|
|
260
|
+
}
|
package/lib/src/stmt/wsStmt.d.ts
CHANGED
|
@@ -1,26 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { StmtBindParams } from
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
private _stmt_id;
|
|
6
|
-
private _precision;
|
|
7
|
-
private lastAffected;
|
|
8
|
-
private constructor();
|
|
9
|
-
static newStmt(wsClient: WsClient, precision?: number, reqId?: number): Promise<WsStmt>;
|
|
1
|
+
import { WSRows } from "../sql/wsRows";
|
|
2
|
+
import { StmtBindParams } from "./wsParamsBase";
|
|
3
|
+
export interface WsStmt {
|
|
4
|
+
getStmtId(): bigint | undefined | null;
|
|
10
5
|
prepare(sql: string): Promise<void>;
|
|
11
6
|
setTableName(tableName: string): Promise<void>;
|
|
12
|
-
setJsonTags(tags: Array<any>): Promise<void>;
|
|
13
|
-
newStmtParam(): StmtBindParams;
|
|
14
7
|
setTags(paramsArray: StmtBindParams): Promise<void>;
|
|
8
|
+
newStmtParam(): StmtBindParams;
|
|
15
9
|
bind(paramsArray: StmtBindParams): Promise<void>;
|
|
16
|
-
jsonBind(paramArray: Array<Array<any>>): Promise<void>;
|
|
17
10
|
batch(): Promise<void>;
|
|
18
11
|
exec(): Promise<void>;
|
|
12
|
+
resultSet(): Promise<WSRows>;
|
|
19
13
|
getLastAffected(): number | null | undefined;
|
|
20
14
|
close(): Promise<void>;
|
|
21
|
-
getStmtId(): number | undefined | null;
|
|
22
|
-
private execute;
|
|
23
|
-
private sendBinaryMsg;
|
|
24
|
-
private init;
|
|
25
15
|
}
|
|
26
16
|
//# sourceMappingURL=wsStmt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsStmt.d.ts","sourceRoot":"","sources":["../../../src/stmt/wsStmt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"wsStmt.d.ts","sourceRoot":"","sources":["../../../src/stmt/wsStmt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,MAAM;IACnB,SAAS,IAAI,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;IACtC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,OAAO,CAAC,WAAW,EAAC,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,YAAY,IAAG,cAAc,CAAA;IAC7B,IAAI,CAAC,WAAW,EAAC,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,eAAe,IAAI,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAEzB"}
|