@pi-r/mariadb 0.11.0 → 0.11.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/client/index.js +24 -6
- package/client/pool.js +1 -1
- package/package.json +4 -4
- package/types/index.d.ts +1 -0
package/client/index.js
CHANGED
|
@@ -126,7 +126,7 @@ function setCredential(item) {
|
|
|
126
126
|
.parent = POOL_STATE;
|
|
127
127
|
}
|
|
128
128
|
async function executeQuery(item, options) {
|
|
129
|
-
return (await executeBatchQuery.call(this, [item], options))
|
|
129
|
+
return (await executeBatchQuery.call(this, [item], options)).at(0) || [];
|
|
130
130
|
}
|
|
131
131
|
async function executeBatchQuery(batch, options = '', outResult) {
|
|
132
132
|
const length = batch.length;
|
|
@@ -212,11 +212,29 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
212
212
|
if (this.host?.username) {
|
|
213
213
|
this.applyCommand(...batch);
|
|
214
214
|
}
|
|
215
|
-
for (let i = 0; i < length; ++i) {
|
|
215
|
+
for (let i = 0, statement; i < length; ++i) {
|
|
216
216
|
const item = batch[i];
|
|
217
|
-
const { source,
|
|
218
|
-
let credential = mariaDBCredential || onceCredential, error;
|
|
217
|
+
const { source, params, ignoreCache } = item;
|
|
219
218
|
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mariadb", 'options', item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
|
|
219
|
+
let credential = mariaDBCredential || onceCredential, query = item.query, prepared = false, error;
|
|
220
|
+
if (typeof item.preparedStatement === 'boolean') {
|
|
221
|
+
if (item.preparedStatement) {
|
|
222
|
+
if (query) {
|
|
223
|
+
statement = query;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
query = statement;
|
|
227
|
+
}
|
|
228
|
+
prepared = true;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
statement = undefined;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else if (!query && statement) {
|
|
235
|
+
query = statement;
|
|
236
|
+
prepared = true;
|
|
237
|
+
}
|
|
220
238
|
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"))) {
|
|
221
239
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
222
240
|
if (!parallel) {
|
|
@@ -236,7 +254,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
236
254
|
item.transactionState = 1;
|
|
237
255
|
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
238
256
|
let queryString = '';
|
|
239
|
-
if (caching && ignoreCache !== true && !streamRow) {
|
|
257
|
+
if (caching && ignoreCache !== true && !prepared && !streamRow) {
|
|
240
258
|
queryString = Db.asString(query, true) + '_' + Db.asString(params, true);
|
|
241
259
|
if (ignoreCache !== 1) {
|
|
242
260
|
const result = this.getQueryResult(source, DbPool.sanitize(credential), queryString, cacheValue);
|
|
@@ -303,7 +321,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
303
321
|
}
|
|
304
322
|
}
|
|
305
323
|
else {
|
|
306
|
-
const rows = await client
|
|
324
|
+
const rows = await client[prepared && connectOnce && !parallel ? 'execute' : 'query'](query, params);
|
|
307
325
|
this.add(item, 4);
|
|
308
326
|
if ((0, types_1.isArray)(rows)) {
|
|
309
327
|
const [row1, row2] = rows;
|
package/client/pool.js
CHANGED
|
@@ -3,7 +3,7 @@ const types_1 = require("@e-mc/types");
|
|
|
3
3
|
const DbPool = require('@e-mc/db/pool');
|
|
4
4
|
const POOL_ACTIVE = new WeakSet();
|
|
5
5
|
class MariaDBPool extends DbPool {
|
|
6
|
-
static CACHE_UNUSED = ['connectTimeout', 'socketTimeout', 'compress', 'keepAliveDelay', 'acquireTimeout', 'connectionLimit', 'idleTimeout', 'initializationTimeout', 'minDelayValidation', 'minimumIdle', 'resetAfterUse', 'noControlAfterUse', 'leakDetectionTimeout'];
|
|
6
|
+
static CACHE_UNUSED = ['connectTimeout', 'socketTimeout', 'compress', 'keepAliveDelay', 'acquireTimeout', 'connectionLimit', 'idleTimeout', 'initializationTimeout', 'minDelayValidation', 'minimumIdle', 'resetAfterUse', 'noControlAfterUse', 'leakDetectionTimeout', 'logger'];
|
|
7
7
|
static CACHE_IGNORE = ['initSql', 'sessionVariables', 'stream', 'infileStreamFactory'];
|
|
8
8
|
static asString(credential) {
|
|
9
9
|
if ((credential.host || credential.socketPath) && credential.user) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mariadb",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "MariaDB client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/db": "^0.13.
|
|
24
|
-
"@e-mc/types": "^0.13.
|
|
25
|
-
"mariadb": "^3.
|
|
23
|
+
"@e-mc/db": "^0.13.9",
|
|
24
|
+
"@e-mc/types": "^0.13.9",
|
|
25
|
+
"mariadb": "^3.5.2"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { PoolConfig, QueryConfig } from 'mariadb';
|
|
|
7
7
|
|
|
8
8
|
export interface MariaDBDataSource<T = unknown> extends DbDataSource<string | QueryConfig, unknown, unknown, MariaDBCredential, string>, ExecuteAction<T> {
|
|
9
9
|
source: "mariadb";
|
|
10
|
+
preparedStatement?: boolean;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export type MariaDBCredential = PoolConfig & ServerAuth;
|