@pi-r/mariadb 0.2.3 → 0.3.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 -10
  2. package/package.json +3 -3
package/client/index.js CHANGED
@@ -1,6 +1,7 @@
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 mariadb = require("mariadb");
4
5
  const util_1 = require("@e-mc/db/util");
5
6
  const types_1 = require("@e-mc/types");
6
7
  const Db = require("@e-mc/db");
@@ -109,7 +110,6 @@ function setCredential(item) {
109
110
  }
110
111
  const poolKey = getPoolKey(credential);
111
112
  if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
112
- const { createPool } = require("mariadb" /* STRINGS.PACKAGE_NAME */);
113
113
  const config = this.getPoolConfig("mariadb" /* STRINGS.MODULE_NAME */, password);
114
114
  if (config) {
115
115
  const { max, idle } = config;
@@ -120,7 +120,7 @@ function setCredential(item) {
120
120
  credential.idleTimeout ?? (credential.idleTimeout = idle);
121
121
  }
122
122
  }
123
- new MariaDBPool(createPool(removeUUIDKey(credential)), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
123
+ new MariaDBPool(mariadb.createPool(removeUUIDKey(credential)), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
124
124
  }
125
125
  else {
126
126
  pool.add(item);
@@ -137,7 +137,6 @@ async function executeBatchQuery(batch, options = '', outResult) {
137
137
  if (length === 0) {
138
138
  return [];
139
139
  }
140
- const db = require("mariadb" /* STRINGS.PACKAGE_NAME */);
141
140
  let parallel, connectOnce, errorQuery, sessionKey, outCacheMiss;
142
141
  if ((0, types_1.isPlainObject)(options)) {
143
142
  ({ parallel, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
@@ -203,7 +202,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
203
202
  }
204
203
  }
205
204
  if (!client) {
206
- clients.push(client = await db.createConnection(removeUUIDKey(mariaDBCredential || credential)));
205
+ clients.push(client = await mariadb.createConnection(removeUUIDKey(mariaDBCredential || credential)));
207
206
  }
208
207
  if (connectOnce) {
209
208
  if (!parallel) {
@@ -306,16 +305,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
306
305
  }
307
306
  }
308
307
  else {
309
- let rows = await client.query(query, params);
308
+ const rows = await client.query(query, params);
310
309
  this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
311
310
  if ((0, types_1.isArray)(rows)) {
312
- if (rows.length === 2 && Array.isArray(rows[0]) && !Array.isArray(rows[1]) && isOkPacket(rows[1])) {
313
- rows = rows[0];
311
+ const [row1, row2] = rows;
312
+ if (rows.length === 2 && Array.isArray(row1) && !Array.isArray(row2) && isOkPacket(row2)) {
313
+ resolve(row1);
314
314
  }
315
- else if (isOkPacket(rows[0])) {
316
- rows = [];
315
+ else {
316
+ resolve(!isOkPacket(row1) ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
317
317
  }
318
- resolve(rows.length ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
319
318
  }
320
319
  else {
321
320
  resolve(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mariadb",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "MariaDB 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",
24
+ "@e-mc/db": "^0.6.0",
25
+ "@e-mc/types": "^0.6.0",
26
26
  "mariadb": "^3.2.0"
27
27
  }
28
28
  }