mysql2 3.13.0 → 3.14.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.
Files changed (2) hide show
  1. package/lib/pool_cluster.js +18 -14
  2. package/package.json +1 -1
@@ -37,6 +37,18 @@ const getMonotonicMilliseconds = function () {
37
37
  return Math.floor(ms);
38
38
  };
39
39
 
40
+ const patternRegExp = function (pattern) {
41
+ if (pattern instanceof RegExp) {
42
+ return pattern;
43
+ }
44
+
45
+ const source = pattern
46
+ .replace(/([.+?^=!:${}()|[\]/\\])/g, '\\$1')
47
+ .replace(/\*/g, '.*');
48
+
49
+ return new RegExp(`^${source}$`);
50
+ };
51
+
40
52
  class PoolNamespace {
41
53
  constructor(cluster, pattern, selector) {
42
54
  this._cluster = cluster;
@@ -256,20 +268,12 @@ class PoolCluster extends EventEmitter {
256
268
  let currentTime = 0;
257
269
  let foundNodeIds = this._findCaches[pattern];
258
270
 
259
- if (typeof this._findCaches[pattern] === 'undefined') {
260
- if (pattern === '*') {
261
- // all
262
- foundNodeIds = this._serviceableNodeIds;
263
- } else if (this._serviceableNodeIds.indexOf(pattern) !== -1) {
264
- // one
265
- foundNodeIds = [pattern];
266
- } else {
267
- // wild matching
268
- const keyword = pattern.substring(pattern.length - 1, 0);
269
- foundNodeIds = this._serviceableNodeIds.filter((id) =>
270
- id.startsWith(keyword)
271
- );
272
- }
271
+ if (foundNodeIds === undefined) {
272
+ const expression = patternRegExp(pattern);
273
+
274
+ foundNodeIds = this._serviceableNodeIds.filter((id) =>
275
+ id.match(expression)
276
+ );
273
277
  }
274
278
 
275
279
  this._findCaches[pattern] = foundNodeIds;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysql2",
3
- "version": "3.13.0",
3
+ "version": "3.14.0",
4
4
  "description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS",
5
5
  "main": "index.js",
6
6
  "typings": "typings/mysql/index",