@tdengine/websocket 3.1.9 → 3.2.1

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.
Files changed (121) hide show
  1. package/lib/example/all_type_query.js +26 -22
  2. package/lib/example/all_type_stmt.js +22 -20
  3. package/lib/example/basicBatchTmq.js +14 -14
  4. package/lib/example/basicSchemaless.js +11 -11
  5. package/lib/example/basicSql.js +10 -10
  6. package/lib/example/basicStmt.js +3 -3
  7. package/lib/example/basicTmq.js +8 -9
  8. package/lib/index.d.ts +1 -1
  9. package/lib/index.d.ts.map +1 -1
  10. package/lib/index.js +1 -1
  11. package/lib/src/client/wsClient.d.ts +3 -2
  12. package/lib/src/client/wsClient.d.ts.map +1 -1
  13. package/lib/src/client/wsClient.js +66 -40
  14. package/lib/src/client/wsConnector.d.ts.map +1 -1
  15. package/lib/src/client/wsConnector.js +40 -14
  16. package/lib/src/client/wsConnectorPool.d.ts.map +1 -1
  17. package/lib/src/client/wsConnectorPool.js +29 -14
  18. package/lib/src/client/wsEventCallback.d.ts.map +1 -1
  19. package/lib/src/client/wsEventCallback.js +6 -4
  20. package/lib/src/client/wsResponse.d.ts.map +1 -1
  21. package/lib/src/client/wsResponse.js +6 -2
  22. package/lib/src/common/config.d.ts +5 -3
  23. package/lib/src/common/config.d.ts.map +1 -1
  24. package/lib/src/common/config.js +15 -5
  25. package/lib/src/common/constant.d.ts +11 -1
  26. package/lib/src/common/constant.d.ts.map +1 -1
  27. package/lib/src/common/constant.js +48 -40
  28. package/lib/src/common/log.d.ts +1 -1
  29. package/lib/src/common/log.d.ts.map +1 -1
  30. package/lib/src/common/log.js +9 -7
  31. package/lib/src/common/reqid.d.ts.map +1 -1
  32. package/lib/src/common/reqid.js +7 -7
  33. package/lib/src/common/taosResult.d.ts.map +1 -1
  34. package/lib/src/common/taosResult.js +46 -27
  35. package/lib/src/common/ut8Helper.d.ts.map +1 -1
  36. package/lib/src/common/ut8Helper.js +8 -8
  37. package/lib/src/common/utils.d.ts.map +1 -1
  38. package/lib/src/common/utils.js +17 -16
  39. package/lib/src/common/wsError.d.ts.map +1 -1
  40. package/lib/src/common/wsError.js +3 -3
  41. package/lib/src/common/wsOptions.d.ts +1 -1
  42. package/lib/src/index.d.ts +3 -3
  43. package/lib/src/index.d.ts.map +1 -1
  44. package/lib/src/sql/wsProto.d.ts.map +1 -1
  45. package/lib/src/sql/wsRows.d.ts +3 -3
  46. package/lib/src/sql/wsRows.d.ts.map +1 -1
  47. package/lib/src/sql/wsRows.js +4 -2
  48. package/lib/src/sql/wsSql.d.ts +5 -5
  49. package/lib/src/sql/wsSql.d.ts.map +1 -1
  50. package/lib/src/sql/wsSql.js +23 -15
  51. package/lib/src/stmt/FieldBindParams.d.ts +9 -0
  52. package/lib/src/stmt/FieldBindParams.d.ts.map +1 -0
  53. package/lib/src/stmt/FieldBindParams.js +13 -0
  54. package/lib/src/stmt/wsColumnInfo.d.ts +12 -0
  55. package/lib/src/stmt/wsColumnInfo.d.ts.map +1 -0
  56. package/lib/src/stmt/wsColumnInfo.js +17 -0
  57. package/lib/src/stmt/wsParams1.d.ts +14 -0
  58. package/lib/src/stmt/wsParams1.d.ts.map +1 -0
  59. package/lib/src/stmt/wsParams1.js +300 -0
  60. package/lib/src/stmt/wsParams2.d.ts +14 -0
  61. package/lib/src/stmt/wsParams2.d.ts.map +1 -0
  62. package/lib/src/stmt/wsParams2.js +203 -0
  63. package/lib/src/stmt/wsParamsBase.d.ts +45 -0
  64. package/lib/src/stmt/wsParamsBase.d.ts.map +1 -0
  65. package/lib/src/stmt/wsParamsBase.js +220 -0
  66. package/lib/src/stmt/wsProto.d.ts +13 -1
  67. package/lib/src/stmt/wsProto.d.ts.map +1 -1
  68. package/lib/src/stmt/wsProto.js +206 -2
  69. package/lib/src/stmt/wsStmt.d.ts +6 -16
  70. package/lib/src/stmt/wsStmt.d.ts.map +1 -1
  71. package/lib/src/stmt/wsStmt.js +0 -201
  72. package/lib/src/stmt/wsStmt1.d.ts +30 -0
  73. package/lib/src/stmt/wsStmt1.d.ts.map +1 -0
  74. package/lib/src/stmt/wsStmt1.js +206 -0
  75. package/lib/src/stmt/wsStmt2.d.ts +37 -0
  76. package/lib/src/stmt/wsStmt2.d.ts.map +1 -0
  77. package/lib/src/stmt/wsStmt2.js +284 -0
  78. package/lib/src/stmt/wsTableInfo.d.ts +17 -0
  79. package/lib/src/stmt/wsTableInfo.d.ts.map +1 -0
  80. package/lib/src/stmt/wsTableInfo.js +54 -0
  81. package/lib/src/tmq/config.d.ts.map +1 -1
  82. package/lib/src/tmq/config.js +2 -2
  83. package/lib/src/tmq/constant.d.ts.map +1 -1
  84. package/lib/src/tmq/constant.js +28 -28
  85. package/lib/src/tmq/tmqResponse.d.ts.map +1 -1
  86. package/lib/src/tmq/tmqResponse.js +31 -17
  87. package/lib/src/tmq/wsTmq.d.ts +2 -2
  88. package/lib/src/tmq/wsTmq.d.ts.map +1 -1
  89. package/lib/src/tmq/wsTmq.js +32 -30
  90. package/lib/test/bulkPulling/cloud.tmq.test.js +11 -11
  91. package/lib/test/bulkPulling/decimal.test.js +50 -26
  92. package/lib/test/bulkPulling/log.test.js +8 -8
  93. package/lib/test/bulkPulling/queryTables.test.js +255 -49
  94. package/lib/test/bulkPulling/schemaless.test.js +34 -34
  95. package/lib/test/bulkPulling/sql.test.js +108 -66
  96. package/lib/test/bulkPulling/stmt1.func.test.d.ts +2 -0
  97. package/lib/test/bulkPulling/stmt1.func.test.d.ts.map +1 -0
  98. package/lib/test/bulkPulling/{stmt.func.test.js → stmt1.func.test.js} +128 -116
  99. package/lib/test/bulkPulling/stmt1.type.test.d.ts +2 -0
  100. package/lib/test/bulkPulling/stmt1.type.test.d.ts.map +1 -0
  101. package/lib/test/bulkPulling/stmt1.type.test.js +399 -0
  102. package/lib/test/bulkPulling/stmt2.func.test.d.ts +2 -0
  103. package/lib/test/bulkPulling/stmt2.func.test.d.ts.map +1 -0
  104. package/lib/test/bulkPulling/stmt2.func.test.js +543 -0
  105. package/lib/test/bulkPulling/stmt2.type.test.d.ts +2 -0
  106. package/lib/test/bulkPulling/stmt2.type.test.d.ts.map +1 -0
  107. package/lib/test/bulkPulling/{stmt.type.test.js → stmt2.type.test.js} +136 -49
  108. package/lib/test/bulkPulling/tmq.test.js +225 -31
  109. package/lib/test/bulkPulling/utils.test.js +2 -2
  110. package/lib/test/bulkPulling/wsConnectPool.test.js +20 -20
  111. package/lib/test/utils.d.ts.map +1 -1
  112. package/lib/test/utils.js +130 -129
  113. package/package.json +1 -1
  114. package/readme.md +1 -0
  115. package/lib/src/stmt/wsParams.d.ts +0 -41
  116. package/lib/src/stmt/wsParams.d.ts.map +0 -1
  117. package/lib/src/stmt/wsParams.js +0 -428
  118. package/lib/test/bulkPulling/stmt.func.test.d.ts +0 -2
  119. package/lib/test/bulkPulling/stmt.func.test.d.ts.map +0 -1
  120. package/lib/test/bulkPulling/stmt.type.test.d.ts +0 -2
  121. package/lib/test/bulkPulling/stmt.type.test.d.ts.map +0 -1
