@pi-r/mariadb 0.5.0 → 0.5.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 +1 -1
- package/README.md +4 -2
- package/client/index.d.ts +11 -0
- package/client/index.js +12 -12
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Wit Studio
|
|
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
|
@@ -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"
|
|
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"
|
|
113
|
+
const config = this.getPoolConfig("mariadb", password);
|
|
114
114
|
if (config) {
|
|
115
115
|
const { min, max, idle, timeout, socket_timeout } = config;
|
|
116
116
|
if (min >= 0) {
|
|
@@ -166,17 +166,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
166
166
|
if (!parallel) {
|
|
167
167
|
outResult || (outResult = new Array(length));
|
|
168
168
|
}
|
|
169
|
-
const caching = this.hasCache("mariadb"
|
|
169
|
+
const caching = this.hasCache("mariadb", sessionKey);
|
|
170
170
|
const tasks = new Array(length);
|
|
171
171
|
const clients = [];
|
|
172
172
|
const pools = [];
|
|
173
173
|
let mariaDBPool, mariaDBClient, mariaDBCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
|
|
174
174
|
const getConnection = async (item, credential) => {
|
|
175
|
-
item.transactionState = 64
|
|
175
|
+
item.transactionState = 64;
|
|
176
176
|
let client;
|
|
177
177
|
if (mariaDBPool) {
|
|
178
178
|
pools.push(client = await mariaDBPool.getConnection());
|
|
179
|
-
item.transactionState &= ~64
|
|
179
|
+
item.transactionState &= ~64;
|
|
180
180
|
return client;
|
|
181
181
|
}
|
|
182
182
|
const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
|
|
@@ -219,15 +219,15 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
219
219
|
}
|
|
220
220
|
mariaDBCredential = credential;
|
|
221
221
|
}
|
|
222
|
-
item.transactionState &= ~64
|
|
222
|
+
item.transactionState &= ~64;
|
|
223
223
|
return client;
|
|
224
224
|
};
|
|
225
225
|
for (let i = 0; i < length; ++i) {
|
|
226
226
|
const item = batch[i];
|
|
227
227
|
const { source, query, params, ignoreCache } = item;
|
|
228
228
|
let credential = mariaDBCredential || onceCredential, error;
|
|
229
|
-
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mariadb"
|
|
230
|
-
if (!(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials"
|
|
229
|
+
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mariadb", 'options', null, item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
|
|
230
|
+
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"))) {
|
|
231
231
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
232
232
|
if (!parallel) {
|
|
233
233
|
tasks.length = 0;
|
|
@@ -243,7 +243,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
243
243
|
}
|
|
244
244
|
continue;
|
|
245
245
|
}
|
|
246
|
-
item.transactionState = 1
|
|
246
|
+
item.transactionState = 1;
|
|
247
247
|
const renewCache = ignoreCache === 0;
|
|
248
248
|
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
249
249
|
let queryString = '';
|
|
@@ -258,7 +258,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
258
258
|
else {
|
|
259
259
|
outResult[i] = result;
|
|
260
260
|
}
|
|
261
|
-
this.add(item, 4
|
|
261
|
+
this.add(item, 4 | 128);
|
|
262
262
|
continue;
|
|
263
263
|
}
|
|
264
264
|
if (!ignoreCache && outCacheMiss) {
|
|
@@ -309,13 +309,13 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
309
309
|
reject(error);
|
|
310
310
|
}
|
|
311
311
|
else {
|
|
312
|
-
this.add(item, 4
|
|
312
|
+
this.add(item, 4);
|
|
313
313
|
resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows.length ? rows : null);
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
else {
|
|
317
317
|
const rows = await client.query(query, params);
|
|
318
|
-
this.add(item, 4
|
|
318
|
+
this.add(item, 4);
|
|
319
319
|
if ((0, types_1.isArray)(rows)) {
|
|
320
320
|
const [row1, row2] = rows;
|
|
321
321
|
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.5.
|
|
3
|
+
"version": "0.5.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.7.
|
|
25
|
-
"@e-mc/types": "^0.7.
|
|
26
|
-
"mariadb": "^3.2.
|
|
24
|
+
"@e-mc/db": "^0.7.2",
|
|
25
|
+
"@e-mc/types": "^0.7.2",
|
|
26
|
+
"mariadb": "^3.2.3"
|
|
27
27
|
}
|
|
28
28
|
}
|