@pi-r/mariadb 0.6.6 → 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
@@ -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,8 +62,8 @@ 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
  }
@@ -124,22 +124,22 @@ function setCredential(item) {
124
124
  if (config) {
125
125
  const { min, max, idle, queue_idle, timeout, socket_timeout } = config;
126
126
  if (min >= 0) {
127
- credential.minimumIdle ?? (credential.minimumIdle = min);
127
+ credential.minimumIdle ??= min;
128
128
  }
129
129
  if (max > 0) {
130
- credential.connectionLimit ?? (credential.connectionLimit = max);
130
+ credential.connectionLimit ??= max;
131
131
  }
132
132
  if (idle >= 0) {
133
- credential.idleTimeout ?? (credential.idleTimeout = idle);
133
+ credential.idleTimeout ??= idle;
134
134
  }
135
135
  if (queue_idle > 0) {
136
- credential.acquireTimeout ?? (credential.acquireTimeout = queue_idle);
136
+ credential.acquireTimeout ??= queue_idle;
137
137
  }
138
138
  if (timeout > 0) {
139
- credential.connectTimeout ?? (credential.connectTimeout = timeout);
139
+ credential.connectTimeout ??= timeout;
140
140
  }
141
141
  if (socket_timeout > 0) {
142
- credential.socketTimeout ?? (credential.socketTimeout = socket_timeout);
142
+ credential.socketTimeout ??= socket_timeout;
143
143
  }
144
144
  }
145
145
  const poolKey = getPoolKey(credential);
@@ -177,7 +177,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
177
177
  parallel = !batch.some(item => item.parallel === false);
178
178
  }
179
179
  if (!parallel) {
180
- outResult || (outResult = new Array(length));
180
+ outResult ||= new Array(length);
181
181
  }
182
182
  const caching = this.hasCache("mariadb", sessionKey);
183
183
  const tasks = new Array(length);
@@ -244,7 +244,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
244
244
  const item = batch[i];
245
245
  const { source, query, params, ignoreCache } = item;
246
246
  let credential = mariaDBCredential || onceCredential, error;
247
- 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;
248
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"))) {
249
249
  if (this.handleFail(error, item, { errorQuery })) {
250
250
  if (!parallel) {
@@ -266,8 +266,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
266
266
  let queryString = '';
267
267
  if (caching && ignoreCache !== true && !streamRow) {
268
268
  queryString = Db.asString(query, true) + '_' + Db.asString(params, true);
269
- const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
270
269
  if (ignoreCache !== 1) {
270
+ const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
271
271
  if (result) {
272
272
  if (parallel) {
273
273
  tasks[i] = Promise.resolve(result);
@@ -368,8 +368,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
368
368
  }
369
369
  return this.processRows(batch, tasks, {
370
370
  disconnect: () => {
371
- clients.forEach(async (item) => item.end());
372
- pools.forEach(async (item) => item.release());
371
+ clients.forEach(item => {
372
+ item.end();
373
+ });
374
+ pools.forEach(item => {
375
+ item.release();
376
+ });
373
377
  },
374
378
  parallel
375
379
  }, outResult);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mariadb",
3
- "version": "0.6.6",
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.7",
25
- "@e-mc/types": "^0.8.7",
24
+ "@e-mc/db": "^0.9.0",
25
+ "@e-mc/types": "^0.9.0",
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