@@ -1,428 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StmtBindParams = exports.ColumnInfo = void 0;
4
- const constant_1 = require("../common/constant");
5
- const wsError_1 = require("../common/wsError");
6
- const taosResult_1 = require("../common/taosResult");
7
- const utils_1 = require("../common/utils");
8
- class ColumnInfo {
9
- constructor([length, data], type, typeLen) {
10
- this.data = data;
11
- this.type = type;
12
- this.length = length;
13
- this.typeLen = typeLen;
14
- }
15
- }
16
- exports.ColumnInfo = ColumnInfo;
17
- class StmtBindParams {
18
- constructor(precision) {
19
- this.precisionLength = constant_1.PrecisionLength['ms'];
20
- this._dataTotalLen = 0;
21
- this._rows = 0;
22
- if (precision) {
23
- this.precisionLength = precision;
24
- }
25
- this._params = [];
26
- }
27
- getDataRows() {
28
- return this._rows;
29
- }
30
- getDataTotalLen() {
31
- return this._dataTotalLen;
32
- }
33
- getParams() {
34
- return this._params;
35
- }
36
- setBoolean(params) {
37
- if (!params || params.length == 0) {
38
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetBooleanColumn params is invalid!");
39
- }
40
- let arrayBuffer = this.encodeDigitColumns(params, "boolean", constant_1.TDengineTypeLength['BOOL'], constant_1.TDengineTypeCode.BOOL);
41
- this._params.push(new ColumnInfo(arrayBuffer, constant_1.TDengineTypeCode.BOOL, constant_1.TDengineTypeLength['BOOL']));
42
- }
43
- setTinyInt(params) {
44
- if (!params || params.length == 0) {
45
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetTinyIntColumn params is invalid!");
46
- }
47
- let arrayBuffer = this.encodeDigitColumns(params, "number", constant_1.TDengineTypeLength['TINYINT'], constant_1.TDengineTypeCode.TINYINT);
48
- this._params.push(new ColumnInfo(arrayBuffer, constant_1.TDengineTypeCode.TINYINT, constant_1.TDengineTypeLength['TINYINT']));
49
- }
50
- setUTinyInt(params) {
51
- if (!params || params.length == 0) {
52
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetUTinyIntColumn params is invalid!");
53
- }
54
- let arrayBuffer = this.encodeDigitColumns(params, "number", constant_1.TDengineTypeLength['TINYINT UNSIGNED'], constant_1.TDengineTypeCode.TINYINT_UNSIGNED);
55
- this._params.push(new ColumnInfo(arrayBuffer, constant_1.TDengineTypeCode.TINYINT_UNSIGNED, constant_1.TDengineTypeLength['TINYINT UNSIGNED']));
56
- }
57
- setSmallInt(params) {
58
- if (!params || params.length == 0) {
59
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetSmallIntColumn params is invalid!");
60
- }
61
- let arrayBuffer = this.encodeDigitColumns(params, "number", constant_1.TDengineTypeLength['SMALLINT'], constant_1.TDengineTypeCode.SMALLINT);
62
- this._params.push(new ColumnInfo(arrayBuffer, constant_1.TDengineTypeCode.SMALLINT, constant_1.TDengineTypeLength['SMALLINT']));
63
- }
64
- setUSmallInt(params) {
65
- if (!params || params.length == 0) {
66
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetSmallIntColumn params is invalid!");
67
- }
68
- let arrayBuffer = this.encodeDigitColumns(params, "number", constant_1.TDengineTypeLength['SMALLINT UNSIGNED'], constant_1.TDengineTypeCode.SMALLINT_UNSIGNED);
69
- this._params.push(new ColumnInfo(arrayBuffer, constant_1.TDengineTypeCode.SMALLINT_UNSIGNED, constant_1.TDengineTypeLength['SMALLINT UNSIGNED']));
70
- }
71
- setInt(params) {
72
- if (!params || params.length == 0) {
73
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetIntColumn params is invalid!");
74
- }
75
- let arrayBuffer = this.encodeDigitColumns(params, "number", constant_1.TDengineTypeLength['INT'], constant_1.TDengineTypeCode.INT);
76
- this._params.push(new ColumnInfo(arrayBuffer, constant_1.TDengineTypeCode.INT, constant_1.TDengineTypeLength['INT']));
77
- }
78
- setUInt(params) {
79
- if (!params || params.length == 0) {
80
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetUIntColumn params is invalid!");
81
- }
82
- let arrayBuffer = this.encodeDigitColumns(params, "number", constant_1.TDengineTypeLength['INT UNSIGNED'], constant_1.TDengineTypeCode.INT_UNSIGNED);
83
- this._params.push(new ColumnInfo(arrayBuffer, constant_1.TDengineTypeCode.INT_UNSIGNED, constant_1.TDengineTypeLength['INT UNSIGNED']));
84
- }
85
- setBigint(params) {
86
- if (!params || params.length == 0) {
87
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetBigIntColumn params is invalid!");
88
- }
89
- let arrayBuffer = this.encodeDigitColumns(params, "bigint", constant_1.TDengineTypeLength['BIGINT'], constant_1.TDengineTypeCode.BIGINT);
90
- this._params.push(new ColumnInfo(arrayBuffer, constant_1.TDengineTypeCode.INT, constant_1.TDengineTypeLength['BIGINT']));
91
- }
92
- setUBigint(params) {
93
- if (!params || params.length == 0) {
94
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetUBigIntColumn params is invalid!");
95
- }
96
- let arrayBuffer = this.encodeDigitColumns(params, "bigint", constant_1.TDengineTypeLength['BIGINT UNSIGNED'], constant_1.TDengineTypeCode.BIGINT_UNSIGNED);
97
- this._params.push(new ColumnInfo(arrayBuffer, constant_1.TDengineTypeCode.BIGINT_UNSIGNED, constant_1.TDengineTypeLength['BIGINT UNSIGNED']));
98
- }
99
- setFloat(params) {
100
- if (!params || params.length == 0) {
101
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetFloatColumn params is invalid!");
102
- }
103
- let arrayBuffer = this.encodeDigitColumns(params, "number", constant_1.TDengineTypeLength['FLOAT'], constant_1.TDengineTypeCode.FLOAT);
104
- this._params.push(new ColumnInfo(arrayBuffer, constant_1.TDengineTypeCode.FLOAT, constant_1.TDengineTypeLength['FLOAT']));
105
- }
106
- setDouble(params) {
107
- if (!params || params.length == 0) {
108
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetDoubleColumn params is invalid!");
109
- }
110
- let arrayBuffer = this.encodeDigitColumns(params, "number", constant_1.TDengineTypeLength['DOUBLE'], constant_1.TDengineTypeCode.DOUBLE);
111
- this._params.push(new ColumnInfo(arrayBuffer, constant_1.TDengineTypeCode.DOUBLE, constant_1.TDengineTypeLength['DOUBLE']));
112
- }
113
- setVarchar(params) {
114
- let data = this.encodeVarLengthColumn(params);
115
- this._params.push(new ColumnInfo(data, constant_1.TDengineTypeCode.VARCHAR, 0));
116
- }
117
- setBinary(params) {
118
- this._params.push(new ColumnInfo(this.encodeVarLengthColumn(params), constant_1.TDengineTypeCode.BINARY, 0));
119
- }
120
- setNchar(params) {
121
- this._params.push(new ColumnInfo(this.encodeNcharColumn(params), constant_1.TDengineTypeCode.NCHAR, 0));
122
- }
123
- setJson(params) {
124
- this._params.push(new ColumnInfo(this.encodeVarLengthColumn(params), constant_1.TDengineTypeCode.JSON, 0));
125
- }
126
- setVarBinary(params) {
127
- this._params.push(new ColumnInfo(this.encodeVarLengthColumn(params), constant_1.TDengineTypeCode.VARBINARY, 0));
128
- }
129
- setGeometry(params) {
130
- this._params.push(new ColumnInfo(this.encodeVarLengthColumn(params), constant_1.TDengineTypeCode.GEOMETRY, 0));
131
- }
132
- setTimestamp(params) {
133
- if (!params || params.length == 0) {
134
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SeTimestampColumn params is invalid!");
135
- }
136
- //computing bitmap length
137
- let bitMapLen = (0, taosResult_1.bitmapLen)(params.length);
138
- //Computing the length of data
139
- let arrayBuffer = new ArrayBuffer(bitMapLen + constant_1.TDengineTypeLength['TIMESTAMP'] * params.length);
140
- //bitmap get data range
141
- let bitmapBuffer = new DataView(arrayBuffer);
142
- //skip bitmap get data range
143
- let dataBuffer = new DataView(arrayBuffer, bitMapLen);
144
- if (this._rows > 0) {
145
- if (this._rows !== params.length) {
146
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "wrong row length!");
147
- }
148
- }
149
- else {
150
- this._rows = params.length;
151
- }
152
- for (let i = 0; i < params.length; i++) {
153
- if (!(0, utils_1.isEmpty)(params[i])) {
154
- if (params[i] instanceof Date) {
155
- let date = params[i];
156
- //node only support milliseconds, need fill 0
157
- if (this.precisionLength == constant_1.PrecisionLength['us']) {
158
- let ms = date.getMilliseconds() * 1000;
159
- dataBuffer.setBigInt64(i * 8, BigInt(ms), true);
160
- }
161
- else if (this.precisionLength == constant_1.PrecisionLength['ns']) {
162
- let ns = date.getMilliseconds() * 1000 * 1000;
163
- dataBuffer.setBigInt64(i * 8, BigInt(ns), true);
164
- }
165
- else {
166
- dataBuffer.setBigInt64(i * 8, BigInt(date.getMilliseconds()), true);
167
- }
168
- }
169
- else if (typeof params[i] == 'bigint' || typeof params[i] == 'number') {
170
- let data;
171
- if (typeof params[i] == 'number') {
172
- data = BigInt(params[i]);
173
- }
174
- else {
175
- data = params[i];
176
- }
177
- //statistical bits of digit
178
- let digit = this.countBigintDigits(data);
179
- //check digit same table Precision
180
- if (this.precisionLength == constant_1.PrecisionLength['ns']) {
181
- if (this.precisionLength <= digit) {
182
- dataBuffer.setBigInt64(i * 8, data, true);
183
- }
184
- else {
185
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SeTimestampColumn params precisionLength is invalid! param:=" + params[i]);
186
- }
187
- }
188
- else if (this.precisionLength == digit) {
189
- dataBuffer.setBigInt64(i * 8, data, true);
190
- }
191
- else {
192
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SeTimestampColumn params is invalid! param:=" + params[i]);
193
- }
194
- }
195
- }
196
- else {
197
- //set bitmap bit is null
198
- let charOffset = (0, taosResult_1.getCharOffset)(i);
199
- let nullVal = (0, taosResult_1.setBitmapNull)(dataBuffer.getInt8(charOffset), i);
200
- bitmapBuffer.setInt8(charOffset, nullVal);
201
- }
202
- }
203
- this._dataTotalLen += arrayBuffer.byteLength;
204
- this._params.push(new ColumnInfo([constant_1.TDengineTypeLength['TIMESTAMP'] * params.length, arrayBuffer], constant_1.TDengineTypeCode.TIMESTAMP, constant_1.TDengineTypeLength['TIMESTAMP']));
205
- }
206
- encodeDigitColumns(params, dataType = 'number', typeLen, columnType) {
207
- let bitMapLen = (0, taosResult_1.bitmapLen)(params.length);
208
- let arrayBuffer = new ArrayBuffer(typeLen * params.length + bitMapLen);
209
- let bitmapBuffer = new DataView(arrayBuffer);
210
- let dataBuffer = new DataView(arrayBuffer, bitMapLen);
211
- if (this._rows > 0) {
212
- if (this._rows !== params.length) {
213
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "wrong row length!");
214
- }
215
- }
216
- else {
217
- this._rows = params.length;
218
- }
219
- for (let i = 0; i < params.length; i++) {
220
- if (!(0, utils_1.isEmpty)(params[i])) {
221
- if (typeof params[i] == dataType) {
222
- switch (columnType) {
223
- case constant_1.TDengineTypeCode.BOOL: {
224
- if (params[i]) {
225
- dataBuffer.setInt8(i, 1);
226
- }
227
- else {
228
- dataBuffer.setInt8(i, 0);
229
- }
230
- break;
231
- }
232
- case constant_1.TDengineTypeCode.TINYINT: {
233
- dataBuffer.setInt8(i, params[i]);
234
- break;
235
- }
236
- case constant_1.TDengineTypeCode.TINYINT_UNSIGNED: {
237
- dataBuffer.setUint8(i, params[i]);
238
- break;
239
- }
240
- case constant_1.TDengineTypeCode.SMALLINT: {
241
- dataBuffer.setInt16(i * 2, params[i], true);
242
- break;
243
- }
244
- case constant_1.TDengineTypeCode.SMALLINT_UNSIGNED: {
245
- dataBuffer.setUint16(i * 2, params[i], true);
246
- break;
247
- }
248
- case constant_1.TDengineTypeCode.INT: {
249
- dataBuffer.setInt32(i * 4, params[i], true);
250
- break;
251
- }
252
- case constant_1.TDengineTypeCode.INT_UNSIGNED: {
253
- dataBuffer.setUint32(i * 4, params[i], true);
254
- break;
255
- }
256
- case constant_1.TDengineTypeCode.BIGINT: {
257
- dataBuffer.setBigInt64(i * 8, params[i], true);
258
- break;
259
- }
260
- case constant_1.TDengineTypeCode.BIGINT_UNSIGNED: {
261
- dataBuffer.setBigUint64(i * 8, params[i], true);
262
- break;
263
- }
264
- case constant_1.TDengineTypeCode.FLOAT: {
265
- dataBuffer.setFloat32(i * 4, params[i], true);
266
- break;
267
- }
268
- case constant_1.TDengineTypeCode.DOUBLE: {
269
- dataBuffer.setFloat64(i * 8, params[i], true);
270
- break;
271
- }
272
- default: {
273
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_UNSUPPORTED_TDENGINE_TYPE, "unsupported type for column" + columnType);
274
- }
275
- }
276
- }
277
- else {
278
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SetTinyIntColumn params is invalid! param:=" + params[i]);
279
- }
280
- }
281
- else {
282
- //set bitmap bit is null
283
- let charOffset = (0, taosResult_1.getCharOffset)(i);
284
- let nullVal = (0, taosResult_1.setBitmapNull)(bitmapBuffer.getUint8(charOffset), i);
285
- bitmapBuffer.setInt8(charOffset, nullVal);
286
- }
287
- }
288
- this._dataTotalLen += dataBuffer.buffer.byteLength;
289
- return [typeLen * params.length, dataBuffer.buffer];
290
- }
291
- encodeVarLengthColumn(params) {
292
- let data = [];
293
- let dataLength = 0;
294
- //create params length buffer
295
- let paramsLenBuffer = new ArrayBuffer(constant_1.TDengineTypeLength['INT'] * params.length);
296
- let paramsLenView = new DataView(paramsLenBuffer);
297
- if (this._rows > 0) {
298
- if (this._rows !== params.length) {
299
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "wrong row length!");
300
- }
301
- }
302
- else {
303
- this._rows = params.length;
304
- }
305
- for (let i = 0; i < params.length; i++) {
306
- //get param length offset 4byte
307
- let offset = constant_1.TDengineTypeLength['INT'] * i;
308
- if (!(0, utils_1.isEmpty)(params[i])) {
309
- //save param length offset 4byte
310
- paramsLenView.setInt32(offset, dataLength, true);
311
- if (typeof params[i] == 'string') {
312
- //string TextEncoder
313
- let encode = new TextEncoder();
314
- let value = encode.encode(params[i]).buffer;
315
- data.push(value);
316
- //add offset length
317
- dataLength += value.byteLength + constant_1.TDengineTypeLength['SMALLINT'];
318
- }
319
- else if (params[i] instanceof ArrayBuffer) {
320
- //input arraybuffer, save not need encode
321
- let value = params[i];
322
- dataLength += value.byteLength + constant_1.TDengineTypeLength['SMALLINT'];
323
- data.push(value);
324
- }
325
- else {
326
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "getColumString params is invalid! param_type:=" + typeof params[i]);
327
- }
328
- }
329
- else {
330
- //set length -1, param is null
331
- for (let j = 0; j < constant_1.TDengineTypeLength['INT']; j++) {
332
- paramsLenView.setInt8(offset + j, 255);
333
- }
334
- }
335
- }
336
- this._dataTotalLen += paramsLenBuffer.byteLength + dataLength;
337
- return [dataLength, this.getBinaryColumnArrayBuffer(data, paramsLenView.buffer, dataLength)];
338
- }
339
- //splicing encode params to arraybuffer
340
- getBinaryColumnArrayBuffer(data, paramsLenBuffer, dataLength) {
341
- //create arraybuffer
342
- let paramsBuffer = new ArrayBuffer(paramsLenBuffer.byteLength + dataLength);
343
- //get length data range
344
- const paramsUint8 = new Uint8Array(paramsBuffer);
345
- const paramsLenView = new Uint8Array(paramsLenBuffer);
346
- paramsUint8.set(paramsLenView, 0);
347
- //get data range
348
- const paramsView = new DataView(paramsBuffer, paramsLenBuffer.byteLength);
349
- let offset = 0;
350
- for (let i = 0; i < data.length; i++) {
351
- //save param field length
352
- paramsView.setInt16(offset, data[i].byteLength, true);
353
- const dataView = new DataView(data[i]);
354
- //save data
355
- for (let j = 0; j < data[i].byteLength; j++) {
356
- paramsView.setUint8(offset + 2 + j, dataView.getUint8(j));
357
- }
358
- offset += data[i].byteLength + 2;
359
- }
360
- return paramsBuffer;
361
- }
362
- //encode nchar type params
363
- encodeNcharColumn(params) {
364
- let data = [];
365
- let dataLength = 0;
366
- let indexBuffer = new ArrayBuffer(constant_1.TDengineTypeLength['INT'] * params.length);
367
- let indexView = new DataView(indexBuffer);
368
- if (this._rows > 0) {
369
- if (this._rows !== params.length) {
370
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "wrong row length!");
371
- }
372
- }
373
- else {
374
- this._rows = params.length;
375
- }
376
- for (let i = 0; i < params.length; i++) {
377
- let offset = constant_1.TDengineTypeLength['INT'] * i;
378
- if (!(0, utils_1.isEmpty)(params[i])) {
379
- indexView.setInt32(offset, dataLength, true);
380
- if (typeof params[i] == 'string') {
381
- let codes = [];
382
- let strNcharParams = params[i];
383
- for (let j = 0; j < params[i].length; j++) {
384
- //get char, cn char need 3~4 byte
385
- codes.push(strNcharParams.charCodeAt(j));
386
- }
387
- let ncharBuffer = new ArrayBuffer(codes.length * 4);
388
- let ncharView = new DataView(ncharBuffer);
389
- for (let j = 0; j < codes.length; j++) {
390
- //1char, save into uint32
391
- ncharView.setUint32(j * 4, codes[j], true);
392
- }
393
- data.push(ncharBuffer);
394
- dataLength += codes.length * 4 + constant_1.TDengineTypeLength['SMALLINT'];
395
- }
396
- else if (params[i] instanceof ArrayBuffer) {
397
- let value = params[i];
398
- dataLength += value.byteLength + constant_1.TDengineTypeLength['SMALLINT'];
399
- data.push(value);
400
- }
401
- else {
402
- throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "getColumString params is invalid! param_type:=" + typeof params[i]);
403
- }
404
- }
405
- else {
406
- //set length -1, param is null
407
- for (let j = 0; j < constant_1.TDengineTypeLength['INT']; j++) {
408
- indexView.setInt8(offset + j, 255);
409
- }
410
- }
411
- }
412
- this._dataTotalLen += indexBuffer.byteLength + dataLength;
413
- return [dataLength, this.getBinaryColumnArrayBuffer(data, indexView.buffer, dataLength)];
414
- }
415
- countBigintDigits(numeral) {
416
- if (numeral === 0n) {
417
- return 1;
418
- }
419
- let count = 0;
420
- let temp = numeral;
421
- while (temp !== 0n) {
422
- temp /= 10n;
423
- count++;
424
- }
425
- return count;
426
- }
427
- }
428
- exports.StmtBindParams = StmtBindParams;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=stmt.func.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stmt.func.test.d.ts","sourceRoot":"","sources":["../../../test/bulkPulling/stmt.func.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=stmt.type.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stmt.type.test.d.ts","sourceRoot":"","sources":["../../../test/bulkPulling/stmt.type.test.ts"],"names":[],"mappings":""}