@tachybase/module-multi-app 1.6.0 → 1.6.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.
Files changed (105) hide show
  1. package/README.md +34 -34
  2. package/README.zh-CN.md +34 -34
  3. package/client.d.ts +1 -1
  4. package/client.js +1 -1
  5. package/dist/externalVersion.js +5 -5
  6. package/dist/locale/en-US.json +48 -48
  7. package/dist/locale/es-ES.json +9 -9
  8. package/dist/locale/ko_KR.json +11 -11
  9. package/dist/locale/pt-BR.json +9 -9
  10. package/dist/locale/zh-CN.json +58 -58
  11. package/dist/node_modules/mariadb/callback.js +43 -8
  12. package/dist/node_modules/mariadb/check-node.js +30 -0
  13. package/dist/node_modules/mariadb/lib/cluster-callback.js +84 -0
  14. package/dist/node_modules/mariadb/lib/cluster.js +446 -0
  15. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +576 -177
  16. package/dist/node_modules/mariadb/lib/cmd/change-user.js +54 -44
  17. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +3 -2
  18. package/dist/node_modules/mariadb/lib/cmd/class/prepare-cache-wrapper.js +46 -0
  19. package/dist/node_modules/mariadb/lib/cmd/class/prepare-result-packet.js +141 -0
  20. package/dist/node_modules/mariadb/lib/cmd/class/prepare-wrapper.js +70 -0
  21. package/dist/node_modules/mariadb/lib/cmd/close-prepare.js +38 -0
  22. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +145 -47
  23. package/dist/node_modules/mariadb/lib/cmd/command.js +41 -75
  24. package/dist/node_modules/mariadb/lib/cmd/decoder/binary-decoder.js +282 -0
  25. package/dist/node_modules/mariadb/lib/cmd/decoder/text-decoder.js +210 -0
  26. package/dist/node_modules/mariadb/lib/cmd/{common-binary-cmd.js → encoder/binary-encoder.js} +34 -77
  27. package/dist/node_modules/mariadb/lib/cmd/encoder/text-encoder.js +311 -0
  28. package/dist/node_modules/mariadb/lib/cmd/execute-stream.js +61 -0
  29. package/dist/node_modules/mariadb/lib/cmd/execute.js +338 -0
  30. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +25 -62
  31. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +39 -6
  32. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +48 -16
  33. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/handshake.js +198 -0
  34. package/dist/node_modules/mariadb/lib/cmd/handshake/{initial-handshake.js → auth/initial-handshake.js} +10 -8
  35. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +22 -9
  36. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +9 -4
  37. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/parsec-auth.js +115 -0
  38. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +12 -5
  39. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +44 -33
  40. package/dist/node_modules/mariadb/lib/cmd/handshake/authentication.js +335 -0
  41. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +20 -19
  42. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +6 -3
  43. package/dist/node_modules/mariadb/lib/cmd/parser.js +861 -0
  44. package/dist/node_modules/mariadb/lib/cmd/ping.js +17 -18
  45. package/dist/node_modules/mariadb/lib/cmd/prepare.js +170 -0
  46. package/dist/node_modules/mariadb/lib/cmd/query.js +281 -144
  47. package/dist/node_modules/mariadb/lib/cmd/quit.js +9 -6
  48. package/dist/node_modules/mariadb/lib/cmd/reset.js +15 -19
  49. package/dist/node_modules/mariadb/lib/cmd/stream.js +21 -6
  50. package/dist/node_modules/mariadb/lib/config/cluster-options.js +23 -0
  51. package/dist/node_modules/mariadb/lib/config/connection-options.js +196 -132
  52. package/dist/node_modules/mariadb/lib/config/pool-options.js +27 -19
  53. package/dist/node_modules/mariadb/lib/connection-callback.js +492 -120
  54. package/dist/node_modules/mariadb/lib/connection-promise.js +372 -0
  55. package/dist/node_modules/mariadb/lib/connection.js +1739 -1016
  56. package/dist/node_modules/mariadb/lib/const/capabilities.js +36 -30
  57. package/dist/node_modules/mariadb/lib/const/collations.js +972 -36
  58. package/dist/node_modules/mariadb/lib/const/connection_status.js +3 -0
  59. package/dist/node_modules/mariadb/lib/const/error-code.js +35 -11
  60. package/dist/node_modules/mariadb/lib/const/field-detail.js +3 -0
  61. package/dist/node_modules/mariadb/lib/const/field-type.js +7 -4
  62. package/dist/node_modules/mariadb/lib/const/server-status.js +4 -1
  63. package/dist/node_modules/mariadb/lib/const/state-change.js +3 -0
  64. package/dist/node_modules/mariadb/lib/filtered-cluster-callback.js +136 -0
  65. package/dist/node_modules/mariadb/lib/filtered-cluster.js +118 -0
  66. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +14 -13
  67. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +21 -18
  68. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +75 -64
  69. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +13 -9
  70. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +12 -10
  71. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +402 -134
  72. package/dist/node_modules/mariadb/lib/io/packet.js +287 -202
  73. package/dist/node_modules/mariadb/lib/lru-prepare-cache.js +84 -0
  74. package/dist/node_modules/mariadb/lib/misc/connection-information.js +15 -32
  75. package/dist/node_modules/mariadb/lib/misc/errors.js +68 -25
  76. package/dist/node_modules/mariadb/lib/misc/parse.js +207 -711
  77. package/dist/node_modules/mariadb/lib/misc/utils.js +34 -62
  78. package/dist/node_modules/mariadb/lib/pool-callback.js +213 -174
  79. package/dist/node_modules/mariadb/lib/pool-promise.js +228 -94
  80. package/dist/node_modules/mariadb/lib/pool.js +951 -0
  81. package/dist/node_modules/mariadb/package.json +1 -1
  82. package/dist/node_modules/mariadb/promise.js +1 -34
  83. package/dist/node_modules/mariadb/types/callback.d.ts +207 -0
  84. package/dist/node_modules/mariadb/types/index.d.ts +94 -674
  85. package/dist/node_modules/mariadb/types/share.d.ts +804 -0
  86. package/dist/node_modules/qs/package.json +1 -1
  87. package/dist/server/actions/apps.js +2 -2
  88. package/dist/server/app-lifecycle.d.ts +1 -1
  89. package/dist/server/app-lifecycle.js +4 -4
  90. package/dist/server/models/application.d.ts +1 -1
  91. package/package.json +7 -7
  92. package/server.d.ts +2 -2
  93. package/server.js +1 -1
  94. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
  95. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
  96. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
  97. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
  98. package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
  99. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
  100. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
  101. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
  102. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
  103. package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
  104. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
  105. package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
