@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 +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 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
|
@@ -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 { 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"
|
|
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
|
|
166
|
+
item.transactionState = 64;
|
|
167
167
|
let client;
|
|
168
168
|
if (mariaDBPool) {
|
|
169
169
|
pools.push(client = await mariaDBPool.getConnection());
|
|
170
|
-
item.transactionState &= ~64
|
|
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
|
|
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"
|
|
221
|
-
if (!(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials"
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
25
|
-
"@e-mc/types": "^0.6.
|
|
26
|
-
"mariadb": "^3.2.
|
|
24
|
+
"@e-mc/db": "^0.6.1",
|
|
25
|
+
"@e-mc/types": "^0.6.1",
|
|
26
|
+
"mariadb": "^3.2.3"
|
|
27
27
|
}
|
|
28
28
|
}
|