@pi-r/mysql 0.2.7 → 0.5.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/client/index.js +9 -7
  2. package/package.json +4 -4
package/client/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = exports.setAuthentication = void 0;
4
+ const main = require("mysql2");
5
+ const mysql = require("mysql2/promise");
4
6
  const util_1 = require("@e-mc/db/util");
5
7
  const types_1 = require("@e-mc/types");
6
8
  const Db = require("@e-mc/db");
@@ -104,10 +106,9 @@ function setCredential(item) {
104
106
  }
105
107
  const poolKey = getPoolKey(credential);
106
108
  if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
107
- const { createPool } = require("mysql2/promise" /* STRINGS.PACKAGE_NAME */);
108
109
  const config = this.getPoolConfig("mysql" /* STRINGS.MODULE_NAME */, password);
109
110
  if (config) {
110
- const { max, idle, queue_max } = config;
111
+ const { max, idle, queue_max, timeout } = config;
111
112
  if (max > 0) {
112
113
  credential.connectionLimit ?? (credential.connectionLimit = max);
113
114
  }
@@ -117,8 +118,11 @@ function setCredential(item) {
117
118
  if (queue_max >= 0) {
118
119
  credential.queueLimit ?? (credential.queueLimit = queue_max);
119
120
  }
121
+ if (timeout > 0) {
122
+ credential.connectTimeout ?? (credential.connectTimeout = timeout);
123
+ }
120
124
  }
121
- new MySQLPool(createPool(removeUUIDKey(credential)), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
125
+ new MySQLPool(mysql.createPool(removeUUIDKey(credential)), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
122
126
  }
123
127
  else {
124
128
  pool.add(item);
@@ -135,7 +139,6 @@ async function executeBatchQuery(batch, options = '', outResult) {
135
139
  if (length === 0) {
136
140
  return [];
137
141
  }
138
- const db = require("mysql2/promise" /* STRINGS.PACKAGE_NAME */);
139
142
  let parallel, connectOnce, errorQuery, sessionKey, outCacheMiss;
140
143
  if ((0, types_1.isPlainObject)(options)) {
141
144
  ({ parallel, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
@@ -201,7 +204,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
201
204
  }
202
205
  }
203
206
  if (!client) {
204
- clients.push(client = await db.createConnection(removeUUIDKey(mysqlCredential || credential)));
207
+ clients.push(client = await mysql.createConnection(removeUUIDKey(mysqlCredential || credential)));
205
208
  }
206
209
  if (connectOnce) {
207
210
  if (!parallel) {
@@ -281,8 +284,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
281
284
  if (streamRow) {
282
285
  const rows = [];
283
286
  const processRow = typeof streamRow === 'function' && streamRow;
284
- const { createConnection } = require("mysql2" /* STRINGS.PACKAGE_STREAM */);
285
- const client = mysql2Client || createConnection(removeUUIDKey(mysql2Credential || credential));
287
+ const client = mysql2Client || main.createConnection(removeUUIDKey(mysql2Credential || credential));
286
288
  clients.push(client);
287
289
  if (connectOnce) {
288
290
  if (!parallel) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mysql",
3
- "version": "0.2.7",
3
+ "version": "0.5.0",
4
4
  "description": "MySQL client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -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.5.3",
25
- "@e-mc/types": "^0.5.3",
26
- "mysql2": "^3.5.2"
24
+ "@e-mc/db": "^0.7.0",
25
+ "@e-mc/types": "^0.7.0",
26
+ "mysql2": "^3.6.5"
27
27
  }
28
28
  }