@pi-r/mysql 0.5.0 → 0.5.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2023 Haruhi Suzumiya
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.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import type { IDb } from '@e-mc/types/lib';
2
- import type { MySQLCredential, MySQLDataSource } from '@e-mc/types/lib/db';
3
2
 
4
3
  import type { IDbSourceClient } from '@e-mc/db/types';
5
4
 
5
+ import type { MySQLCredential, MySQLDataSource } from '../types';
6
+
6
7
  declare const MySQL: IDbSourceClient<MySQLDataSource> & {
7
8
  setAuthentication(this: IDb, credential: MySQLCredential): void;
8
- };
9
-
10
- export = MySQL;
9
+ };
package/client/index.js CHANGED
@@ -91,7 +91,7 @@ function setCredential(item) {
91
91
  errors.push('user');
92
92
  }
93
93
  if (errors.length) {
94
- throw (0, types_1.errorMessage)("mysql" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
94
+ throw (0, types_1.errorMessage)("mysql", 'Not defined - ' + errors.join(' | '));
95
95
  }
96
96
  }
97
97
  const usePool = item.usePool;
@@ -106,7 +106,7 @@ function setCredential(item) {
106
106
  }
107
107
  const poolKey = getPoolKey(credential);
108
108
  if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
109
- const config = this.getPoolConfig("mysql" /* STRINGS.MODULE_NAME */, password);
109
+ const config = this.getPoolConfig("mysql", password);
110
110
  if (config) {
111
111
  const { max, idle, queue_max, timeout } = config;
112
112
  if (max > 0) {
@@ -159,17 +159,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
159
159
  if (!parallel) {
160
160
  outResult || (outResult = new Array(length));
161
161
  }
162
- const caching = this.hasCache("mysql" /* STRINGS.MODULE_NAME */, sessionKey);
162
+ const caching = this.hasCache("mysql", sessionKey);
163
163
  const tasks = new Array(length);
164
164
  const clients = [];
165
165
  const pools = [];
166
166
  let mysqlPool, mysqlClient, mysqlCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
167
167
  const getConnection = async (item, credential) => {
168
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
168
+ item.transactionState = 64;
169
169
  let client;
170
170
  if (mysqlPool) {
171
171
  pools.push(client = await mysqlPool.getConnection());
172
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
172
+ item.transactionState &= ~64;
173
173
  return client;
174
174
  }
175
175
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -212,13 +212,13 @@ async function executeBatchQuery(batch, options = '', outResult) {
212
212
  }
213
213
  mysqlCredential = credential;
214
214
  }
215
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
215
+ item.transactionState &= ~64;
216
216
  return client;
217
217
  };
218
218
  for (let i = 0, mysql2Client, mysql2Credential; i < length; ++i) {
219
219
  const item = batch[i];
220
220
  const { source, query, params, ignoreCache } = item;
221
- 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;
221
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql", 'options', null, mysql2Credential || item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
222
222
  let credential, error;
223
223
  if (streamRow) {
224
224
  if (mysql2Credential) {
@@ -229,7 +229,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
229
229
  else if (credential = mysqlCredential || onceCredential) {
230
230
  error = null;
231
231
  }
232
- 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 */))) {
232
+ 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"))) {
233
233
  if (this.handleFail(error, item, { errorQuery })) {
234
234
  if (!parallel) {
235
235
  tasks.length = 0;
@@ -245,7 +245,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
245
245
  }
246
246
  continue;
247
247
  }
248
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
248
+ item.transactionState = 1;
249
249
  const renewCache = ignoreCache === 0;
250
250
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
251
251
  let queryString = '';
@@ -260,7 +260,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
260
260
  else {
261
261
  outResult[i] = result;
262
262
  }
263
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
263
+ this.add(item, 4 | 128);
264
264
  continue;
265
265
  }
266
266
  if (!ignoreCache && outCacheMiss) {
@@ -314,7 +314,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
314
314
  reject(error);
315
315
  }
316
316
  else {
317
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
317
+ this.add(item, 4);
318
318
  resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows.length ? rows : null);
319
319
  }
320
320
  });
@@ -326,7 +326,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
326
326
  }
327
327
  commandType = this.commandType.SELECT;
328
328
  const [rows] = await client.query(query, params);
329
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
329
+ this.add(item, 4);
330
330
  if ((0, types_1.isArray)(rows)) {
331
331
  const [row1, row2] = rows;
332
332
  if (rows.length === 2 && Array.isArray(row1) && !Array.isArray(row2) && isResultSetHeader(row2)) {
@@ -362,7 +362,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
362
362
  }
363
363
  return this.processRows(batch, tasks, {
364
364
  disconnect: () => {
365
- 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 })));
365
+ clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection", "mysql"], err, { type: 65536, fatal: false })));
366
366
  pools.forEach(item => item.release());
367
367
  },
368
368
  parallel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mysql",
3
- "version": "0.5.0",
3
+ "version": "0.5.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.7.0",
25
- "@e-mc/types": "^0.7.0",
26
- "mysql2": "^3.6.5"
24
+ "@e-mc/db": "^0.7.3",
25
+ "@e-mc/types": "^0.7.3",
26
+ "mysql2": "^3.9.3"
27
27
  }
28
28
  }