@tdengine/websocket 3.2.0 → 3.2.2
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/all_type_query.js +26 -22
- package/lib/example/all_type_stmt.js +22 -20
- package/lib/example/basicBatchTmq.js +14 -14
- package/lib/example/basicSchemaless.js +11 -11
- package/lib/example/basicSql.js +10 -10
- package/lib/example/basicStmt.js +3 -3
- package/lib/example/basicTmq.js +8 -9
- package/lib/index.d.ts +0 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -7
- package/lib/src/client/wsClient.d.ts +2 -2
- package/lib/src/client/wsClient.d.ts.map +1 -1
- package/lib/src/client/wsClient.js +60 -37
- package/lib/src/client/wsConnector.d.ts.map +1 -1
- package/lib/src/client/wsConnector.js +40 -14
- package/lib/src/client/wsConnectorPool.d.ts.map +1 -1
- package/lib/src/client/wsConnectorPool.js +29 -14
- package/lib/src/client/wsEventCallback.d.ts.map +1 -1
- package/lib/src/client/wsEventCallback.js +6 -4
- package/lib/src/client/wsResponse.d.ts.map +1 -1
- package/lib/src/client/wsResponse.js +6 -2
- package/lib/src/common/config.d.ts +2 -2
- package/lib/src/common/config.d.ts.map +1 -1
- package/lib/src/common/config.js +5 -5
- package/lib/src/common/constant.d.ts.map +1 -1
- package/lib/src/common/constant.js +27 -27
- package/lib/src/common/log.d.ts +1 -1
- package/lib/src/common/log.d.ts.map +1 -1
- package/lib/src/common/log.js +9 -7
- package/lib/src/common/reqid.d.ts.map +1 -1
- package/lib/src/common/reqid.js +7 -7
- package/lib/src/common/taosResult.d.ts.map +1 -1
- package/lib/src/common/taosResult.js +46 -27
- package/lib/src/common/ut8Helper.d.ts.map +1 -1
- package/lib/src/common/ut8Helper.js +8 -8
- package/lib/src/common/utils.d.ts.map +1 -1
- package/lib/src/common/utils.js +17 -16
- package/lib/src/common/wsError.d.ts.map +1 -1
- package/lib/src/common/wsError.js +3 -3
- package/lib/src/common/wsOptions.d.ts +1 -1
- package/lib/src/index.d.ts +3 -3
- package/lib/src/index.d.ts.map +1 -1
- package/lib/src/sql/wsProto.d.ts.map +1 -1
- package/lib/src/sql/wsRows.d.ts +3 -3
- package/lib/src/sql/wsRows.d.ts.map +1 -1
- package/lib/src/sql/wsRows.js +4 -2
- package/lib/src/sql/wsSql.d.ts +5 -5
- package/lib/src/sql/wsSql.d.ts.map +1 -1
- package/lib/src/sql/wsSql.js +15 -16
- package/lib/src/stmt/FieldBindParams.d.ts.map +1 -1
- package/lib/src/stmt/wsColumnInfo.d.ts.map +1 -1
- package/lib/src/stmt/wsParams1.d.ts.map +1 -1
- package/lib/src/stmt/wsParams1.js +50 -24
- package/lib/src/stmt/wsParams2.d.ts.map +1 -1
- package/lib/src/stmt/wsParams2.js +30 -15
- package/lib/src/stmt/wsParamsBase.d.ts.map +1 -1
- package/lib/src/stmt/wsParamsBase.js +5 -3
- package/lib/src/stmt/wsProto.d.ts.map +1 -1
- package/lib/src/stmt/wsProto.js +22 -11
- package/lib/src/stmt/wsStmt.d.ts.map +1 -1
- package/lib/src/stmt/wsStmt1.d.ts +5 -5
- package/lib/src/stmt/wsStmt1.d.ts.map +1 -1
- package/lib/src/stmt/wsStmt1.js +14 -14
- package/lib/src/stmt/wsStmt2.d.ts +1 -1
- package/lib/src/stmt/wsStmt2.d.ts.map +1 -1
- package/lib/src/stmt/wsStmt2.js +18 -14
- package/lib/src/stmt/wsTableInfo.d.ts.map +1 -1
- package/lib/src/tmq/config.d.ts.map +1 -1
- package/lib/src/tmq/config.js +2 -2
- package/lib/src/tmq/constant.d.ts.map +1 -1
- package/lib/src/tmq/constant.js +28 -28
- package/lib/src/tmq/tmqResponse.d.ts.map +1 -1
- package/lib/src/tmq/tmqResponse.js +30 -16
- package/lib/src/tmq/wsTmq.d.ts +2 -2
- package/lib/src/tmq/wsTmq.d.ts.map +1 -1
- package/lib/src/tmq/wsTmq.js +32 -30
- package/lib/test/bulkPulling/cloud.tmq.test.js +11 -11
- package/lib/test/bulkPulling/decimal.test.js +50 -26
- package/lib/test/bulkPulling/log.test.js +8 -8
- package/lib/test/bulkPulling/queryTables.test.js +255 -49
- package/lib/test/bulkPulling/schemaless.test.js +34 -34
- package/lib/test/bulkPulling/sql.test.js +108 -69
- package/lib/test/bulkPulling/stmt1.func.test.js +96 -96
- package/lib/test/bulkPulling/stmt1.type.test.js +124 -48
- package/lib/test/bulkPulling/stmt2.func.test.js +116 -112
- package/lib/test/bulkPulling/stmt2.type.test.js +124 -48
- package/lib/test/bulkPulling/tmq.test.js +225 -31
- package/lib/test/bulkPulling/utils.test.js +2 -2
- package/lib/test/bulkPulling/wsConnectPool.test.js +18 -18
- package/lib/test/utils.d.ts.map +1 -1
- package/lib/test/utils.js +129 -129
- package/package.json +1 -1
- package/readme.md +1 -0
- package/lib/src/stmt/wsParams.d.ts +0 -41
- package/lib/src/stmt/wsParams.d.ts.map +0 -1
- package/lib/src/stmt/wsParams.js +0 -428
- package/lib/test/bulkPulling/stmt.func.test.d.ts +0 -2
- package/lib/test/bulkPulling/stmt.func.test.d.ts.map +0 -1
- package/lib/test/bulkPulling/stmt.func.test.js +0 -493
- package/lib/test/bulkPulling/stmt.type.test.d.ts +0 -2
- package/lib/test/bulkPulling/stmt.type.test.d.ts.map +0 -1
- package/lib/test/bulkPulling/stmt.type.test.js +0 -316
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const wsConnectorPool_1 = require("../../src/client/wsConnectorPool");
|
|
4
|
-
const config_1 = require("../../src/common/config");
|
|
5
|
-
const log_1 = require("../../src/common/log");
|
|
6
|
-
const wsSql_1 = require("../../src/sql/wsSql");
|
|
7
|
-
const utils_1 = require("../utils");
|
|
8
|
-
const stable = 'ws_stmt_stb';
|
|
9
|
-
const table = 'stmt_001';
|
|
10
|
-
const db = 'ws_stmt';
|
|
11
|
-
const createDB = `create database if not exists ${db} keep 3650`;
|
|
12
|
-
const useDB = `use ${db}`;
|
|
13
|
-
const dropDB = `drop database if exists ${db}`;
|
|
14
|
-
const tableCN = 'stmt_cn';
|
|
15
|
-
const stableCN = 'ws_stmt_stb_cn';
|
|
16
|
-
const jsonTable = 'stmt_json';
|
|
17
|
-
const jsonTableCN = 'stmt_json_cn';
|
|
18
|
-
const stableTags = [true, -1, -2, -3, -4, 1, 2, 3, 4, parseFloat(3.1415.toFixed(5)), parseFloat(3.14159265.toFixed(15)), 'varchar_tag_1', 'nchar_tag_1'];
|
|
19
|
-
const stableCNTags = [false, -1 * 2, -2 * 2, -3 * 2, -4 * 2, 1 * 2, 2 * 2, 3 * 2, 4 * 2, parseFloat((3.1415 * 2).toFixed(5)), parseFloat((3.14159265 * 2).toFixed(15)), 'varchar_标签_壹', 'nchar_标签_贰'];
|
|
20
|
-
const tableValues = [
|
|
21
|
-
[1656677710000, 1656677720000, 1656677730000, 1656677740000, 1656677750000],
|
|
22
|
-
[0, -1, -2, -3, -4],
|
|
23
|
-
[-1, -2, -3, -4, -5],
|
|
24
|
-
[-3, -4, -5, -6, -7],
|
|
25
|
-
// [0, 1, 2, 3, 4],
|
|
26
|
-
[BigInt(-2), BigInt(-3), BigInt(-4), BigInt(-5), BigInt(-6)],
|
|
27
|
-
[0, 1, 2, 3, 4],
|
|
28
|
-
[1, 2, 3, 4, 5],
|
|
29
|
-
[2, 3, 4, 5, 6],
|
|
30
|
-
// [0, 1, 2, 3, 4],
|
|
31
|
-
[BigInt(3), BigInt(4), BigInt(5), BigInt(6), BigInt(7)],
|
|
32
|
-
[parseFloat(3.1415.toFixed(5)), parseFloat((3.1415 * 2).toFixed(5)), parseFloat((3.1415 * 3).toFixed(5)), parseFloat((3.1415 * 4).toFixed(5)), parseFloat((3.1415 * 5).toFixed(5))],
|
|
33
|
-
[parseFloat(3.14159265.toFixed(15)), parseFloat((3.14159265 * 2).toFixed(15)), parseFloat((3.14159265 * 3).toFixed(15)), parseFloat((3.14159265 * 4).toFixed(15)), parseFloat((3.14159265 * 5).toFixed(15))],
|
|
34
|
-
['varchar_col_1', 'varchar_col_2', 'varchar_col_3', 'varchar_col_4', 'varchar_col_5'],
|
|
35
|
-
['nchar_col_1', 'nchar_col_2', '', 'nchar_col_4', 'nchar_col_5'],
|
|
36
|
-
[true, false, true, false, true],
|
|
37
|
-
[null, null, null, null, null]
|
|
38
|
-
];
|
|
39
|
-
const tableCNValues = [
|
|
40
|
-
[BigInt(1656677760000), BigInt(1656677770000), BigInt(1656677780000), BigInt(1656677790000), BigInt(1656677100000)],
|
|
41
|
-
[0, -1, -2, -3, -4],
|
|
42
|
-
[-1, -2, -3, -4, -5],
|
|
43
|
-
[-2, -3, -4, -5, -6],
|
|
44
|
-
[BigInt(-3), BigInt(-4), BigInt(-5), BigInt(-6), BigInt(-7)],
|
|
45
|
-
[0, 1, 2, 3, 4],
|
|
46
|
-
[1, 2, 3, 4, 5],
|
|
47
|
-
[2, 3, 4, 5, 6],
|
|
48
|
-
[BigInt(3), BigInt(4), BigInt(5), BigInt(6), BigInt(7)],
|
|
49
|
-
[parseFloat(3.1415.toFixed(5)), parseFloat((3.1415 * 2).toFixed(5)), parseFloat((3.1415 * 3).toFixed(5)), parseFloat((3.1415 * 4).toFixed(5)), parseFloat((3.1415 * 5).toFixed(5))],
|
|
50
|
-
[parseFloat(3.14159265.toFixed(15)), parseFloat((3.14159265 * 2).toFixed(15)), parseFloat((3.14159265 * 3).toFixed(15)), parseFloat((3.14159265 * 4).toFixed(15)), parseFloat((3.14159265 * 5).toFixed(15))],
|
|
51
|
-
['varchar_列_壹', 'varchar_列_贰', 'varchar_列_叁', 'varchar_列_肆', 'varchar_列_伍'],
|
|
52
|
-
['nchar_列_甲', 'nchar_列_乙', 'nchar_列_丙', 'nchar_列_丁', 'nchar_列_戊'],
|
|
53
|
-
[true, false, true, false, true],
|
|
54
|
-
[null, null, null, null, null],
|
|
55
|
-
];
|
|
56
|
-
let geoDataArray = [];
|
|
57
|
-
let varbinary = [];
|
|
58
|
-
const encoder = new TextEncoder();
|
|
59
|
-
for (let i = 0; i < 5; i++) {
|
|
60
|
-
let data = new Uint8Array([0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
61
|
-
0x00, 0x00, 0x00, 0x59, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x40,]);
|
|
62
|
-
geoDataArray.push(data.buffer);
|
|
63
|
-
let vdata = encoder.encode(`varchar_col_${i + 1}`);
|
|
64
|
-
varbinary.push(vdata.buffer);
|
|
65
|
-
}
|
|
66
|
-
const jsonTags = ["{\"key1\":\"taos\",\"key2\":null,\"key3\":\"TDengine\",\"key4\":0,\"key5\":false}"];
|
|
67
|
-
const jsonTagsCN = ["{\"key1\":\"taosdata\",\"key2\":null,\"key3\":\"TDengine涛思数据\",\"key4\":1,\"key5\":true}"];
|
|
68
|
-
const selectStable = `select * from ${stable}`;
|
|
69
|
-
const selectStableCN = `select * from ${stableCN}`;
|
|
70
|
-
const selectTable = `select * from ${table}`;
|
|
71
|
-
const selectTableCN = `select * from ${tableCN}`;
|
|
72
|
-
const selectJsonTable = `select * from ${jsonTable}`;
|
|
73
|
-
const selectJsonTableCN = `select * from ${jsonTableCN}`;
|
|
74
|
-
let dsn = 'ws://root:taosdata@192.168.2.156:6041';
|
|
75
|
-
(0, log_1.setLevel)("debug");
|
|
76
|
-
beforeAll(async () => {
|
|
77
|
-
let conf = new config_1.WSConfig(dsn);
|
|
78
|
-
let ws = await wsSql_1.WsSql.open(conf);
|
|
79
|
-
await ws.exec(dropDB);
|
|
80
|
-
await ws.exec(createDB);
|
|
81
|
-
await ws.exec(useDB);
|
|
82
|
-
await ws.exec((0, utils_1.createBaseSTable)(stable));
|
|
83
|
-
await ws.exec((0, utils_1.createSTableJSON)(jsonTable));
|
|
84
|
-
await ws.close();
|
|
85
|
-
});
|
|
86
|
-
describe('TDWebSocket.Stmt()', () => {
|
|
87
|
-
jest.setTimeout(20 * 1000);
|
|
88
|
-
test('normal BindParam', async () => {
|
|
89
|
-
let wsConf = new config_1.WSConfig(dsn);
|
|
90
|
-
wsConf.setDb(db);
|
|
91
|
-
let connector = await wsSql_1.WsSql.open(wsConf);
|
|
92
|
-
let stmt = await connector.stmtInit();
|
|
93
|
-
expect(stmt).toBeTruthy();
|
|
94
|
-
expect(connector.state()).toBeGreaterThan(0);
|
|
95
|
-
await stmt.prepare((0, utils_1.getInsertBind)(tableValues.length + 2, stableTags.length, db, stable));
|
|
96
|
-
await stmt.setTableName(table);
|
|
97
|
-
let tagParams = stmt.newStmtParam();
|
|
98
|
-
tagParams.setBoolean([stableTags[0]]);
|
|
99
|
-
tagParams.setTinyInt([stableTags[1]]);
|
|
100
|
-
tagParams.setSmallInt([stableTags[2]]);
|
|
101
|
-
tagParams.setInt([stableTags[3]]);
|
|
102
|
-
tagParams.setBigint([BigInt(stableTags[4])]);
|
|
103
|
-
tagParams.setUTinyInt([stableTags[5]]);
|
|
104
|
-
tagParams.setUSmallInt([stableTags[6]]);
|
|
105
|
-
tagParams.setUInt([stableTags[7]]);
|
|
106
|
-
tagParams.setUBigint([BigInt(stableTags[8])]);
|
|
107
|
-
tagParams.setFloat([stableTags[9]]);
|
|
108
|
-
tagParams.setDouble([stableTags[10]]);
|
|
109
|
-
tagParams.setBinary([stableTags[11]]);
|
|
110
|
-
tagParams.setNchar([stableTags[12]]);
|
|
111
|
-
await stmt.setTags(tagParams);
|
|
112
|
-
let bindParams = stmt.newStmtParam();
|
|
113
|
-
bindParams.setTimestamp(tableValues[0]);
|
|
114
|
-
bindParams.setTinyInt(tableValues[1]);
|
|
115
|
-
bindParams.setSmallInt(tableValues[2]);
|
|
116
|
-
bindParams.setInt(tableValues[3]);
|
|
117
|
-
bindParams.setBigint(tableValues[4]);
|
|
118
|
-
bindParams.setUTinyInt(tableValues[5]);
|
|
119
|
-
bindParams.setUSmallInt(tableValues[6]);
|
|
120
|
-
bindParams.setUInt(tableValues[7]);
|
|
121
|
-
bindParams.setUBigint(tableValues[8]);
|
|
122
|
-
bindParams.setFloat(tableValues[9]);
|
|
123
|
-
bindParams.setDouble(tableValues[10]);
|
|
124
|
-
bindParams.setBinary(tableValues[11]);
|
|
125
|
-
bindParams.setNchar(tableValues[12]);
|
|
126
|
-
bindParams.setBoolean(tableValues[13]);
|
|
127
|
-
bindParams.setInt(tableValues[14]);
|
|
128
|
-
bindParams.setGeometry(geoDataArray);
|
|
129
|
-
bindParams.setVarBinary(varbinary);
|
|
130
|
-
await stmt.bind(bindParams);
|
|
131
|
-
await stmt.batch();
|
|
132
|
-
await stmt.exec();
|
|
133
|
-
expect(stmt.getLastAffected()).toEqual(5);
|
|
134
|
-
await stmt.close();
|
|
135
|
-
let result = await connector.exec(`select * from ${db}.${stable}`);
|
|
136
|
-
console.log(result);
|
|
137
|
-
await connector.close();
|
|
138
|
-
});
|
|
139
|
-
test('normal CN BindParam', async () => {
|
|
140
|
-
let wsConf = new config_1.WSConfig(dsn);
|
|
141
|
-
wsConf.setDb(db);
|
|
142
|
-
let connector = await wsSql_1.WsSql.open(wsConf);
|
|
143
|
-
let stmt = await (await connector).stmtInit();
|
|
144
|
-
expect(stmt).toBeTruthy();
|
|
145
|
-
expect(connector.state()).toBeGreaterThan(0);
|
|
146
|
-
await stmt.prepare((0, utils_1.getInsertBind)(tableValues.length + 2, stableTags.length, db, stable));
|
|
147
|
-
await stmt.setTableName(table);
|
|
148
|
-
let tagParams = stmt.newStmtParam();
|
|
149
|
-
tagParams.setBoolean([stableCNTags[0]]);
|
|
150
|
-
tagParams.setTinyInt([stableCNTags[1]]);
|
|
151
|
-
tagParams.setSmallInt([stableCNTags[2]]);
|
|
152
|
-
tagParams.setInt([stableCNTags[3]]);
|
|
153
|
-
tagParams.setBigint([BigInt(stableCNTags[4])]);
|
|
154
|
-
tagParams.setUTinyInt([stableCNTags[5]]);
|
|
155
|
-
tagParams.setUSmallInt([stableCNTags[6]]);
|
|
156
|
-
tagParams.setUInt([stableCNTags[7]]);
|
|
157
|
-
tagParams.setUBigint([BigInt(stableCNTags[8])]);
|
|
158
|
-
tagParams.setFloat([stableCNTags[9]]);
|
|
159
|
-
tagParams.setDouble([stableCNTags[10]]);
|
|
160
|
-
tagParams.setBinary([stableCNTags[11]]);
|
|
161
|
-
tagParams.setNchar([stableCNTags[12]]);
|
|
162
|
-
await stmt.setTags(tagParams);
|
|
163
|
-
let bindParams = stmt.newStmtParam();
|
|
164
|
-
bindParams.setTimestamp(tableCNValues[0]);
|
|
165
|
-
bindParams.setTinyInt(tableCNValues[1]);
|
|
166
|
-
bindParams.setSmallInt(tableCNValues[2]);
|
|
167
|
-
bindParams.setInt(tableCNValues[3]);
|
|
168
|
-
bindParams.setBigint(tableCNValues[4]);
|
|
169
|
-
bindParams.setUTinyInt(tableCNValues[5]);
|
|
170
|
-
bindParams.setUSmallInt(tableCNValues[6]);
|
|
171
|
-
bindParams.setUInt(tableCNValues[7]);
|
|
172
|
-
bindParams.setUBigint(tableCNValues[8]);
|
|
173
|
-
bindParams.setFloat(tableCNValues[9]);
|
|
174
|
-
bindParams.setDouble(tableCNValues[10]);
|
|
175
|
-
bindParams.setBinary(tableCNValues[11]);
|
|
176
|
-
bindParams.setNchar(tableCNValues[12]);
|
|
177
|
-
bindParams.setBoolean(tableCNValues[13]);
|
|
178
|
-
bindParams.setInt(tableCNValues[14]);
|
|
179
|
-
bindParams.setGeometry(geoDataArray);
|
|
180
|
-
bindParams.setVarBinary(varbinary);
|
|
181
|
-
await stmt.bind(bindParams);
|
|
182
|
-
await stmt.batch();
|
|
183
|
-
await stmt.exec();
|
|
184
|
-
expect(stmt.getLastAffected()).toEqual(5);
|
|
185
|
-
await stmt.close();
|
|
186
|
-
let result = await connector.exec(`select count(*) from ${db}.${stable}`);
|
|
187
|
-
console.log(result);
|
|
188
|
-
await connector.close();
|
|
189
|
-
});
|
|
190
|
-
test('normal json tag BindParam', async () => {
|
|
191
|
-
let wsConf = new config_1.WSConfig(dsn);
|
|
192
|
-
wsConf.setDb(db);
|
|
193
|
-
let connector = await wsSql_1.WsSql.open(wsConf);
|
|
194
|
-
let stmt = await (await connector).stmtInit();
|
|
195
|
-
expect(stmt).toBeTruthy();
|
|
196
|
-
expect(connector.state()).toBeGreaterThan(0);
|
|
197
|
-
await stmt.prepare((0, utils_1.getInsertBind)(tableValues.length + 2, jsonTags.length, db, jsonTable));
|
|
198
|
-
await stmt.setTableName(`${jsonTable}_001`);
|
|
199
|
-
let tagParams = stmt.newStmtParam();
|
|
200
|
-
tagParams.setJson(jsonTags);
|
|
201
|
-
await stmt.setTags(tagParams);
|
|
202
|
-
let bindParams = stmt.newStmtParam();
|
|
203
|
-
bindParams.setTimestamp(tableCNValues[0]);
|
|
204
|
-
bindParams.setTinyInt(tableCNValues[1]);
|
|
205
|
-
bindParams.setSmallInt(tableCNValues[2]);
|
|
206
|
-
bindParams.setInt(tableCNValues[3]);
|
|
207
|
-
bindParams.setBigint(tableCNValues[4]);
|
|
208
|
-
bindParams.setUTinyInt(tableCNValues[5]);
|
|
209
|
-
bindParams.setUSmallInt(tableCNValues[6]);
|
|
210
|
-
bindParams.setUInt(tableCNValues[7]);
|
|
211
|
-
bindParams.setUBigint(tableCNValues[8]);
|
|
212
|
-
bindParams.setFloat(tableCNValues[9]);
|
|
213
|
-
bindParams.setDouble(tableCNValues[10]);
|
|
214
|
-
bindParams.setBinary(tableCNValues[11]);
|
|
215
|
-
bindParams.setNchar(tableCNValues[12]);
|
|
216
|
-
bindParams.setBoolean(tableCNValues[13]);
|
|
217
|
-
bindParams.setInt(tableCNValues[14]);
|
|
218
|
-
bindParams.setGeometry(geoDataArray);
|
|
219
|
-
bindParams.setVarBinary(varbinary);
|
|
220
|
-
await stmt.bind(bindParams);
|
|
221
|
-
await stmt.batch();
|
|
222
|
-
await stmt.exec();
|
|
223
|
-
expect(stmt.getLastAffected()).toEqual(5);
|
|
224
|
-
await stmt.close();
|
|
225
|
-
let result = await connector.exec(`select * from ${db}.${jsonTable}`);
|
|
226
|
-
console.log(result);
|
|
227
|
-
await connector.close();
|
|
228
|
-
});
|
|
229
|
-
test('normal json cn tag BindParam', async () => {
|
|
230
|
-
let wsConf = new config_1.WSConfig(dsn);
|
|
231
|
-
wsConf.setDb(db);
|
|
232
|
-
let connector = await wsSql_1.WsSql.open(wsConf);
|
|
233
|
-
let stmt = await connector.stmtInit();
|
|
234
|
-
expect(stmt).toBeTruthy();
|
|
235
|
-
expect(connector.state()).toBeGreaterThan(0);
|
|
236
|
-
await stmt.prepare((0, utils_1.getInsertBind)(tableValues.length + 2, jsonTags.length, db, jsonTable));
|
|
237
|
-
await stmt.setTableName(`${jsonTable}_001`);
|
|
238
|
-
let tagParams = stmt.newStmtParam();
|
|
239
|
-
tagParams.setJson(jsonTagsCN);
|
|
240
|
-
await stmt.setTags(tagParams);
|
|
241
|
-
let bindParams = stmt.newStmtParam();
|
|
242
|
-
bindParams.setTimestamp(tableCNValues[0]);
|
|
243
|
-
bindParams.setTinyInt(tableCNValues[1]);
|
|
244
|
-
bindParams.setSmallInt(tableCNValues[2]);
|
|
245
|
-
bindParams.setInt(tableCNValues[3]);
|
|
246
|
-
bindParams.setBigint(tableCNValues[4]);
|
|
247
|
-
bindParams.setUTinyInt(tableCNValues[5]);
|
|
248
|
-
bindParams.setUSmallInt(tableCNValues[6]);
|
|
249
|
-
bindParams.setUInt(tableCNValues[7]);
|
|
250
|
-
bindParams.setUBigint(tableCNValues[8]);
|
|
251
|
-
bindParams.setFloat(tableCNValues[9]);
|
|
252
|
-
bindParams.setDouble(tableCNValues[10]);
|
|
253
|
-
bindParams.setBinary(tableCNValues[11]);
|
|
254
|
-
bindParams.setNchar(tableCNValues[12]);
|
|
255
|
-
bindParams.setBoolean(tableCNValues[13]);
|
|
256
|
-
bindParams.setInt(tableCNValues[14]);
|
|
257
|
-
bindParams.setGeometry(geoDataArray);
|
|
258
|
-
bindParams.setVarBinary(varbinary);
|
|
259
|
-
await stmt.bind(bindParams);
|
|
260
|
-
await stmt.batch();
|
|
261
|
-
await stmt.exec();
|
|
262
|
-
expect(stmt.getLastAffected()).toEqual(5);
|
|
263
|
-
await stmt.close();
|
|
264
|
-
let result = await connector.exec(`select * from ${db}.${jsonTable}`);
|
|
265
|
-
console.log(result);
|
|
266
|
-
await connector.close();
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
test('test bind exception cases', async () => {
|
|
270
|
-
let wsConf = new config_1.WSConfig(dsn);
|
|
271
|
-
let connector = await wsSql_1.WsSql.open(wsConf);
|
|
272
|
-
let stmt = await connector.stmtInit();
|
|
273
|
-
const params = stmt.newStmtParam();
|
|
274
|
-
const emptyArrayMethods = [
|
|
275
|
-
{ method: 'setBoolean', name: 'SetBooleanColumn' },
|
|
276
|
-
{ method: 'setTinyInt', name: 'SetTinyIntColumn' },
|
|
277
|
-
{ method: 'setUTinyInt', name: 'SetUTinyIntColumn' },
|
|
278
|
-
{ method: 'setSmallInt', name: 'SetSmallIntColumn' },
|
|
279
|
-
{ method: 'setUSmallInt', name: 'SetSmallIntColumn' },
|
|
280
|
-
{ method: 'setInt', name: 'SetIntColumn' },
|
|
281
|
-
{ method: 'setUInt', name: 'SetUIntColumn' },
|
|
282
|
-
{ method: 'setBigint', name: 'SetBigIntColumn' },
|
|
283
|
-
{ method: 'setUBigint', name: 'SetUBigIntColumn' },
|
|
284
|
-
{ method: 'setFloat', name: 'SetFloatColumn' },
|
|
285
|
-
{ method: 'setDouble', name: 'SetDoubleColumn' },
|
|
286
|
-
{ method: 'setTimestamp', name: 'SeTimestampColumn' }
|
|
287
|
-
];
|
|
288
|
-
emptyArrayMethods.forEach(({ method, name }) => {
|
|
289
|
-
expect(() => {
|
|
290
|
-
params[method]([]);
|
|
291
|
-
}).toThrow(`${name} params is invalid!`);
|
|
292
|
-
expect(() => {
|
|
293
|
-
params[method](null);
|
|
294
|
-
}).toThrow(`${name} params is invalid!`);
|
|
295
|
-
expect(() => {
|
|
296
|
-
params[method](undefined);
|
|
297
|
-
}).toThrow(`${name} params is invalid!`);
|
|
298
|
-
});
|
|
299
|
-
expect(() => {
|
|
300
|
-
params.setBoolean(['not boolean']);
|
|
301
|
-
}).toThrow('SetTinyIntColumn params is invalid!');
|
|
302
|
-
expect(() => {
|
|
303
|
-
params.setTinyInt(['not number']);
|
|
304
|
-
}).toThrow('SetTinyIntColumn params is invalid!');
|
|
305
|
-
expect(() => {
|
|
306
|
-
params.setBigint(['not bigint']);
|
|
307
|
-
}).toThrow('SetTinyIntColumn params is invalid!');
|
|
308
|
-
await connector.close();
|
|
309
|
-
});
|
|
310
|
-
afterAll(async () => {
|
|
311
|
-
// let conf :WSConfig = new WSConfig(dsn)
|
|
312
|
-
// let ws = await WsSql.open(conf);
|
|
313
|
-
// await ws.exec(dropDB);
|
|
314
|
-
// await ws.close();
|
|
315
|
-
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
316
|
-
});
|