@pi-r/mariadb 0.6.7 → 0.7.1

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
@@ -29,7 +29,7 @@ function removePoolProperties(credential) {
29
29
  for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
30
30
  const attr = POOL_UNUSED[i];
31
31
  if (attr in credential) {
32
- result || (result = { ...credential });
32
+ result ||= { ...credential };
33
33
  if (attr !== 'ssl') {
34
34
  delete result[attr];
35
35
  }
@@ -62,15 +62,14 @@ function getPoolKey(credential) {
62
62
  }
63
63
  function setAuthentication(credential) {
64
64
  const auth = (0, util_1.parseServerAuth)(credential);
65
- credential.host || (credential.host = auth.hostname);
66
- credential.user || (credential.user = auth.username);
65
+ credential.host ||= auth.hostname;
66
+ credential.user ||= auth.username;
67
67
  if ((0, types_1.isPlainObject)(credential.ssl)) {
68
68
  this.readTLSConfig(credential.ssl);
69
69
  }
70
70
  }
71
71
  exports.setAuthentication = setAuthentication;
72
72
  function setCredential(item) {
73
- var _a, _b, _c, _d, _e, _f;
74
73
  let credential = this.getCredential(item);
75
74
  if (credential) {
76
75
  setAuthentication.call(this, credential);
@@ -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
- (_a = credential.minimumIdle) !== null && _a !== void 0 ? _a : (credential.minimumIdle = min);
127
+ credential.minimumIdle ??= min;
129
128
  }
130
129
  if (max > 0) {
131
- (_b = credential.connectionLimit) !== null && _b !== void 0 ? _b : (credential.connectionLimit = max);
130
+ credential.connectionLimit ??= max;
132
131
  }
133
132
  if (idle >= 0) {
134
- (_c = credential.idleTimeout) !== null && _c !== void 0 ? _c : (credential.idleTimeout = idle);
133
+ credential.idleTimeout ??= idle;
135
134
  }
136
135
  if (queue_idle > 0) {
137
- (_d = credential.acquireTimeout) !== null && _d !== void 0 ? _d : (credential.acquireTimeout = queue_idle);
136
+ credential.acquireTimeout ??= queue_idle;
138
137
  }
139
138
  if (timeout > 0) {
140
- (_e = credential.connectTimeout) !== null && _e !== void 0 ? _e : (credential.connectTimeout = timeout);
139
+ credential.connectTimeout ??= timeout;
141
140
  }
142
141
  if (socket_timeout > 0) {
143
- (_f = credential.socketTimeout) !== null && _f !== void 0 ? _f : (credential.socketTimeout = socket_timeout);
142
+ credential.socketTimeout ??= socket_timeout;
144
143
  }
145
144
  }
146
145
  const poolKey = getPoolKey(credential);
@@ -156,7 +155,6 @@ async function executeQuery(item, options) {
156
155
  }
157
156
  exports.executeQuery = executeQuery;
158
157
  async function executeBatchQuery(batch, options = '', outResult) {
159
- var _a;
160
158
  const length = batch.length;
161
159
  if (length === 0) {
162
160
  return [];
@@ -179,7 +177,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
179
177
  parallel = !batch.some(item => item.parallel === false);
180
178
  }
181
179
  if (!parallel) {
182
- outResult || (outResult = new Array(length));
180
+ outResult ||= new Array(length);
183
181
  }
184
182
  const caching = this.hasCache("mariadb", sessionKey);
185
183
  const tasks = new Array(length);
@@ -239,14 +237,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
239
237
  item.transactionState &= ~64;
240
238
  return client;
241
239
  };
242
- if ((_a = this.host) === null || _a === void 0 ? void 0 : _a.username) {
240
+ if (this.host?.username) {
243
241
  this.applyCommand(...batch);
244
242
  }
245
243
  for (let i = 0; i < length; ++i) {
246
244
  const item = batch[i];
247
245
  const { source, query, params, ignoreCache } = item;
248
246
  let credential = mariaDBCredential || onceCredential, error;
249
- 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;
250
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"))) {
251
249
  if (this.handleFail(error, item, { errorQuery })) {
252
250
  if (!parallel) {
@@ -268,8 +266,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
268
266
  let queryString = '';
269
267
  if (caching && ignoreCache !== true && !streamRow) {
270
268
  queryString = Db.asString(query, true) + '_' + Db.asString(params, true);
271
- const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
272
269
  if (ignoreCache !== 1) {
270
+ const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
273
271
  if (result) {
274
272
  if (parallel) {
275
273
  tasks[i] = Promise.resolve(result);
@@ -370,8 +368,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
370
368
  }
371
369
  return this.processRows(batch, tasks, {
372
370
  disconnect: () => {
373
- clients.forEach(async (item) => item.end());
374
- pools.forEach(async (item) => item.release());
371
+ clients.forEach(item => {
372
+ item.end();
373
+ });
374
+ pools.forEach(item => {
375
+ item.release();
376
+ });
375
377
  },
376
378
  parallel
377
379
  }, outResult);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mariadb",
3
- "version": "0.6.7",
3
+ "version": "0.7.1",
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.8",
25
- "@e-mc/types": "^0.8.8",
24
+ "@e-mc/db": "^0.9.2",
25
+ "@e-mc/types": "^0.9.2",
26
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