@@ -1,607 +0,0 @@
1
- 'use strict';
2
-
3
- const Command = require('./command');
4
- const ServerStatus = require('../const/server-status');
5
- const ColumnDefinition = require('./column-definition');
6
- const Errors = require('../misc/errors');
7
- const fs = require('fs');
8
- const Parse = require('../misc/parse');
9
-
10
- /**
11
- * handle COM_QUERY / COM_STMT_EXECUTE results
12
- * see : https://mariadb.com/kb/en/library/4-server-response-packets/
13
- */
14
- class ResultSet extends Command {
15
- constructor(resolve, reject) {
16
- super(resolve, reject);
17
- this._responseIndex = 0;
18
- this._rows = [];
19
- }
20
-
21
- /**
22
- * Read Query response packet.
23
- * packet can be :
24
- * - a result-set
25
- * - an ERR_Packet
26
- * - a OK_Packet
27
- * - LOCAL_INFILE Packet
28
- *
29
- * @param packet query response
30
- * @param out output writer
31
- * @param opts connection options
32
- * @param info connection info
33
- */
34
- readResponsePacket(packet, out, opts, info) {
35
- switch (packet.peek()) {
36
- //*********************************************************************************************************
37
- //* OK response
38
- //*********************************************************************************************************
39
- case 0x00:
40
- return this.readOKPacket(packet, out, opts, info);
41
-
42
- //*********************************************************************************************************
43
- //* ERROR response
44
- //*********************************************************************************************************
45
- case 0xff:
46
- const err = packet.readError(info, this.displaySql(), this.stack);
47
- //force in transaction status, since query will have created a transaction if autocommit is off
48
- //goal is to avoid unnecessary COMMIT/ROLLBACK.
49
- info.status |= ServerStatus.STATUS_IN_TRANS;
50
- return this.throwError(err, info);
51
-
52
- //*********************************************************************************************************
53
- //* LOCAL INFILE response
54
- //*********************************************************************************************************
55
- case 0xfb:
56
- return this.readLocalInfile(packet, out, opts, info);
57
-
58
- //*********************************************************************************************************
59
- //* ResultSet
60
- //*********************************************************************************************************
61
- default:
62
- return this.readResultSet(packet);
63
- }
64
- }
65
-
66
- /**
67
- * Read result-set packets :
68
- * see https://mariadb.com/kb/en/library/resultset/
69
- *
70
- * @param packet Column count packet
71
- * @returns {ResultSet.readColumn} next packet handler
72
- */
73
- readResultSet(packet) {
74
- this._columnCount = packet.readUnsignedLength();
75
- this._getValue = this.opts.typeCast ? this.readCastValue : this.readRowData;
76
- this._rows.push([]);
77
- this._columns = [];
78
-
79
- this.onPacketReceive = this.readColumn;
80
- }
81
-
82
- /**
83
- * Assign global configuration option used by result-set to current query option.
84
- * a little faster than Object.assign() since doest copy all information
85
- *
86
- * @param connOpts connection global configuration
87
- * @param cmdOpts specific command options
88
- */
89
- configAssign(connOpts, cmdOpts) {
90
- if (!cmdOpts) {
91
- this.opts = connOpts;
92
- return;
93
- }
94
- this.opts = {
95
- timeout: cmdOpts.timeout,
96
- autoJsonMap: connOpts.autoJsonMap,
97
- arrayParenthesis: connOpts.arrayParenthesis,
98
- supportBigInt:
99
- cmdOpts.supportBigInt != undefined ? cmdOpts.supportBigInt : connOpts.supportBigInt,
100
- checkDuplicate:
101
- cmdOpts.checkDuplicate != undefined ? cmdOpts.checkDuplicate : connOpts.checkDuplicate,
102
- typeCast: cmdOpts.typeCast != undefined ? cmdOpts.typeCast : connOpts.typeCast,
103
- rowsAsArray: cmdOpts.rowsAsArray != undefined ? cmdOpts.rowsAsArray : connOpts.rowsAsArray,
104
- nestTables: cmdOpts.nestTables != undefined ? cmdOpts.nestTables : connOpts.nestTables,
105
- dateStrings: cmdOpts.dateStrings != undefined ? cmdOpts.dateStrings : connOpts.dateStrings,
106
- tz: cmdOpts.tz != undefined ? cmdOpts.tz : connOpts.tz,
107
- pipelining: connOpts.pipelining,
108
- _localTz: cmdOpts.localTz != undefined ? cmdOpts.localTz : connOpts._localTz,
109
- namedPlaceholders:
110
- cmdOpts.namedPlaceholders != undefined
111
- ? cmdOpts.namedPlaceholders
112
- : connOpts.namedPlaceholders,
113
- maxAllowedPacket:
114
- cmdOpts.maxAllowedPacket != undefined
115
- ? cmdOpts.maxAllowedPacket
116
- : connOpts.maxAllowedPacket,
117
- supportBigNumbers:
118
- cmdOpts.supportBigNumbers != undefined
119
- ? cmdOpts.supportBigNumbers
120
- : connOpts.supportBigNumbers,
121
- permitSetMultiParamEntries:
122
- cmdOpts.permitSetMultiParamEntries != undefined
123
- ? cmdOpts.permitSetMultiParamEntries
124
- : connOpts.permitSetMultiParamEntries,
125
- bigNumberStrings:
126
- cmdOpts.bigNumberStrings != undefined ? cmdOpts.bigNumberStrings : connOpts.bigNumberStrings
127
- };
128
- }
129
-
130
- /**
131
- * Read OK_Packet.
132
- * see https://mariadb.com/kb/en/library/ok_packet/
133
- *
134
- * @param packet OK_Packet
135
- * @param opts connection options
136
- * @param info connection information
137
- * @param out output writer
138
- * @returns {*} null or {Resultset.readResponsePacket} in case of multi-result-set
139
- */
140
- readOKPacket(packet, out, opts, info) {
141
- const okPacket = this.parseOkPacket(packet, out, opts, info);
142
- this._rows.push(okPacket);
143
-
144
- if (info.status & ServerStatus.MORE_RESULTS_EXISTS) {
145
- this._responseIndex++;
146
- return (this.onPacketReceive = this.readResponsePacket);
147
- }
148
- this.success(this._responseIndex === 0 ? this._rows[0] : this._rows);
149
- }
150
-
151
- /**
152
- * Read COM_STMT_PREPARE response Packet.
153
- * see https://mariadb.com/kb/en/library/com_stmt_prepare/#com_stmt_prepare-response
154
- *
155
- * @param packet COM_STMT_PREPARE_OK packet
156
- * @param opts connection options
157
- * @param info connection information
158
- * @param out output writer
159
- * @returns {*} null or {Resultset.readResponsePacket} in case of multi-result-set
160
- */
161
- readPrepareResultPacket(packet, out, opts, info) {
162
- switch (packet.peek()) {
163
- //*********************************************************************************************************
164
- //* OK response
165
- //*********************************************************************************************************
166
- case 0x00:
167
- packet.skip(1); //skip header
168
- this.statementId = packet.readInt32();
169
- this.columnNo = packet.readUInt16();
170
- this.parameterNo = packet.readUInt16();
171
-
172
- if (this.columnNo > 0) return (this.onPacketReceive = this.skipColumnsPacket);
173
- if (this.parameterNo > 0) return (this.onPacketReceive = this.skipParameterPacket);
174
- return this.success();
175
-
176
- //*********************************************************************************************************
177
- //* ERROR response
178
- //*********************************************************************************************************
179
- case 0xff:
180
- const err = packet.readError(info, this.displaySql(), this.stack);
181
- //force in transaction status, since query will have created a transaction if autocommit is off
182
- //goal is to avoid unnecessary COMMIT/ROLLBACK.
183
- info.status |= ServerStatus.STATUS_IN_TRANS;
184
- this.onPacketReceive = this.readResponsePacket;
185
- return this.throwError(err, info);
186
-
187
- //*********************************************************************************************************
188
- //* Unexpected response
189
- //*********************************************************************************************************
190
- default:
191
- info.status |= ServerStatus.STATUS_IN_TRANS;
192
- this.onPacketReceive = this.readResponsePacket;
193
- return this.throwError(Errors.ER_UNEXPECTED_PACKET, info);
194
- }
195
- }
196
-
197
- skipColumnsPacket(packet, out, opts, info) {
198
- this.columnNo--;
199
- if (this.columnNo === 0) {
200
- if (info.eofDeprecated) {
201
- if (this.parameterNo > 0) return (this.onPacketReceive = this.skipParameterPacket);
202
- this.success();
203
- }
204
- return (this.onPacketReceive = this.skipEofPacket);
205
- }
206
- }
207
-
208
- skipEofPacket(packet, out, opts, info) {
209
- if (this.parameterNo > 0) return (this.onPacketReceive = this.skipParameterPacket);
210
- this.success();
211
- }
212
-
213
- skipParameterPacket(packet, out, opts, info) {
214
- this.parameterNo--;
215
- if (this.parameterNo === 0) {
216
- if (info.eofDeprecated) return this.success();
217
- return (this.onPacketReceive = this.skipEofPacket);
218
- }
219
- }
220
-
221
- success(val) {
222
- this.successEnd(val);
223
- this._columns = null;
224
- this._rows = null;
225
- }
226
-
227
- /**
228
- * Read column information metadata
229
- * see https://mariadb.com/kb/en/library/resultset/#column-definition-packet
230
- *
231
- * @param packet column definition packet
232
- * @param out output writer
233
- * @param opts connection options
234
- * @param info connection information
235
- * @returns {*}
236
- */
237
- readColumn(packet, out, opts, info) {
238
- if (this._columns.length !== this._columnCount) {
239
- this._columns.push(new ColumnDefinition(packet, info));
240
- }
241
-
242
- // last column
243
- if (this._columns.length === this._columnCount) {
244
- if (this.opts.rowsAsArray) {
245
- this.parseRow = this.parseRowAsArray;
246
- } else {
247
- this.tableHeader = new Array(this._columnCount);
248
- if (this.opts.nestTables) {
249
- this.parseRow = this.parseRowStd;
250
- if (typeof this.opts.nestTables === 'string') {
251
- for (let i = 0; i < this._columnCount; i++) {
252
- this.tableHeader[i] =
253
- this._columns[i].table() + this.opts.nestTables + this._columns[i].name();
254
- }
255
- this.checkDuplicates();
256
- } else if (this.opts.nestTables === true) {
257
- this.parseRow = this.parseRowNested;
258
- for (let i = 0; i < this._columnCount; i++) {
259
- this.tableHeader[i] = [this._columns[i].table(), this._columns[i].name()];
260
- }
261
- this.checkNestTablesDuplicates();
262
- }
263
- } else {
264
- this.parseRow = this.parseRowStd;
265
- for (let i = 0; i < this._columnCount; i++) {
266
- this.tableHeader[i] = this._columns[i].name();
267
- }
268
- this.checkDuplicates();
269
- }
270
- }
271
-
272
- this.emit('fields', this._columns);
273
-
274
- return (this.onPacketReceive = info.eofDeprecated
275
- ? this.readResultSetRow
276
- : this.readIntermediateEOF);
277
- }
278
- }
279
-
280
- checkDuplicates() {
281
- if (this.opts.checkDuplicate) {
282
- for (let i = 0; i < this._columnCount; i++) {
283
- if (this.tableHeader.indexOf(this.tableHeader[i], i + 1) > 0) {
284
- const dupes = this.tableHeader.reduce(
285
- (acc, v, i, arr) =>
286
- arr.indexOf(v) !== i && acc.indexOf(v) === -1 ? acc.concat(v) : acc,
287
- []
288
- );
289
- this.throwUnexpectedError(
290
- 'Error in results, duplicate field name `' +
291
- dupes[0] +
292
- '`.\n' +
293
- '(see option `checkDuplicate`)',
294
- false,
295
- null,
296
- '42000',
297
- Errors.ER_DUPLICATE_FIELD
298
- );
299
- }
300
- }
301
- }
302
- }
303
-
304
- checkNestTablesDuplicates() {
305
- if (this.opts.checkDuplicate) {
306
- for (let i = 0; i < this._columnCount; i++) {
307
- for (let j = 0; j < i; j++) {
308
- if (
309
- this.tableHeader[j][0] === this.tableHeader[i][0] &&
310
- this.tableHeader[j][1] === this.tableHeader[i][1]
311
- ) {
312
- this.throwUnexpectedError(
313
- 'Error in results, duplicate field name `' +
314
- this.tableHeader[i][0] +
315
- '`.`' +
316
- this.tableHeader[i][1] +
317
- '`\n' +
318
- '(see option `checkDuplicate`)',
319
- false,
320
- null,
321
- '42000',
322
- Errors.ER_DUPLICATE_FIELD
323
- );
324
- }
325
- }
326
- }
327
- }
328
- }
329
-
330
- /**
331
- * Read intermediate EOF.
332
- * _only for server before MariaDB 10.2 / MySQL 5.7 that doesn't have CLIENT_DEPRECATE_EOF capability_
333
- * see https://mariadb.com/kb/en/library/eof_packet/
334
- *
335
- * @param packet EOF Packet
336
- * @param out output writer
337
- * @param opts connection options
338
- * @param info connection information
339
- * @returns {*}
340
- */
341
- readIntermediateEOF(packet, out, opts, info) {
342
- if (packet.peek() !== 0xfe) {
343
- return this.throwNewError(
344
- 'Error in protocol, expected EOF packet',
345
- true,
346
- info,
347
- '42000',
348
- Errors.ER_EOF_EXPECTED
349
- );
350
- }
351
-
352
- //before MySQL 5.7.5, last EOF doesn't contain the good flag SERVER_MORE_RESULTS_EXISTS
353
- //for OUT parameters. It must be checked here
354
- //(5.7.5 does have the CLIENT_DEPRECATE_EOF capability, so this packet in not even send)
355
- packet.skip(3);
356
- info.status = packet.readUInt16();
357
- this.isOutParameter = info.status & ServerStatus.PS_OUT_PARAMS;
358
-
359
- this.onPacketReceive = this.readResultSetRow;
360
- }
361
-
362
- handleNewRows(row) {
363
- this._rows[this._responseIndex].push(row);
364
- }
365
-
366
- /**
367
- * Check if packet is result-set end = EOF of OK_Packet with EOF header according to CLIENT_DEPRECATE_EOF capability
368
- * or a result-set row
369
- *
370
- * @param packet current packet
371
- * @param out output writer
372
- * @param opts connection options
373
- * @param info connection information
374
- * @returns {*}
375
- */
376
- readResultSetRow(packet, out, opts, info) {
377
- if (packet.peek() >= 0xfe) {
378
- if (packet.peek() === 0xff) {
379
- const err = packet.readError(info, this.displaySql(), this.stack);
380
- //force in transaction status, since query will have created a transaction if autocommit is off
381
- //goal is to avoid unnecessary COMMIT/ROLLBACK.
382
- info.status |= ServerStatus.STATUS_IN_TRANS;
383
- return this.throwError(err, info);
384
- }
385
-
386
- if (
387
- (!info.eofDeprecated && packet.length() < 13) ||
388
- (info.eofDeprecated && packet.length() < 0xffffff)
389
- ) {
390
- if (!info.eofDeprecated) {
391
- packet.skip(3);
392
- info.status = packet.readUInt16();
393
- } else {
394
- packet.skip(1); //skip header
395
- packet.skipLengthCodedNumber(); //skip update count
396
- packet.skipLengthCodedNumber(); //skip insert id
397
- info.status = packet.readUInt16();
398
- }
399
-
400
- if (opts.metaAsArray) {
401
- //return promise object as array :
402
- // example for SELECT 1 =>
403
- // [
404
- // [ {"1": 1} ], //rows
405
- // [ColumnDefinition] //meta
406
- // ]
407
- if (!this._meta) {
408
- this._meta = new Array(this._responseIndex);
409
- }
410
-
411
- this._meta[this._responseIndex] = this._columns;
412
-
413
- if (info.status & ServerStatus.MORE_RESULTS_EXISTS || this.isOutParameter) {
414
- this._responseIndex++;
415
- return (this.onPacketReceive = this.readResponsePacket);
416
- }
417
- this.success(
418
- this._responseIndex === 0 ? [this._rows[0], this._meta[0]] : [this._rows, this._meta]
419
- );
420
- } else {
421
- //return promise object as rows that have meta property :
422
- // example for SELECT 1 =>
423
- // [
424
- // {"1": 1},
425
- // meta: [ColumnDefinition]
426
- // ]
427
- this._rows[this._responseIndex].meta = this._columns;
428
- if (info.status & ServerStatus.MORE_RESULTS_EXISTS || this.isOutParameter) {
429
- this._responseIndex++;
430
- return (this.onPacketReceive = this.readResponsePacket);
431
- }
432
- this.success(this._responseIndex === 0 ? this._rows[0] : this._rows);
433
- }
434
-
435
- return;
436
- }
437
- }
438
-
439
- const row = this.parseRow(this._columns, packet, opts);
440
- this.handleNewRows(row);
441
- }
442
-
443
- /**
444
- * Display current SQL with parameters (truncated if too big)
445
- *
446
- * @returns {string}
447
- */
448
- displaySql() {
449
- if (this.opts && this.initialValues) {
450
- if (this.sql.length > this.opts.debugLen) {
451
- return this.sql.substring(0, this.opts.debugLen) + '...';
452
- }
453
-
454
- let sqlMsg = this.sql + ' - parameters:';
455
- return this.logParameters(sqlMsg, this.initialValues);
456
- }
457
- return this.sql + ' - parameters:[]';
458
- }
459
-
460
- logParameters(sqlMsg, values) {
461
- if (this.opts.namedPlaceholders) {
462
- sqlMsg += '{';
463
- let first = true;
464
- for (let key in values) {
465
- if (first) {
466
- first = false;
467
- } else {
468
- sqlMsg += ',';
469
- }
470
- sqlMsg += "'" + key + "':";
471
- let param = values[key];
472
- sqlMsg = ResultSet.logParam(sqlMsg, param);
473
- if (sqlMsg.length > this.opts.debugLen) {
474
- sqlMsg = sqlMsg.substr(0, this.opts.debugLen) + '...';
475
- break;
476
- }
477
- }
478
- sqlMsg += '}';
479
- } else {
480
- sqlMsg += '[';
481
- if (Array.isArray(values)) {
482
- for (let i = 0; i < values.length; i++) {
483
- if (i !== 0) sqlMsg += ',';
484
- let param = values[i];
485
- sqlMsg = ResultSet.logParam(sqlMsg, param);
486
- if (sqlMsg.length > this.opts.debugLen) {
487
- sqlMsg = sqlMsg.substr(0, this.opts.debugLen) + '...';
488
- break;
489
- }
490
- }
491
- } else {
492
- sqlMsg = ResultSet.logParam(sqlMsg, values);
493
- if (sqlMsg.length > this.opts.debugLen) {
494
- sqlMsg = sqlMsg.substr(0, this.opts.debugLen) + '...';
495
- }
496
- }
497
- sqlMsg += ']';
498
- }
499
- return sqlMsg;
500
- }
501
-
502
- readLocalInfile(packet, out, opts, info) {
503
- packet.skip(1); //skip header
504
- out.startPacket(this);
505
-
506
- const fileName = packet.readStringRemaining();
507
-
508
- if (!Parse.validateFileName(this.sql, this.initialValues, fileName)) {
509
- out.writeEmptyPacket();
510
- const error = Errors.createError(
511
- "LOCAL INFILE wrong filename. '" +
512
- fileName +
513
- "' doesn't correspond to query " +
514
- this.sql +
515
- '. Query cancelled. Check for malicious server / proxy',
516
- this.sql,
517
- false,
518
- info,
519
- 'HY000',
520
- Errors.ER_LOCAL_INFILE_WRONG_FILENAME
521
- );
522
-
523
- process.nextTick(this.reject, error);
524
- this.reject = null;
525
- this.resolve = null;
526
- return (this.onPacketReceive = this.readResponsePacket);
527
- }
528
-
529
- // this.sequenceNo = 2;
530
- // this.compressSequenceNo = 2;
531
- const stream = fs.createReadStream(fileName);
532
- stream.on('error', (err) => {
533
- out.writeEmptyPacket();
534
- const error = Errors.createError(
535
- 'LOCAL INFILE command failed: ' + err.message,
536
- this.sql,
537
- false,
538
- info,
539
- '22000',
540
- Errors.ER_LOCAL_INFILE_NOT_READABLE
541
- );
542
- process.nextTick(this.reject, error);
543
- this.reject = null;
544
- this.resolve = null;
545
- });
546
- stream.on('data', (chunk) => {
547
- out.writeBuffer(chunk, 0, chunk.length);
548
- });
549
- stream.on('end', () => {
550
- if (!out.isEmpty()) {
551
- out.flushBuffer(false);
552
- }
553
- out.writeEmptyPacket();
554
- });
555
- this.onPacketReceive = this.readResponsePacket;
556
- }
557
-
558
- static logParam(sqlMsg, param) {
559
- if (param === undefined || param === null) {
560
- sqlMsg += param === undefined ? 'undefined' : 'null';
561
- } else {
562
- switch (param.constructor.name) {
563
- case 'Buffer':
564
- sqlMsg += '0x' + param.toString('hex', 0, Math.min(1024, param.length)) + '';
565
- break;
566
-
567
- case 'String':
568
- sqlMsg += "'" + param + "'";
569
- break;
570
-
571
- case 'Date':
572
- sqlMsg += getStringDate(param);
573
- break;
574
-
575
- case 'Object':
576
- sqlMsg += JSON.stringify(param);
577
- break;
578
-
579
- default:
580
- sqlMsg += param.toString();
581
- }
582
- }
583
- return sqlMsg;
584
- }
585
- }
586
-
587
- function getStringDate(param) {
588
- return (
589
- "'" +
590
- ('00' + (param.getMonth() + 1)).slice(-2) +
591
- '/' +
592
- ('00' + param.getDate()).slice(-2) +
593
- '/' +
594
- param.getFullYear() +
595
- ' ' +
596
- ('00' + param.getHours()).slice(-2) +
597
- ':' +
598
- ('00' + param.getMinutes()).slice(-2) +
599
- ':' +
600
- ('00' + param.getSeconds()).slice(-2) +
601
- '.' +
602
- ('000' + param.getMilliseconds()).slice(-3) +
603
- "'"
604
- );
605
- }
606
-
607
- module.exports = ResultSet;
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- class PoolClusterOptions {
4
- constructor(opts) {
5
- if (opts) {
6
- this.canRetry = opts.canRetry === undefined ? true : opts.canRetry;
7
- this.removeNodeErrorCount = opts.removeNodeErrorCount || 5;
8
- this.restoreNodeTimeout = opts.restoreNodeTimeout || 1000;
9
- this.defaultSelector = opts.defaultSelector || 'RR';
10
- } else {
11
- this.canRetry = true;
12
- this.removeNodeErrorCount = 5;
13
- this.restoreNodeTimeout = 1000;
14
- this.defaultSelector = 'RR';
15
- }
16
- }
17
- }
18
-
19
- module.exports = PoolClusterOptions;
@@ -1,81 +0,0 @@
1
- /**
2
- * Similar to pool cluster with pre-set pattern and selector.
3
- * Additional method query
4
- *
5
- * @param poolCluster cluster
6
- * @param patternArg pre-set pattern
7
- * @param selectorArg pre-set selector
8
- * @constructor
9
- */
10
- function FilteredPoolCluster(poolCluster, patternArg, selectorArg) {
11
- const cluster = poolCluster;
12
- const pattern = patternArg;
13
- const selector = selectorArg;
14
-
15
- /**
16
- * Get a connection according to previously indicated pattern and selector.
17
- *
18
- * @return {Promise}
19
- */
20
- this.getConnection = () => {
21
- return cluster.getConnection(pattern, selector);
22
- };
23
-
24
- /**
25
- * Execute a query on one connection from available pools matching pattern
26
- * in cluster.
27
- *
28
- * @param sql sql command
29
- * @param value parameter value of sql command (not mandatory)
30
- * @return {Promise}
31
- */
32
- this.query = function (sql, value) {
33
- return cluster
34
- .getConnection(pattern, selector)
35
- .then((conn) => {
36
- return conn
37
- .query(sql, value)
38
- .then((res) => {
39
- conn.end();
40
- return res;
41
- })
42
- .catch((err) => {
43
- conn.end();
44
- return Promise.reject(err);
45
- });
46
- })
47
- .catch((err) => {
48
- return Promise.reject(err);
49
- });
50
- };
51
-
52
- /**
53
- * Execute a batch on one connection from available pools matching pattern
54
- * in cluster.
55
- *
56
- * @param sql sql command
57
- * @param value parameter value of sql command
58
- * @return {Promise}
59
- */
60
- this.batch = function (sql, value) {
61
- return cluster
62
- .getConnection(pattern, selector)
63
- .then((conn) => {
64
- return conn
65
- .batch(sql, value)
66
- .then((res) => {
67
- conn.end();
68
- return res;
69
- })
70
- .catch((err) => {
71
- conn.end();
72
- return Promise.reject(err);
73
- });
74
- })
75
- .catch((err) => {
76
- return Promise.reject(err);
77
- });
78
- };
79
- }
80
-
81
- module.exports = FilteredPoolCluster;