@tdengine/websocket 3.1.9 → 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 +1 -0
- package/lib/src/client/wsClient.d.ts.map +1 -1
- package/lib/src/client/wsClient.js +6 -3
- package/lib/src/common/config.d.ts +3 -1
- package/lib/src/common/config.d.ts.map +1 -1
- package/lib/src/common/config.js +11 -1
- package/lib/src/common/constant.d.ts +11 -1
- package/lib/src/common/constant.d.ts.map +1 -1
- package/lib/src/common/constant.js +21 -13
- package/lib/src/sql/wsSql.d.ts.map +1 -1
- package/lib/src/sql/wsSql.js +8 -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 +13 -1
- package/lib/src/stmt/wsProto.d.ts.map +1 -1
- package/lib/src/stmt/wsProto.js +195 -2
- 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 -201
- 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/tmqResponse.js +1 -1
- package/lib/test/bulkPulling/sql.test.js +3 -0
- package/lib/test/bulkPulling/stmt.func.test.js +99 -11
- package/lib/test/bulkPulling/stmt.type.test.js +8 -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/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,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Stmt2BindParams = void 0;
|
|
7
|
+
const constant_1 = require("../common/constant");
|
|
8
|
+
const wsError_1 = require("../common/wsError");
|
|
9
|
+
const utils_1 = require("../common/utils");
|
|
10
|
+
const wsColumnInfo_1 = require("./wsColumnInfo");
|
|
11
|
+
const wsParamsBase_1 = require("./wsParamsBase");
|
|
12
|
+
const taosResult_1 = require("../common/taosResult");
|
|
13
|
+
const FieldBindParams_1 = require("./FieldBindParams");
|
|
14
|
+
const json_bigint_1 = __importDefault(require("json-bigint"));
|
|
15
|
+
class Stmt2BindParams extends wsParamsBase_1.StmtBindParams {
|
|
16
|
+
constructor(paramsCount, precision, fields) {
|
|
17
|
+
super(precision, paramsCount);
|
|
18
|
+
this.paramIndex = 0;
|
|
19
|
+
this._fields = fields || [];
|
|
20
|
+
}
|
|
21
|
+
addParams(params, dataType, typeLen, columnType) {
|
|
22
|
+
if (!params || params.length == 0) {
|
|
23
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "StmtBindParams params is invalid!");
|
|
24
|
+
}
|
|
25
|
+
if (this._fieldParams) {
|
|
26
|
+
if (this.paramsCount > 0) {
|
|
27
|
+
if (this._fieldParams[this.paramIndex]) {
|
|
28
|
+
if (this._fieldParams[this.paramIndex].dataType !== dataType || this._fieldParams[this.paramIndex].columnType !== columnType) {
|
|
29
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, `StmtBindParams params type is not match! ${this.paramIndex} ${this.paramsCount} ${json_bigint_1.default.stringify({ dataType, columnType })} vs ${json_bigint_1.default.stringify({ dataType: this._fieldParams[this.paramIndex].dataType, columnType: this._fieldParams[this.paramIndex].columnType })}`);
|
|
30
|
+
}
|
|
31
|
+
this._fieldParams[this.paramIndex].params.push(...params);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
let bindType = this._fields[this.paramIndex].bind_type || 0;
|
|
35
|
+
this._fieldParams[this.paramIndex] = new FieldBindParams_1.FieldBindParams(params, dataType, typeLen, columnType, bindType);
|
|
36
|
+
this._bindCount++;
|
|
37
|
+
}
|
|
38
|
+
this.paramIndex++;
|
|
39
|
+
if (this.paramIndex >= this.paramsCount) {
|
|
40
|
+
this.paramIndex = 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this._fieldParams.push(new FieldBindParams_1.FieldBindParams(params, dataType, typeLen, columnType, constant_1.FieldBindType.TAOS_FIELD_COL));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
mergeParams(bindParams) {
|
|
49
|
+
if (!bindParams || !bindParams._fieldParams || bindParams._fieldParams.length === 0 || !this._fieldParams) {
|
|
50
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "StmtBindParams params is invalid!");
|
|
51
|
+
}
|
|
52
|
+
this.paramIndex = 0;
|
|
53
|
+
for (let i = 0; i < bindParams._fieldParams.length; i++) {
|
|
54
|
+
let fieldParam = bindParams._fieldParams[i];
|
|
55
|
+
if (fieldParam) {
|
|
56
|
+
this.addParams(fieldParam.params, fieldParam.dataType, fieldParam.typeLen, fieldParam.columnType);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
encode() {
|
|
61
|
+
this.paramIndex = 0;
|
|
62
|
+
if (!this._fieldParams || this._fieldParams.length == 0) {
|
|
63
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "StmtBindParams params is invalid!");
|
|
64
|
+
}
|
|
65
|
+
if (this._rows > 0) {
|
|
66
|
+
if (this._rows !== this._fieldParams[0].params.length) {
|
|
67
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "wrong row length!");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this._rows = this._fieldParams[0].params.length;
|
|
72
|
+
}
|
|
73
|
+
for (let i = 0; i < this._fieldParams.length; i++) {
|
|
74
|
+
let fieldParam = this._fieldParams[i];
|
|
75
|
+
if (!fieldParam) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
let isVarType = (0, taosResult_1._isVarType)(fieldParam.columnType);
|
|
79
|
+
if (isVarType == constant_1.ColumnsBlockType.SOLID) {
|
|
80
|
+
if (fieldParam.dataType === "TIMESTAMP") {
|
|
81
|
+
this._params.push(this.encodeTimestampColumn(fieldParam.params, fieldParam.typeLen, fieldParam.columnType));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this._params.push(this.encodeDigitColumns(fieldParam.params, fieldParam.dataType, fieldParam.typeLen, fieldParam.columnType));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this._params.push(this.encodeVarColumns(fieldParam.params, fieldParam.dataType, fieldParam.typeLen, fieldParam.columnType));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
encodeVarColumns(params, dataType = 'number', typeLen, columnType) {
|
|
93
|
+
let isNull = [];
|
|
94
|
+
let dataLengths = [];
|
|
95
|
+
// TotalLength(4) + Type (4) + Num(4) + IsNull(1) * size + haveLength(1) + BufferLength(4) + 4 * v.length + totalLength
|
|
96
|
+
// 17 + (5 * params.length) + totalLength;
|
|
97
|
+
let totalLength = 17 + (5 * params.length);
|
|
98
|
+
const bytes = [];
|
|
99
|
+
for (let i = 0; i < params.length; i++) {
|
|
100
|
+
if (!(0, utils_1.isEmpty)(params[i])) {
|
|
101
|
+
isNull.push(0);
|
|
102
|
+
if (typeof params[i] == 'string') {
|
|
103
|
+
let encoder = new TextEncoder().encode(params[i]);
|
|
104
|
+
let length = encoder.length;
|
|
105
|
+
totalLength += length;
|
|
106
|
+
dataLengths.push(length);
|
|
107
|
+
bytes.push(...encoder);
|
|
108
|
+
}
|
|
109
|
+
else if (params[i] instanceof ArrayBuffer) {
|
|
110
|
+
//input arraybuffer, save not need encode
|
|
111
|
+
let value = params[i];
|
|
112
|
+
totalLength += value.byteLength;
|
|
113
|
+
dataLengths.push(value.byteLength);
|
|
114
|
+
bytes.push(...new Uint8Array(value));
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "getColumString params is invalid! param_type:=" + typeof params[i]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
isNull.push(1);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
this._dataTotalLen += totalLength;
|
|
125
|
+
const dataBuffer = new Uint8Array(bytes).buffer;
|
|
126
|
+
return new wsColumnInfo_1.ColumnInfo([totalLength, dataBuffer], columnType, typeLen, this._rows, isNull, dataLengths, 1);
|
|
127
|
+
}
|
|
128
|
+
encodeDigitColumns(params, dataType = 'number', typeLen, columnType) {
|
|
129
|
+
let isNull = [];
|
|
130
|
+
// TotalLength(4) + Type (4) + Num(4) + IsNull(1) * size + haveLength(1) + BufferLength(4) + size * dataLen
|
|
131
|
+
let dataLength = 17 + (typeLen + 1) * params.length;
|
|
132
|
+
let arrayBuffer = new ArrayBuffer(typeLen * params.length);
|
|
133
|
+
let dataBuffer = new DataView(arrayBuffer);
|
|
134
|
+
for (let i = 0; i < params.length; i++) {
|
|
135
|
+
if (!(0, utils_1.isEmpty)(params[i])) {
|
|
136
|
+
isNull.push(0);
|
|
137
|
+
this.writeDataToBuffer(dataBuffer, params[i], dataType, typeLen, columnType, i);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
isNull.push(1);
|
|
141
|
+
if (dataType === 'bigint') {
|
|
142
|
+
this.writeDataToBuffer(dataBuffer, BigInt(0), dataType, typeLen, columnType, i);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this.writeDataToBuffer(dataBuffer, 0, dataType, typeLen, columnType, i);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
this._dataTotalLen += dataLength;
|
|
150
|
+
return new wsColumnInfo_1.ColumnInfo([dataLength, dataBuffer.buffer], columnType, typeLen, this._rows, isNull);
|
|
151
|
+
}
|
|
152
|
+
encodeTimestampColumn(params, typeLen, columnType) {
|
|
153
|
+
let timeStamps = [];
|
|
154
|
+
for (let i = 0; i < params.length; i++) {
|
|
155
|
+
if (!(0, utils_1.isEmpty)(params[i])) {
|
|
156
|
+
let timeStamp = BigInt(0);
|
|
157
|
+
if (params[i] instanceof Date) {
|
|
158
|
+
let date = params[i];
|
|
159
|
+
//node only support milliseconds, need fill 0
|
|
160
|
+
if (this.precisionLength == constant_1.PrecisionLength['us']) {
|
|
161
|
+
timeStamp = BigInt(date.getTime() * 1000);
|
|
162
|
+
}
|
|
163
|
+
else if (this.precisionLength == constant_1.PrecisionLength['ns']) {
|
|
164
|
+
timeStamp = BigInt(date.getTime() * 1000 * 1000);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
timeStamp = BigInt(date.getTime());
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (typeof params[i] == 'bigint' || typeof params[i] == 'number') {
|
|
171
|
+
if (typeof params[i] == 'number') {
|
|
172
|
+
timeStamp = BigInt(params[i]);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
timeStamp = params[i];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
timeStamps.push(timeStamp);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
//set bitmap bit is null
|
|
182
|
+
timeStamps.push(null);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return this.encodeDigitColumns(timeStamps, 'bigint', typeLen, columnType);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.Stmt2BindParams = Stmt2BindParams;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FieldBindParams } from "./FieldBindParams";
|
|
2
|
+
import { ColumnInfo } from "./wsColumnInfo";
|
|
3
|
+
export interface IDataEncoder {
|
|
4
|
+
encode(): void;
|
|
5
|
+
addParams(params: any[], dataType: string, typeLen: number, columnType: number): void;
|
|
6
|
+
mergeParams(bindParams: StmtBindParams): void;
|
|
7
|
+
}
|
|
8
|
+
export declare abstract class StmtBindParams {
|
|
9
|
+
protected readonly precisionLength: number;
|
|
10
|
+
protected readonly _params: ColumnInfo[];
|
|
11
|
+
_fieldParams?: FieldBindParams[];
|
|
12
|
+
protected _dataTotalLen: number;
|
|
13
|
+
protected paramsCount: number;
|
|
14
|
+
protected _rows: number;
|
|
15
|
+
protected _bindCount: number;
|
|
16
|
+
constructor(precision?: number, paramsCount?: number);
|
|
17
|
+
abstract encode(): void;
|
|
18
|
+
abstract addParams(params: any[], dataType: string, typeLen: number, columnType: number): void;
|
|
19
|
+
addBindFieldParams(fieldParams: FieldBindParams): void;
|
|
20
|
+
abstract mergeParams(bindParams: StmtBindParams): void;
|
|
21
|
+
getBindCount(): number;
|
|
22
|
+
getDataRows(): number;
|
|
23
|
+
getDataTotalLen(): number;
|
|
24
|
+
getParams(): ColumnInfo[];
|
|
25
|
+
setBoolean(params: any[]): void;
|
|
26
|
+
setTinyInt(params: any[]): void;
|
|
27
|
+
setUTinyInt(params: any[]): void;
|
|
28
|
+
setSmallInt(params: any[]): void;
|
|
29
|
+
setUSmallInt(params: any[]): void;
|
|
30
|
+
setInt(params: any[]): void;
|
|
31
|
+
setUInt(params: any[]): void;
|
|
32
|
+
setBigint(params: any[]): void;
|
|
33
|
+
setUBigint(params: any[]): void;
|
|
34
|
+
setFloat(params: any[]): void;
|
|
35
|
+
setDouble(params: any[]): void;
|
|
36
|
+
setVarchar(params: any[]): void;
|
|
37
|
+
setBinary(params: any[]): void;
|
|
38
|
+
setNchar(params: any[]): void;
|
|
39
|
+
setJson(params: any[]): void;
|
|
40
|
+
setVarBinary(params: any[]): void;
|
|
41
|
+
setGeometry(params: any[]): void;
|
|
42
|
+
setTimestamp(params: any[]): void;
|
|
43
|
+
protected writeDataToBuffer(dataBuffer: DataView, params: any, dataType: string | undefined, typeLen: number, columnType: number, i: number): void;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=wsParamsBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wsParamsBase.d.ts","sourceRoot":"","sources":["../../../src/stmt/wsParamsBase.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,MAAM,WAAW,YAAY;IACzB,MAAM,IAAI,IAAI,CAAC;IACf,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACtF,WAAW,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI,CAAC;CACjD;AAED,8BAAsB,cAAc;IAChC,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAC,MAAM,CAAwB;IACjE,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC;IACzC,YAAY,CAAC,EAAE,eAAe,EAAE,CAAC;IACjC,SAAS,CAAC,aAAa,EAAC,MAAM,CAAK;IACnC,SAAS,CAAC,WAAW,EAAE,MAAM,CAAK;IAClC,SAAS,CAAC,KAAK,SAAK;IACpB,SAAS,CAAC,UAAU,SAAK;gBAEb,SAAS,CAAC,EAAC,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;IAcnD,QAAQ,CAAC,MAAM,IAAI,IAAI;IAEvB,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAE9F,kBAAkB,CAAC,WAAW,EAAE,eAAe,GAAG,IAAI;IAUtD,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI;IAGtD,YAAY,IAAI,MAAM;IAItB,WAAW,IAAI,MAAM;IAIrB,eAAe,IAAI,MAAM;IAKlB,SAAS,IAAI,UAAU,EAAE;IAIhC,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE;IAOxB,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE;IAOxB,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE;IAQzB,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE;IASzB,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE;IAQ1B,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE;IAQpB,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE;IAQrB,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE;IAQvB,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE;IAQxB,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IAQtB,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE;IAQvB,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE;IAQxB,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE;IAQvB,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IAOtB,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE;IAQrB,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE;IAO1B,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE;IAQzB,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE;IAQ1B,SAAS,CAAC,iBAAiB,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAW,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,EAAC,MAAM,GAAG,IAAI;CAmEnJ"}
|
|
@@ -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;
|
|
@@ -13,9 +14,19 @@ interface StmtParamsInfo {
|
|
|
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
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 {
|
|
@@ -23,5 +34,6 @@ export declare const enum StmtBindType {
|
|
|
23
34
|
STMT_TYPE_BIND = 2
|
|
24
35
|
}
|
|
25
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"}
|