@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.
- package/README.md +34 -34
- package/README.zh-CN.md +34 -34
- package/client.d.ts +1 -1
- package/client.js +1 -1
- package/dist/externalVersion.js +5 -5
- package/dist/locale/en-US.json +48 -48
- package/dist/locale/es-ES.json +9 -9
- package/dist/locale/ko_KR.json +11 -11
- package/dist/locale/pt-BR.json +9 -9
- package/dist/locale/zh-CN.json +58 -58
- package/dist/node_modules/mariadb/callback.js +43 -8
- package/dist/node_modules/mariadb/check-node.js +30 -0
- package/dist/node_modules/mariadb/lib/cluster-callback.js +84 -0
- package/dist/node_modules/mariadb/lib/cluster.js +446 -0
- package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +576 -177
- package/dist/node_modules/mariadb/lib/cmd/change-user.js +54 -44
- package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +3 -2
- package/dist/node_modules/mariadb/lib/cmd/class/prepare-cache-wrapper.js +46 -0
- package/dist/node_modules/mariadb/lib/cmd/class/prepare-result-packet.js +141 -0
- package/dist/node_modules/mariadb/lib/cmd/class/prepare-wrapper.js +70 -0
- package/dist/node_modules/mariadb/lib/cmd/close-prepare.js +38 -0
- package/dist/node_modules/mariadb/lib/cmd/column-definition.js +145 -47
- package/dist/node_modules/mariadb/lib/cmd/command.js +41 -75
- package/dist/node_modules/mariadb/lib/cmd/decoder/binary-decoder.js +282 -0
- package/dist/node_modules/mariadb/lib/cmd/decoder/text-decoder.js +210 -0
- package/dist/node_modules/mariadb/lib/cmd/{common-binary-cmd.js → encoder/binary-encoder.js} +34 -77
- package/dist/node_modules/mariadb/lib/cmd/encoder/text-encoder.js +311 -0
- package/dist/node_modules/mariadb/lib/cmd/execute-stream.js +61 -0
- package/dist/node_modules/mariadb/lib/cmd/execute.js +338 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +25 -62
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +39 -6
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +48 -16
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/handshake.js +198 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/{initial-handshake.js → auth/initial-handshake.js} +10 -8
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +22 -9
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +9 -4
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/parsec-auth.js +115 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +12 -5
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +44 -33
- package/dist/node_modules/mariadb/lib/cmd/handshake/authentication.js +335 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +20 -19
- package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +6 -3
- package/dist/node_modules/mariadb/lib/cmd/parser.js +861 -0
- package/dist/node_modules/mariadb/lib/cmd/ping.js +17 -18
- package/dist/node_modules/mariadb/lib/cmd/prepare.js +170 -0
- package/dist/node_modules/mariadb/lib/cmd/query.js +281 -144
- package/dist/node_modules/mariadb/lib/cmd/quit.js +9 -6
- package/dist/node_modules/mariadb/lib/cmd/reset.js +15 -19
- package/dist/node_modules/mariadb/lib/cmd/stream.js +21 -6
- package/dist/node_modules/mariadb/lib/config/cluster-options.js +23 -0
- package/dist/node_modules/mariadb/lib/config/connection-options.js +196 -132
- package/dist/node_modules/mariadb/lib/config/pool-options.js +27 -19
- package/dist/node_modules/mariadb/lib/connection-callback.js +492 -120
- package/dist/node_modules/mariadb/lib/connection-promise.js +372 -0
- package/dist/node_modules/mariadb/lib/connection.js +1739 -1016
- package/dist/node_modules/mariadb/lib/const/capabilities.js +36 -30
- package/dist/node_modules/mariadb/lib/const/collations.js +972 -36
- package/dist/node_modules/mariadb/lib/const/connection_status.js +3 -0
- package/dist/node_modules/mariadb/lib/const/error-code.js +35 -11
- package/dist/node_modules/mariadb/lib/const/field-detail.js +3 -0
- package/dist/node_modules/mariadb/lib/const/field-type.js +7 -4
- package/dist/node_modules/mariadb/lib/const/server-status.js +4 -1
- package/dist/node_modules/mariadb/lib/const/state-change.js +3 -0
- package/dist/node_modules/mariadb/lib/filtered-cluster-callback.js +136 -0
- package/dist/node_modules/mariadb/lib/filtered-cluster.js +118 -0
- package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +14 -13
- package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +21 -18
- package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +75 -64
- package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +13 -9
- package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +12 -10
- package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +402 -134
- package/dist/node_modules/mariadb/lib/io/packet.js +287 -202
- package/dist/node_modules/mariadb/lib/lru-prepare-cache.js +84 -0
- package/dist/node_modules/mariadb/lib/misc/connection-information.js +15 -32
- package/dist/node_modules/mariadb/lib/misc/errors.js +68 -25
- package/dist/node_modules/mariadb/lib/misc/parse.js +207 -711
- package/dist/node_modules/mariadb/lib/misc/utils.js +34 -62
- package/dist/node_modules/mariadb/lib/pool-callback.js +213 -174
- package/dist/node_modules/mariadb/lib/pool-promise.js +228 -94
- package/dist/node_modules/mariadb/lib/pool.js +951 -0
- package/dist/node_modules/mariadb/package.json +1 -1
- package/dist/node_modules/mariadb/promise.js +1 -34
- package/dist/node_modules/mariadb/types/callback.d.ts +207 -0
- package/dist/node_modules/mariadb/types/index.d.ts +94 -674
- package/dist/node_modules/mariadb/types/share.d.ts +804 -0
- package/dist/node_modules/qs/package.json +1 -1
- package/dist/server/actions/apps.js +2 -2
- package/dist/server/app-lifecycle.d.ts +1 -1
- package/dist/server/app-lifecycle.js +4 -4
- package/dist/server/models/application.d.ts +1 -1
- package/package.json +7 -7
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
- package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
- package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
- package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
- package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
- package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
- package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
- package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
- package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
- package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
- package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
2
|
+
// Copyright (c) 2015-2024 MariaDB Corporation Ab
|
|
3
|
+
|
|
1
4
|
'use strict';
|
|
2
|
-
const Long = require('long');
|
|
3
5
|
const hexArray = '0123456789ABCDEF'.split('');
|
|
4
6
|
const Errors = require('../misc/errors');
|
|
5
|
-
const CommonText = require('../cmd/common-text-cmd');
|
|
6
7
|
const Iconv = require('iconv-lite');
|
|
8
|
+
const TextEncoder = require('../cmd/encoder/text-encoder');
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Write bytes/hexadecimal value of a byte array to a string.
|
|
@@ -40,8 +42,7 @@ module.exports.log = function (opts, buf, off, end, header) {
|
|
|
40
42
|
if (posHexa === 0) out.push('| ');
|
|
41
43
|
byteValue = header[pos++] & 0xff;
|
|
42
44
|
out.push(hexArray[byteValue >>> 4], hexArray[byteValue & 0x0f], ' ');
|
|
43
|
-
asciiValue[posHexa++] =
|
|
44
|
-
byteValue > 31 && byteValue < 127 ? String.fromCharCode(byteValue) : '.';
|
|
45
|
+
asciiValue[posHexa++] = byteValue > 31 && byteValue < 127 ? String.fromCharCode(byteValue) : '.';
|
|
45
46
|
if (posHexa === 8) out.push(' ');
|
|
46
47
|
}
|
|
47
48
|
}
|
|
@@ -53,8 +54,7 @@ module.exports.log = function (opts, buf, off, end, header) {
|
|
|
53
54
|
|
|
54
55
|
out.push(hexArray[byteValue >>> 4], hexArray[byteValue & 0x0f], ' ');
|
|
55
56
|
|
|
56
|
-
asciiValue[posHexa++] =
|
|
57
|
-
byteValue > 31 && byteValue < 127 ? String.fromCharCode(byteValue) : '.';
|
|
57
|
+
asciiValue[posHexa++] = byteValue > 31 && byteValue < 127 ? String.fromCharCode(byteValue) : '.';
|
|
58
58
|
|
|
59
59
|
if (posHexa === 8) out.push(' ');
|
|
60
60
|
if (posHexa === 16) {
|
|
@@ -87,65 +87,52 @@ module.exports.log = function (opts, buf, off, end, header) {
|
|
|
87
87
|
return out.join('');
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
+
module.exports.toHexString = (bytes) => {
|
|
91
|
+
return Array.from(bytes, (byte) => {
|
|
92
|
+
return ('0' + (byte & 0xff).toString(16)).slice(-2);
|
|
93
|
+
}).join('');
|
|
94
|
+
};
|
|
95
|
+
|
|
90
96
|
module.exports.escapeId = (opts, info, value) => {
|
|
91
97
|
if (!value || value === '') {
|
|
92
|
-
throw Errors.createError(
|
|
93
|
-
'Cannot escape empty ID value',
|
|
94
|
-
null,
|
|
95
|
-
false,
|
|
96
|
-
info,
|
|
97
|
-
'0A000',
|
|
98
|
-
Errors.ER_NULL_ESCAPEID
|
|
99
|
-
);
|
|
98
|
+
throw Errors.createError('Cannot escape empty ID value', Errors.ER_NULL_ESCAPEID, info, '0A000');
|
|
100
99
|
}
|
|
101
100
|
if (value.includes('\u0000')) {
|
|
102
101
|
throw Errors.createError(
|
|
103
102
|
'Cannot escape ID with null character (u0000)',
|
|
104
|
-
|
|
105
|
-
false,
|
|
103
|
+
Errors.ER_NULL_CHAR_ESCAPEID,
|
|
106
104
|
info,
|
|
107
|
-
'0A000'
|
|
108
|
-
Errors.ER_NULL_CHAR_ESCAPEID
|
|
105
|
+
'0A000'
|
|
109
106
|
);
|
|
110
107
|
}
|
|
111
108
|
|
|
112
|
-
// always return escaped value,
|
|
109
|
+
// always return escaped value, even when there is no special characters
|
|
113
110
|
// to permit working with reserved words
|
|
114
|
-
if (value.match(/^`.+`$/g)) {
|
|
115
|
-
// already escaped
|
|
116
|
-
return value;
|
|
117
|
-
}
|
|
118
111
|
return '`' + value.replace(/`/g, '``') + '`';
|
|
119
112
|
};
|
|
120
113
|
|
|
121
114
|
const escapeParameters = (opts, info, value) => {
|
|
122
|
-
if (value
|
|
115
|
+
if (value == null) return 'NULL';
|
|
123
116
|
|
|
124
117
|
switch (typeof value) {
|
|
125
118
|
case 'boolean':
|
|
126
119
|
return value ? 'true' : 'false';
|
|
127
120
|
case 'bigint':
|
|
128
121
|
case 'number':
|
|
129
|
-
return
|
|
122
|
+
return `${value}`;
|
|
130
123
|
case 'object':
|
|
131
124
|
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
132
|
-
return
|
|
133
|
-
? opts.tz === 'Etc/UTC'
|
|
134
|
-
? CommonText.getUtcDate(value, opts)
|
|
135
|
-
: CommonText.getTimezoneDate(value, opts)
|
|
136
|
-
: CommonText.getLocalDate(value, opts);
|
|
125
|
+
return TextEncoder.getFixedFormatDate(value);
|
|
137
126
|
} else if (Buffer.isBuffer(value)) {
|
|
138
127
|
let stValue;
|
|
139
|
-
if (Buffer.isEncoding(
|
|
140
|
-
stValue = value.toString(
|
|
128
|
+
if (Buffer.isEncoding(info.collation.charset)) {
|
|
129
|
+
stValue = value.toString(info.collation.charset, 0, value.length);
|
|
141
130
|
} else {
|
|
142
|
-
stValue = Iconv.decode(value,
|
|
131
|
+
stValue = Iconv.decode(value, info.collation.charset);
|
|
143
132
|
}
|
|
144
133
|
return "_binary'" + escapeString(stValue) + "'";
|
|
145
134
|
} else if (typeof value.toSqlString === 'function') {
|
|
146
135
|
return "'" + escapeString(String(value.toSqlString())) + "'";
|
|
147
|
-
} else if (Long.isLong(value)) {
|
|
148
|
-
return value.toString();
|
|
149
136
|
} else if (Array.isArray(value)) {
|
|
150
137
|
let out = opts.arrayParenthesis ? '(' : '';
|
|
151
138
|
for (let i = 0; i < value.length; i++) {
|
|
@@ -170,40 +157,28 @@ const escapeParameters = (opts, info, value) => {
|
|
|
170
157
|
//GeoJSON format.
|
|
171
158
|
let prefix =
|
|
172
159
|
info &&
|
|
173
|
-
((info.isMariaDB() && info.hasMinVersion(10, 1, 4)) ||
|
|
174
|
-
(!info.isMariaDB() && info.hasMinVersion(5, 7, 6)))
|
|
160
|
+
((info.isMariaDB() && info.hasMinVersion(10, 1, 4)) || (!info.isMariaDB() && info.hasMinVersion(5, 7, 6)))
|
|
175
161
|
? 'ST_'
|
|
176
162
|
: '';
|
|
177
163
|
switch (value.type) {
|
|
178
164
|
case 'Point':
|
|
179
|
-
return (
|
|
180
|
-
prefix +
|
|
181
|
-
"PointFromText('POINT(" +
|
|
182
|
-
CommonText.geoPointToString(value.coordinates) +
|
|
183
|
-
")')"
|
|
184
|
-
);
|
|
165
|
+
return prefix + "PointFromText('POINT(" + TextEncoder.geoPointToString(value.coordinates) + ")')";
|
|
185
166
|
|
|
186
167
|
case 'LineString':
|
|
187
168
|
return (
|
|
188
|
-
prefix +
|
|
189
|
-
"LineFromText('LINESTRING(" +
|
|
190
|
-
CommonText.geoArrayPointToString(value.coordinates) +
|
|
191
|
-
")')"
|
|
169
|
+
prefix + "LineFromText('LINESTRING(" + TextEncoder.geoArrayPointToString(value.coordinates) + ")')"
|
|
192
170
|
);
|
|
193
171
|
|
|
194
172
|
case 'Polygon':
|
|
195
173
|
return (
|
|
196
|
-
prefix +
|
|
197
|
-
"PolygonFromText('POLYGON(" +
|
|
198
|
-
CommonText.geoMultiArrayPointToString(value.coordinates) +
|
|
199
|
-
")')"
|
|
174
|
+
prefix + "PolygonFromText('POLYGON(" + TextEncoder.geoMultiArrayPointToString(value.coordinates) + ")')"
|
|
200
175
|
);
|
|
201
176
|
|
|
202
177
|
case 'MultiPoint':
|
|
203
178
|
return (
|
|
204
179
|
prefix +
|
|
205
180
|
"MULTIPOINTFROMTEXT('MULTIPOINT(" +
|
|
206
|
-
|
|
181
|
+
TextEncoder.geoArrayPointToString(value.coordinates) +
|
|
207
182
|
")')"
|
|
208
183
|
);
|
|
209
184
|
|
|
@@ -211,23 +186,20 @@ const escapeParameters = (opts, info, value) => {
|
|
|
211
186
|
return (
|
|
212
187
|
prefix +
|
|
213
188
|
"MLineFromText('MULTILINESTRING(" +
|
|
214
|
-
|
|
189
|
+
TextEncoder.geoMultiArrayPointToString(value.coordinates) +
|
|
215
190
|
")')"
|
|
216
191
|
);
|
|
217
192
|
|
|
218
193
|
case 'MultiPolygon':
|
|
219
194
|
return (
|
|
220
|
-
prefix +
|
|
221
|
-
"MPolyFromText('MULTIPOLYGON(" +
|
|
222
|
-
CommonText.geoMultiPolygonToString(value.coordinates) +
|
|
223
|
-
")')"
|
|
195
|
+
prefix + "MPolyFromText('MULTIPOLYGON(" + TextEncoder.geoMultiPolygonToString(value.coordinates) + ")')"
|
|
224
196
|
);
|
|
225
197
|
|
|
226
198
|
case 'GeometryCollection':
|
|
227
199
|
return (
|
|
228
200
|
prefix +
|
|
229
201
|
"GeomCollFromText('GEOMETRYCOLLECTION(" +
|
|
230
|
-
|
|
202
|
+
TextEncoder.geometricCollectionToString(value.geometries) +
|
|
231
203
|
")')"
|
|
232
204
|
);
|
|
233
205
|
}
|
|
@@ -271,17 +243,17 @@ const LITTERAL_ESCAPE = {
|
|
|
271
243
|
'\\': '\\\\'
|
|
272
244
|
};
|
|
273
245
|
|
|
274
|
-
const
|
|
275
|
-
const pattern = /[\u0000'"\b\n\r\t\u001A\\]/g;
|
|
246
|
+
const CHARS_GLOBAL_REGEXP = /[\000\032"'\\\b\n\r\t]/g;
|
|
276
247
|
|
|
248
|
+
const escapeString = (val) => {
|
|
277
249
|
let offset = 0;
|
|
278
250
|
let escaped = '';
|
|
279
251
|
let match;
|
|
280
252
|
|
|
281
|
-
while ((match =
|
|
253
|
+
while ((match = CHARS_GLOBAL_REGEXP.exec(val))) {
|
|
282
254
|
escaped += val.substring(offset, match.index);
|
|
283
255
|
escaped += LITTERAL_ESCAPE[match[0]];
|
|
284
|
-
offset =
|
|
256
|
+
offset = CHARS_GLOBAL_REGEXP.lastIndex;
|
|
285
257
|
}
|
|
286
258
|
|
|
287
259
|
if (offset === 0) {
|
|
@@ -1,149 +1,110 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
2
|
+
// Copyright (c) 2015-2025 MariaDB Corporation Ab
|
|
3
|
+
|
|
1
4
|
'use strict';
|
|
2
5
|
|
|
3
|
-
const
|
|
4
|
-
|
|
6
|
+
const { EventEmitter } = require('events');
|
|
7
|
+
|
|
8
|
+
const Pool = require('./pool');
|
|
5
9
|
const Errors = require('./misc/errors');
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
function PoolCallback(options) {
|
|
9
|
-
const processTaskCallback = function (conn, sql, values, isBatch) {
|
|
10
|
-
if (sql) {
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
const fct = isBatch ? conn.batch : conn.query;
|
|
13
|
-
fct(sql, values, (err, rows, fields) => {
|
|
14
|
-
conn.releaseWithoutError();
|
|
15
|
-
if (err) {
|
|
16
|
-
reject(err);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
return resolve(rows);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
return Promise.resolve(conn);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const pingPromise = function (conn) {
|
|
28
|
-
return new Promise((resolve, reject) => {
|
|
29
|
-
conn.ping(options.pingTimeout, (err) => {
|
|
30
|
-
if (err) {
|
|
31
|
-
reject(err);
|
|
32
|
-
} else resolve();
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const createConnectionPoolCallback = function (pool) {
|
|
38
|
-
const conn = new ConnectionCallback(options.connOptions);
|
|
39
|
-
return new Promise(function (resolve, reject) {
|
|
40
|
-
conn.connect((err) => {
|
|
41
|
-
if (err) {
|
|
42
|
-
reject(err);
|
|
43
|
-
} else {
|
|
44
|
-
if (pool.closed) {
|
|
45
|
-
//discard connection
|
|
46
|
-
conn.end((err) => {});
|
|
47
|
-
reject(
|
|
48
|
-
Errors.createError(
|
|
49
|
-
'Cannot create new connection to pool, pool closed',
|
|
50
|
-
null,
|
|
51
|
-
true,
|
|
52
|
-
null,
|
|
53
|
-
'08S01',
|
|
54
|
-
Errors.ER_ADD_CONNECTION_CLOSED_POOL,
|
|
55
|
-
null
|
|
56
|
-
)
|
|
57
|
-
);
|
|
58
|
-
} else {
|
|
59
|
-
const initialEnd = conn.end;
|
|
60
|
-
conn.forceEnd = () => {
|
|
61
|
-
return new Promise(function (res, rej) {
|
|
62
|
-
initialEnd((err) => {
|
|
63
|
-
if (err) {
|
|
64
|
-
rej(err);
|
|
65
|
-
} else {
|
|
66
|
-
res();
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
conn.release = function (cb) {
|
|
73
|
-
if (pool.closed) {
|
|
74
|
-
pool._discardConnection(conn);
|
|
75
|
-
if (cb) cb();
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (options.noControlAfterUse) {
|
|
79
|
-
pool._releaseConnection(conn);
|
|
80
|
-
if (cb) cb();
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
//if server permit it, reset the connection, or rollback only if not
|
|
85
|
-
// COM_RESET_CONNECTION exist since mysql 5.7.3 and mariadb 10.2.4
|
|
86
|
-
// but not possible to use it with mysql waiting for https://bugs.mysql.com/bug.php?id=97633 correction.
|
|
87
|
-
// and mariadb only since https://jira.mariadb.org/browse/MDEV-18281
|
|
88
|
-
let revertFunction = conn.rollback;
|
|
89
|
-
if (
|
|
90
|
-
options.resetAfterUse &&
|
|
91
|
-
conn.info.isMariaDB() &&
|
|
92
|
-
((conn.info.serverVersion.minor === 2 && conn.info.hasMinVersion(10, 2, 22)) ||
|
|
93
|
-
conn.info.hasMinVersion(10, 3, 13))
|
|
94
|
-
) {
|
|
95
|
-
revertFunction = conn.reset;
|
|
96
|
-
}
|
|
97
|
-
revertFunction((errCall) => {
|
|
98
|
-
if (errCall) {
|
|
99
|
-
//uncertain connection state.
|
|
100
|
-
pool._discardConnection(conn);
|
|
101
|
-
if (cb) cb();
|
|
102
|
-
return;
|
|
103
|
-
} else {
|
|
104
|
-
pool._releaseConnection(conn);
|
|
105
|
-
}
|
|
106
|
-
if (cb) cb();
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
conn.end = conn.release;
|
|
110
|
-
conn.releaseWithoutError = () => {
|
|
111
|
-
conn.end((err) => {});
|
|
112
|
-
};
|
|
113
|
-
resolve(conn);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
};
|
|
10
|
+
const ConnectionCallback = require('./connection-callback');
|
|
119
11
|
|
|
120
|
-
|
|
12
|
+
class PoolCallback extends EventEmitter {
|
|
13
|
+
#pool;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
super();
|
|
16
|
+
this.#pool = new Pool(options);
|
|
17
|
+
this.#pool.on('acquire', this.emit.bind(this, 'acquire'));
|
|
18
|
+
this.#pool.on('connection', this.emit.bind(this, 'connection'));
|
|
19
|
+
this.#pool.on('enqueue', this.emit.bind(this, 'enqueue'));
|
|
20
|
+
this.#pool.on('release', this.emit.bind(this, 'release'));
|
|
21
|
+
this.#pool.on('error', this.emit.bind(this, 'error'));
|
|
22
|
+
}
|
|
121
23
|
|
|
122
|
-
|
|
123
|
-
const endPromise = this.end.bind(this);
|
|
124
|
-
const queryPromise = this.query.bind(this);
|
|
125
|
-
const batchPromise = this.batch.bind(this);
|
|
126
|
-
const emptyError = (err) => {};
|
|
24
|
+
#noop = () => {};
|
|
127
25
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
26
|
+
get closed() {
|
|
27
|
+
return this.#pool.closed;
|
|
28
|
+
}
|
|
131
29
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
30
|
+
/**
|
|
31
|
+
* Get current total connection number.
|
|
32
|
+
* @return {number}
|
|
33
|
+
*/
|
|
34
|
+
totalConnections() {
|
|
35
|
+
return this.#pool.totalConnections();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Get current active connections.
|
|
40
|
+
* @return {number}
|
|
41
|
+
*/
|
|
42
|
+
activeConnections() {
|
|
43
|
+
return this.#pool.activeConnections();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get current idle connection number.
|
|
48
|
+
* @return {number}
|
|
49
|
+
*/
|
|
50
|
+
idleConnections() {
|
|
51
|
+
return this.#pool.idleConnections();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get current stacked connection request.
|
|
56
|
+
* @return {number}
|
|
57
|
+
*/
|
|
58
|
+
taskQueueSize() {
|
|
59
|
+
return this.#pool.taskQueueSize();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
escape(value) {
|
|
63
|
+
return this.#pool.escape(value);
|
|
64
|
+
}
|
|
139
65
|
|
|
140
|
-
|
|
141
|
-
|
|
66
|
+
escapeId(value) {
|
|
67
|
+
return this.#pool.escapeId(value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Ends pool
|
|
72
|
+
*
|
|
73
|
+
* @param callback
|
|
74
|
+
*/
|
|
75
|
+
end(callback) {
|
|
76
|
+
this.#pool
|
|
77
|
+
.end()
|
|
142
78
|
.then(() => {
|
|
143
79
|
if (callback) callback(null);
|
|
144
80
|
})
|
|
145
|
-
.catch(callback ||
|
|
146
|
-
}
|
|
81
|
+
.catch(callback || this.#noop);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Retrieve a connection from the pool.
|
|
86
|
+
* Create a new one if the limit is not reached.
|
|
87
|
+
* wait until acquireTimeout.
|
|
88
|
+
*
|
|
89
|
+
* @param cb callback
|
|
90
|
+
*/
|
|
91
|
+
getConnection(cb) {
|
|
92
|
+
if (!cb) {
|
|
93
|
+
throw new Errors.createError('missing mandatory callback parameter', Errors.ER_MISSING_PARAMETER);
|
|
94
|
+
}
|
|
95
|
+
const cmdParam = {};
|
|
96
|
+
if (this.#pool.opts.connOptions.trace) Error.captureStackTrace(cmdParam);
|
|
97
|
+
this.#pool.getConnection(cmdParam, (err, baseConn) => {
|
|
98
|
+
if (err) {
|
|
99
|
+
cb(err);
|
|
100
|
+
} else {
|
|
101
|
+
const cc = new ConnectionCallback(baseConn);
|
|
102
|
+
cc.end = (cb) => cc.release(cb);
|
|
103
|
+
cc.close = (cb) => cc.release(cb);
|
|
104
|
+
cb(null, cc);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
147
108
|
|
|
148
109
|
/**
|
|
149
110
|
* Execute query using text protocol with callback emit columns/data/end/error
|
|
@@ -153,50 +114,128 @@ function PoolCallback(options) {
|
|
|
153
114
|
* Object must then have sql property.
|
|
154
115
|
* @param values object / array of placeholder values (not mandatory)
|
|
155
116
|
* @param cb callback
|
|
156
|
-
* @returns {Query} query
|
|
157
117
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
118
|
+
query(sql, values, cb) {
|
|
119
|
+
const cmdParam = ConnectionCallback._PARAM(this.#pool.opts.connOptions, sql, values, cb);
|
|
120
|
+
this.#pool.getConnection(cmdParam, (err, baseConn) => {
|
|
121
|
+
if (err) {
|
|
122
|
+
if (cmdParam.callback) cmdParam.callback(err);
|
|
123
|
+
} else {
|
|
124
|
+
const _cb = cmdParam.callback;
|
|
125
|
+
cmdParam.callback = (err, rows, meta) => {
|
|
126
|
+
this.#pool.release(baseConn);
|
|
127
|
+
if (_cb) _cb(err, rows, meta);
|
|
128
|
+
};
|
|
129
|
+
ConnectionCallback._QUERY_CMD(baseConn, cmdParam);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
166
133
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Execute query using binary protocol with callback emit columns/data/end/error
|
|
136
|
+
* events to permit streaming big result-set
|
|
137
|
+
*
|
|
138
|
+
* @param sql sql parameter Object can be used to supersede default option.
|
|
139
|
+
* Object must then have sql property.
|
|
140
|
+
* @param values object / array of placeholder values (not mandatory)
|
|
141
|
+
* @param cb callback
|
|
142
|
+
*/
|
|
143
|
+
execute(sql, values, cb) {
|
|
144
|
+
const cmdParam = ConnectionCallback._PARAM(this.#pool.opts.connOptions, sql, values, cb);
|
|
145
|
+
|
|
146
|
+
this.#pool.getConnection(cmdParam, (err, baseConn) => {
|
|
147
|
+
if (err) {
|
|
148
|
+
if (cmdParam.callback) cmdParam.callback(err);
|
|
149
|
+
} else {
|
|
150
|
+
const _cb = cmdParam.callback;
|
|
151
|
+
baseConn.prepareExecute(
|
|
152
|
+
cmdParam,
|
|
153
|
+
(res) => {
|
|
154
|
+
this.#pool.release(baseConn);
|
|
155
|
+
if (_cb) _cb(null, res, res.meta);
|
|
156
|
+
},
|
|
157
|
+
(err) => {
|
|
158
|
+
this.#pool.release(baseConn);
|
|
159
|
+
if (_cb) _cb(err);
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
173
165
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
166
|
+
/**
|
|
167
|
+
* execute a batch
|
|
168
|
+
*
|
|
169
|
+
* @param sql sql parameter Object can be used to supersede default option.
|
|
170
|
+
* Object must then have sql property.
|
|
171
|
+
* @param values array of placeholder values
|
|
172
|
+
* @param cb callback
|
|
173
|
+
*/
|
|
174
|
+
batch(sql, values, cb) {
|
|
175
|
+
const cmdParam = ConnectionCallback._PARAM(this.#pool.opts.connOptions, sql, values, cb);
|
|
176
|
+
this.#pool.getConnection(cmdParam, (err, baseConn) => {
|
|
177
|
+
if (err) {
|
|
178
|
+
if (cmdParam.callback) cmdParam.callback(err);
|
|
179
|
+
} else {
|
|
180
|
+
const _cb = cmdParam.callback;
|
|
181
|
+
baseConn.batch(
|
|
182
|
+
cmdParam,
|
|
183
|
+
(res) => {
|
|
184
|
+
this.#pool.release(baseConn);
|
|
185
|
+
if (_cb) _cb(null, res);
|
|
186
|
+
},
|
|
187
|
+
(err) => {
|
|
188
|
+
this.#pool.release(baseConn);
|
|
189
|
+
if (_cb) _cb(err);
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
177
195
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
196
|
+
/**
|
|
197
|
+
* Import sql file.
|
|
198
|
+
*
|
|
199
|
+
* @param opts JSON array with 2 possible fields: file and database
|
|
200
|
+
* @param cb callback
|
|
201
|
+
*/
|
|
202
|
+
importFile(opts, cb) {
|
|
203
|
+
if (!opts) {
|
|
204
|
+
if (cb)
|
|
205
|
+
cb(
|
|
206
|
+
Errors.createError(
|
|
207
|
+
'SQL file parameter is mandatory',
|
|
208
|
+
Errors.ER_MISSING_SQL_PARAMETER,
|
|
209
|
+
null,
|
|
210
|
+
'HY000',
|
|
211
|
+
null,
|
|
212
|
+
false,
|
|
213
|
+
null
|
|
214
|
+
)
|
|
215
|
+
);
|
|
216
|
+
return;
|
|
181
217
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
218
|
+
this.#pool.getConnection({}, (err, baseConn) => {
|
|
219
|
+
if (err) {
|
|
220
|
+
if (cb) cb(err);
|
|
221
|
+
} else {
|
|
222
|
+
baseConn.importFile(
|
|
223
|
+
{ file: opts.file, database: opts.database },
|
|
224
|
+
(res) => {
|
|
225
|
+
this.#pool.release(baseConn);
|
|
226
|
+
if (cb) cb(null, res);
|
|
227
|
+
},
|
|
228
|
+
(err) => {
|
|
229
|
+
this.#pool.release(baseConn);
|
|
230
|
+
if (cb) cb(err);
|
|
231
|
+
}
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
toString() {
|
|
237
|
+
return 'poolCallback(' + this.#pool.toString() + ')';
|
|
238
|
+
}
|
|
198
239
|
}
|
|
199
240
|
|
|
200
|
-
util.inherits(PoolCallback, PoolBase);
|
|
201
|
-
|
|
202
241
|
module.exports = PoolCallback;
|