@pi-r/mariadb 0.6.5 → 0.7.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.
package/README.md CHANGED
@@ -1,10 +1,7 @@
1
- # @pi-r/mariadb
1
+ ### @pi-r/mariadb
2
2
 
3
- ## Documentation
3
+ https://e-mc.readthedocs.io/en/latest/db/mariadb.html
4
4
 
5
- - [E-mc](https://e-mc.readthedocs.io/en/latest/db/mariadb.html)
6
- - [squared](https://squared.readthedocs.io)
7
-
8
- ## LICENSE
5
+ ### LICENSE
9
6
 
10
7
  MIT
package/client/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
+ import type { IDb } from '@e-mc/types/lib';
2
+
1
3
  import type { IDbSourceClient } from '@e-mc/db/types';
2
4
 
3
- import type { MariaDBDataSource } from '../types';
5
+ import type { MariaDBCredential, MariaDBDataSource } from '../types';
4
6
 
5
- declare const MariaDB: IDbSourceClient<MariaDBDataSource>;
7
+ declare const MariaDB: IDbSourceClient<MariaDBDataSource> & {
8
+ setAuthentication(this: IDb, credential: MariaDBCredential): void;
9
+ };
6
10
 
7
11
  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");
@@ -30,7 +29,7 @@ function removePoolProperties(credential) {
30
29
  for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
31
30
  const attr = POOL_UNUSED[i];
32
31
  if (attr in credential) {
33
- result || (result = { ...credential });
32
+ result ||= { ...credential };
34
33
  if (attr !== 'ssl') {
35
34
  delete result[attr];
36
35
  }
@@ -63,8 +62,8 @@ function getPoolKey(credential) {
63
62
  }
64
63
  function setAuthentication(credential) {
65
64
  const auth = (0, util_1.parseServerAuth)(credential);
66
- credential.host || (credential.host = auth.hostname);
67
- credential.user || (credential.user = auth.username);
65
+ credential.host ||= auth.hostname;
66
+ credential.user ||= auth.username;
68
67
  if ((0, types_1.isPlainObject)(credential.ssl)) {
69
68
  this.readTLSConfig(credential.ssl);
70
69
  }
@@ -125,22 +124,22 @@ function setCredential(item) {
125
124
  if (config) {
126
125
  const { min, max, idle, queue_idle, timeout, socket_timeout } = config;
127
126
  if (min >= 0) {
128
- credential.minimumIdle ?? (credential.minimumIdle = min);
127
+ credential.minimumIdle ??= min;
129
128
  }
130
129
  if (max > 0) {
131
- credential.connectionLimit ?? (credential.connectionLimit = max);
130
+ credential.connectionLimit ??= max;
132
131
  }
133
132
  if (idle >= 0) {
134
- credential.idleTimeout ?? (credential.idleTimeout = idle);
133
+ credential.idleTimeout ??= idle;
135
134
  }
136
135
  if (queue_idle > 0) {
137
- credential.acquireTimeout ?? (credential.acquireTimeout = queue_idle);
136
+ credential.acquireTimeout ??= queue_idle;
138
137
  }
139
138
  if (timeout > 0) {
140
- credential.connectTimeout ?? (credential.connectTimeout = timeout);
139
+ credential.connectTimeout ??= timeout;
141
140
  }
142
141
  if (socket_timeout > 0) {
143
- credential.socketTimeout ?? (credential.socketTimeout = socket_timeout);
142
+ credential.socketTimeout ??= socket_timeout;
144
143
  }
145
144
  }
146
145
  const poolKey = getPoolKey(credential);
@@ -178,7 +177,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
178
177
  parallel = !batch.some(item => item.parallel === false);
179
178
  }
180
179
  if (!parallel) {
181
- outResult || (outResult = new Array(length));
180
+ outResult ||= new Array(length);
182
181
  }
183
182
  const caching = this.hasCache("mariadb", sessionKey);
184
183
  const tasks = new Array(length);
@@ -245,7 +244,7 @@ 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", 'options', null, item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
247
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mariadb", 'options', item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
249
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) {
@@ -267,8 +266,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
267
266
  let queryString = '';
268
267
  if (caching && ignoreCache !== true && !streamRow) {
269
268
  queryString = Db.asString(query, true) + '_' + Db.asString(params, true);
270
- const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
271
269
  if (ignoreCache !== 1) {
270
+ const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
272
271
  if (result) {
273
272
  if (parallel) {
274
273
  tasks[i] = Promise.resolve(result);
@@ -369,8 +368,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
369
368
  }
370
369
  return this.processRows(batch, tasks, {
371
370
  disconnect: () => {
372
- clients.forEach(async (item) => item.end());
373
- pools.forEach(async (item) => item.release());
371
+ clients.forEach(item => {
372
+ item.end();
373
+ });
374
+ pools.forEach(item => {
375
+ item.release();
376
+ });
374
377
  },
375
378
  parallel
376
379
  }, outResult);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mariadb",
3
- "version": "0.6.5",
3
+ "version": "0.7.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.8.6",
25
- "@e-mc/types": "^0.8.6",
26
- "mariadb": "^3.2.3"
24
+ "@e-mc/db": "^0.9.0",
25
+ "@e-mc/types": "^0.9.0",
26
+ "mariadb": "^3.3.0"
27
27
  }
28
28
  }
package/types/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import type { SecureContextOptions } from 'tls';
6
6
 
7
7
  import type { PoolConfig, QueryConfig } from 'mariadb';
8
8
 
9
- export interface MariaDBDataSource<T = unknown> extends DbDataSource<string | QueryConfig, unknown, unknown, string | MariaDBCredential, string>, ExecuteAction<T> {
9
+ export interface MariaDBDataSource<T = unknown> extends DbDataSource<string | QueryConfig, unknown, unknown, MariaDBCredential, string>, ExecuteAction<T> {
10
10
  source: "mariadb";
11
11
  }
12
12