@pi-r/mysql 0.2.7 → 0.2.8

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2023 Mile Square Park
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
- ### @pi-r/mysql
1
+ # @pi-r/mysql
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever
4
+
5
+ ## LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -89,7 +89,7 @@ function setCredential(item) {
89
89
  errors.push('user');
90
90
  }
91
91
  if (errors.length) {
92
- throw (0, types_1.errorMessage)("mysql" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
92
+ throw (0, types_1.errorMessage)("mysql", 'Not defined - ' + errors.join(' | '));
93
93
  }
94
94
  }
95
95
  const usePool = item.usePool;
@@ -104,8 +104,8 @@ function setCredential(item) {
104
104
  }
105
105
  const poolKey = getPoolKey(credential);
106
106
  if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
107
- const { createPool } = require("mysql2/promise" /* STRINGS.PACKAGE_NAME */);
108
- const config = this.getPoolConfig("mysql" /* STRINGS.MODULE_NAME */, password);
107
+ const { createPool } = require("mysql2/promise");
108
+ const config = this.getPoolConfig("mysql", password);
109
109
  if (config) {
110
110
  const { max, idle, queue_max } = config;
111
111
  if (max > 0) {
@@ -135,7 +135,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
135
135
  if (length === 0) {
136
136
  return [];
137
137
  }
138
- const db = require("mysql2/promise" /* STRINGS.PACKAGE_NAME */);
138
+ const db = require("mysql2/promise");
139
139
  let parallel, connectOnce, errorQuery, sessionKey, outCacheMiss;
140
140
  if ((0, types_1.isPlainObject)(options)) {
141
141
  ({ parallel, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
@@ -156,17 +156,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
156
156
  if (!parallel) {
157
157
  outResult || (outResult = new Array(length));
158
158
  }
159
- const caching = this.hasCache("mysql" /* STRINGS.MODULE_NAME */, sessionKey);
159
+ const caching = this.hasCache("mysql", sessionKey);
160
160
  const tasks = new Array(length);
161
161
  const clients = [];
162
162
  const pools = [];
163
163
  let mysqlPool, mysqlClient, mysqlCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
164
164
  const getConnection = async (item, credential) => {
165
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
165
+ item.transactionState = 64;
166
166
  let client;
167
167
  if (mysqlPool) {
168
168
  pools.push(client = await mysqlPool.getConnection());
169
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
169
+ item.transactionState &= ~64;
170
170
  return client;
171
171
  }
172
172
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -209,13 +209,13 @@ async function executeBatchQuery(batch, options = '', outResult) {
209
209
  }
210
210
  mysqlCredential = credential;
211
211
  }
212
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
212
+ item.transactionState &= ~64;
213
213
  return client;
214
214
  };
215
215
  for (let i = 0, mysql2Client, mysql2Credential; i < length; ++i) {
216
216
  const item = batch[i];
217
217
  const { source, query, params, ignoreCache } = item;
218
- const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql" /* STRINGS.MODULE_NAME */, 'options', null, mysql2Credential || item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
218
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql", 'options', null, mysql2Credential || item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
219
219
  let credential, error;
220
220
  if (streamRow) {
221
221
  if (mysql2Credential) {
@@ -226,7 +226,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
226
226
  else if (credential = mysqlCredential || onceCredential) {
227
227
  error = null;
228
228
  }
229
- if (error !== null && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials" /* ERR_DB.CREDENTIALS */)) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query" /* ERR_DB.QUERY */))) {
229
+ if (error !== null && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials")) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query"))) {
230
230
  if (this.handleFail(error, item, { errorQuery })) {
231
231
  if (!parallel) {
232
232
  tasks.length = 0;
@@ -242,7 +242,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
242
242
  }
243
243
  continue;
244
244
  }
245
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
245
+ item.transactionState = 1;
246
246
  const renewCache = ignoreCache === 0;
247
247
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
248
248
  let queryString = '';
@@ -257,7 +257,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
257
257
  else {
258
258
  outResult[i] = result;
259
259
  }
260
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
260
+ this.add(item, 4 | 128);
261
261
  continue;
262
262
  }
263
263
  if (!ignoreCache && outCacheMiss) {
@@ -281,7 +281,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
281
281
  if (streamRow) {
282
282
  const rows = [];
283
283
  const processRow = typeof streamRow === 'function' && streamRow;
284
- const { createConnection } = require("mysql2" /* STRINGS.PACKAGE_STREAM */);
284
+ const { createConnection } = require("mysql2");
285
285
  const client = mysql2Client || createConnection(removeUUIDKey(mysql2Credential || credential));
286
286
  clients.push(client);
287
287
  if (connectOnce) {
@@ -312,7 +312,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
312
312
  reject(error);
313
313
  }
314
314
  else {
315
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
315
+ this.add(item, 4);
316
316
  resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows.length ? rows : null);
317
317
  }
318
318
  });
@@ -324,7 +324,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
324
324
  }
325
325
  commandType = this.commandType.SELECT;
326
326
  const [rows] = await client.query(query, params);
327
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
327
+ this.add(item, 4);
328
328
  if ((0, types_1.isArray)(rows)) {
329
329
  const [row1, row2] = rows;
330
330
  if (rows.length === 2 && Array.isArray(row1) && !Array.isArray(row2) && isResultSetHeader(row2)) {
@@ -360,7 +360,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
360
360
  }
361
361
  return this.processRows(batch, tasks, {
362
362
  disconnect: () => {
363
- clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection" /* ERR_DB.CONNECTION_CLOSE */, "mysql" /* STRINGS.MODULE_NAME */], err, { type: 65536 /* LOG_TYPE.DB */, fatal: false })));
363
+ clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection", "mysql"], err, { type: 65536, fatal: false })));
364
364
  pools.forEach(item => item.release());
365
365
  },
366
366
  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.2.8",
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.5.3",
25
- "@e-mc/types": "^0.5.3",
26
- "mysql2": "^3.5.2"
24
+ "@e-mc/db": "^0.5.4",
25
+ "@e-mc/types": "^0.5.4",
26
+ "mysql2": "^3.9.2"
27
27
  }
28
28
  }