@pi-r/mysql 0.6.1 → 0.6.3

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  ### @pi-r/mysql
2
2
 
3
+ https://e-mc.readthedocs.io/en/latest/db/mysql.html
4
+
3
5
  ### LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -23,7 +23,7 @@ class MySQLPool extends DbPool {
23
23
  }
24
24
  }
25
25
  const POOL_STATE = {};
26
- const POOL_UNUSED = ['ssl', 'connectTimeout', 'queueLimit', 'waitForConnections', 'connectionLimit', 'maxIdle', 'idleTimeout', 'enableKeepAlive', 'keepAliveInitialDelay'];
26
+ const POOL_UNUSED = ['ssl', 'connectTimeout', 'queueLimit', 'waitForConnections', 'connectionLimit', 'maxIdle', 'idleTimeout', 'enableKeepAlive', 'keepAliveInitialDelay', 'Promise'];
27
27
  function removePoolProperties(credential) {
28
28
  if (!credential.uuidKey) {
29
29
  let result;
@@ -31,12 +31,12 @@ function removePoolProperties(credential) {
31
31
  const attr = POOL_UNUSED[i];
32
32
  if (attr in credential) {
33
33
  result || (result = { ...credential });
34
- if (attr === 'ssl' && (0, types_1.isObject)(result[attr])) {
35
- result[attr] = true;
36
- }
37
- else {
34
+ if (attr !== 'ssl') {
38
35
  delete result[attr];
39
36
  }
37
+ else if ((0, types_1.isObject)(result.ssl)) {
38
+ result[attr] = true;
39
+ }
40
40
  }
41
41
  }
42
42
  if (result) {
@@ -63,7 +63,11 @@ function isResultSetHeader(value) {
63
63
  }
64
64
  return false;
65
65
  }
66
- const getPoolKey = (credential) => (credential.host || '') + '_' + (credential.port || '3306') + (credential.user || '') + '_' + (credential.password || '') + '_' + (credential.database || '') + '_' + (credential.uri || '') + '_' + (credential.rowsAsArray ? '1' : '0');
66
+ function getPoolKey(credential) {
67
+ if ((credential.host || credential.socketPath) && credential.user) {
68
+ return JSON.stringify(removeUUIDKey(credential));
69
+ }
70
+ }
67
71
  function setAuthentication(credential) {
68
72
  const auth = (0, util_1.parseServerAuth)(credential);
69
73
  credential.host || (credential.host = auth.hostname);
@@ -84,7 +88,7 @@ function setCredential(item) {
84
88
  }
85
89
  if (!credential.uri) {
86
90
  const errors = [];
87
- if (!credential.host) {
91
+ if (!credential.host && !credential.socketPath) {
88
92
  errors.push('host');
89
93
  }
90
94
  if (!credential.user) {
@@ -99,18 +103,19 @@ function setCredential(item) {
99
103
  return;
100
104
  }
101
105
  let username, password, pool;
102
- if (typeof usePool === 'string' && (username = credential.user || credential.uri && (0, util_1.parseConnectionString)(credential.uri)?.username)) {
103
- [password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
104
- if (pool) {
105
- pool.add(item, password);
106
+ if ((0, types_1.isString)(usePool)) {
107
+ if (username = credential.user || credential.uri && (0, util_1.parseConnectionString)(credential.uri)?.username) {
108
+ [password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
109
+ if (pool) {
110
+ pool.add(item, password);
111
+ return;
112
+ }
113
+ }
114
+ if (!password) {
115
+ item.usePool = '';
106
116
  return;
107
117
  }
108
118
  }
109
- const poolKey = getPoolKey(credential);
110
- if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
111
- pool.add(item);
112
- return;
113
- }
114
119
  const config = this.getPoolConfig("mysql" /* STRINGS.MODULE_NAME */, password);
115
120
  if (config) {
116
121
  const { max, idle, queue_max, timeout } = config;
@@ -127,6 +132,11 @@ function setCredential(item) {
127
132
  credential.connectTimeout ?? (credential.connectTimeout = timeout);
128
133
  }
129
134
  }
135
+ const poolKey = getPoolKey(credential);
136
+ if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
137
+ pool.add(item);
138
+ return;
139
+ }
130
140
  new MySQLPool(mysql.createPool(removeUUIDKey(credential)), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
131
141
  }
132
142
  exports.setCredential = setCredential;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mysql",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "MySQL client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/anpham6/pi-r.git",
12
+ "url": "git+https://github.com/anpham6/pi-r.git",
13
13
  "directory": "src/db/mysql"
14
14
  },
15
15
  "keywords": [
@@ -21,8 +21,8 @@
21
21
  "license": "MIT",
22
22
  "homepage": "https://github.com/anpham6/pi-r#readme",
23
23
  "dependencies": {
24
- "@e-mc/db": "^0.8.1",
25
- "@e-mc/types": "^0.8.1",
26
- "mysql2": "^3.6.5"
24
+ "@e-mc/db": "^0.8.3",
25
+ "@e-mc/types": "^0.8.3",
26
+ "mysql2": "^3.9.1"
27
27
  }
28
28
  }