@pi-r/mariadb 0.6.4 → 0.6.6

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 2024 An Pham
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,7 +1,10 @@
1
- ### @pi-r/mariadb
1
+ # @pi-r/mariadb
2
2
 
3
- https://e-mc.readthedocs.io/en/latest/db/mariadb.html
3
+ ## Documentation
4
4
 
5
- ### LICENSE
5
+ - [E-mc](https://e-mc.readthedocs.io/en/latest/db/mariadb.html)
6
+ - [squared](https://squared.readthedocs.io)
7
+
8
+ ## LICENSE
6
9
 
7
10
  MIT
@@ -0,0 +1,7 @@
1
+ import type { IDbSourceClient } from '@e-mc/db/types';
2
+
3
+ import type { MariaDBDataSource } from '../types';
4
+
5
+ declare const MariaDB: IDbSourceClient<MariaDBDataSource>;
6
+
7
+ export = MariaDB;
package/client/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = exports.setAuthentication = void 0;
4
3
  const mariadb = require("mariadb");
5
4
  const util_1 = require("@e-mc/db/util");
@@ -101,7 +100,7 @@ function setCredential(item) {
101
100
  errors.push('user');
102
101
  }
103
102
  if (errors.length) {
104
- throw (0, types_1.errorMessage)("mariadb" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
103
+ throw (0, types_1.errorMessage)("mariadb", 'Not defined - ' + errors.join(' | '));
105
104
  }
106
105
  const usePool = item.usePool;
107
106
  if (!usePool) {
@@ -121,7 +120,7 @@ function setCredential(item) {
121
120
  return;
122
121
  }
123
122
  }
124
- const config = this.getPoolConfig("mariadb" /* STRINGS.MODULE_NAME */, password);
123
+ const config = this.getPoolConfig("mariadb", password);
125
124
  if (config) {
126
125
  const { min, max, idle, queue_idle, timeout, socket_timeout } = config;
127
126
  if (min >= 0) {
@@ -180,17 +179,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
180
179
  if (!parallel) {
181
180
  outResult || (outResult = new Array(length));
182
181
  }
183
- const caching = this.hasCache("mariadb" /* STRINGS.MODULE_NAME */, sessionKey);
182
+ const caching = this.hasCache("mariadb", sessionKey);
184
183
  const tasks = new Array(length);
185
184
  const clients = [];
186
185
  const pools = [];
187
186
  let mariaDBPool, mariaDBClient, mariaDBCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
188
187
  const getConnection = async (item, credential) => {
189
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
188
+ item.transactionState = 64;
190
189
  let client;
191
190
  if (mariaDBPool) {
192
191
  pools.push(client = await mariaDBPool.getConnection());
193
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
192
+ item.transactionState &= ~64;
194
193
  POOL_ACTIVE.add(credential);
195
194
  return client;
196
195
  }
@@ -235,7 +234,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
235
234
  }
236
235
  mariaDBCredential = credential;
237
236
  }
238
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
237
+ item.transactionState &= ~64;
239
238
  return client;
240
239
  };
241
240
  if (this.host?.username) {
@@ -245,8 +244,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
245
244
  const item = batch[i];
246
245
  const { source, query, params, ignoreCache } = item;
247
246
  let credential = mariaDBCredential || onceCredential, error;
248
- const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mariadb" /* STRINGS.MODULE_NAME */, 'options', null, item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
249
- if (!(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 */))) {
247
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mariadb", 'options', null, item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
248
+ if (!(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"))) {
250
249
  if (this.handleFail(error, item, { errorQuery })) {
251
250
  if (!parallel) {
252
251
  tasks.length = 0;
@@ -262,7 +261,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
262
261
  }
263
262
  continue;
264
263
  }
265
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
264
+ item.transactionState = 1;
266
265
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
267
266
  let queryString = '';
268
267
  if (caching && ignoreCache !== true && !streamRow) {
@@ -276,7 +275,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
276
275
  else {
277
276
  outResult[i] = result;
278
277
  }
279
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
278
+ this.add(item, 4 | 128);
280
279
  continue;
281
280
  }
282
281
  if (!ignoreCache && outCacheMiss) {
@@ -327,13 +326,13 @@ async function executeBatchQuery(batch, options = '', outResult) {
327
326
  reject(error);
328
327
  }
329
328
  else {
330
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
329
+ this.add(item, 4);
331
330
  resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows.length ? rows : null);
332
331
  }
333
332
  }
334
333
  else {
335
334
  const rows = await client.query(query, params);
336
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
335
+ this.add(item, 4);
337
336
  if ((0, types_1.isArray)(rows)) {
338
337
  const [row1, row2] = rows;
339
338
  if (rows.length === 2 && Array.isArray(row1) && !Array.isArray(row2) && isOkPacket(row2)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mariadb",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
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.8.4",
25
- "@e-mc/types": "^0.8.4",
26
- "mariadb": "^3.2.3"
24
+ "@e-mc/db": "^0.8.7",
25
+ "@e-mc/types": "^0.8.7",
26
+ "mariadb": "^3.3.0"
27
27
  }
28
28
  }