@pi-r/mariadb 0.3.0 → 0.3.2

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 2023 Studio Trigger
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,5 +1,7 @@
1
- ### @pi-r/mariadb
1
+ # @pi-r/mariadb
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever Aina
4
+
5
+ ## LICENSE
4
6
 
5
7
  MIT
@@ -0,0 +1,11 @@
1
+ import type { IDb } from '@e-mc/types/lib';
2
+
3
+ import type { IDbSourceClient } from '@e-mc/db/types';
4
+
5
+ import type { MariaDBCredential, MariaDBDataSource } from '../types';
6
+
7
+ declare const MariaDB: IDbSourceClient<MariaDBDataSource> & {
8
+ setAuthentication(this: IDb, credential: MariaDBCredential): void;
9
+ };
10
+
11
+ export = MariaDB;
package/client/index.js CHANGED
@@ -96,7 +96,7 @@ function setCredential(item) {
96
96
  errors.push('user');
97
97
  }
98
98
  if (errors.length) {
99
- throw (0, types_1.errorMessage)("mariadb" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
99
+ throw (0, types_1.errorMessage)("mariadb", 'Not defined - ' + errors.join(' | '));
100
100
  }
101
101
  const usePool = item.usePool;
102
102
  if (usePool) {
@@ -110,7 +110,7 @@ function setCredential(item) {
110
110
  }
111
111
  const poolKey = getPoolKey(credential);
112
112
  if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
113
- const config = this.getPoolConfig("mariadb" /* STRINGS.MODULE_NAME */, password);
113
+ const config = this.getPoolConfig("mariadb", password);
114
114
  if (config) {
115
115
  const { max, idle } = config;
116
116
  if (max > 0) {
@@ -157,17 +157,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
157
157
  if (!parallel) {
158
158
  outResult || (outResult = new Array(length));
159
159
  }
160
- const caching = this.hasCache("mariadb" /* STRINGS.MODULE_NAME */, sessionKey);
160
+ const caching = this.hasCache("mariadb", sessionKey);
161
161
  const tasks = new Array(length);
162
162
  const clients = [];
163
163
  const pools = [];
164
164
  let mariaDBPool, mariaDBClient, mariaDBCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
165
165
  const getConnection = async (item, credential) => {
166
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
166
+ item.transactionState = 64;
167
167
  let client;
168
168
  if (mariaDBPool) {
169
169
  pools.push(client = await mariaDBPool.getConnection());
170
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
170
+ item.transactionState &= ~64;
171
171
  return client;
172
172
  }
173
173
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -210,15 +210,15 @@ async function executeBatchQuery(batch, options = '', outResult) {
210
210
  }
211
211
  mariaDBCredential = credential;
212
212
  }
213
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
213
+ item.transactionState &= ~64;
214
214
  return client;
215
215
  };
216
216
  for (let i = 0; i < length; ++i) {
217
217
  const item = batch[i];
218
218
  const { source, query, params, ignoreCache } = item;
219
219
  let credential = mariaDBCredential || onceCredential, error;
220
- const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mariadb" /* STRINGS.MODULE_NAME */, 'options', null, item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
221
- 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 */))) {
220
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mariadb", 'options', null, item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
221
+ 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"))) {
222
222
  if (this.handleFail(error, item, { errorQuery })) {
223
223
  if (!parallel) {
224
224
  tasks.length = 0;
@@ -234,7 +234,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
234
234
  }
235
235
  continue;
236
236
  }
237
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
237
+ item.transactionState = 1;
238
238
  const renewCache = ignoreCache === 0;
239
239
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
240
240
  let queryString = '';
@@ -249,7 +249,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
249
249
  else {
250
250
  outResult[i] = result;
251
251
  }
252
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
252
+ this.add(item, 4 | 128);
253
253
  continue;
254
254
  }
255
255
  if (!ignoreCache && outCacheMiss) {
@@ -300,13 +300,13 @@ async function executeBatchQuery(batch, options = '', outResult) {
300
300
  reject(error);
301
301
  }
302
302
  else {
303
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
303
+ this.add(item, 4);
304
304
  resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows.length ? rows : null);
305
305
  }
306
306
  }
307
307
  else {
308
308
  const rows = await client.query(query, params);
309
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
309
+ this.add(item, 4);
310
310
  if ((0, types_1.isArray)(rows)) {
311
311
  const [row1, row2] = rows;
312
312
  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.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "MariaDB client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/anpham6/pi-r.git",
12
+ "url": "git+https://github.com/anpham6/pi-r.git",
13
13
  "directory": "src/db/mariadb"
14
14
  },
15
15
  "keywords": [
@@ -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.6.0",
25
- "@e-mc/types": "^0.6.0",
26
- "mariadb": "^3.2.0"
24
+ "@e-mc/db": "^0.6.1",
25
+ "@e-mc/types": "^0.6.1",
26
+ "mariadb": "^3.2.3"
27
27
  }
28
28
  }