@pi-r/mssql 0.5.0 → 0.6.1
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 +39 -37
- package/package.json +3 -3
- package/types/index.d.ts +2 -0
package/client/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const Db = require("@e-mc/db");
|
|
|
8
8
|
const TediousPool = require('tedious-connection-pool2');
|
|
9
9
|
const DbPool = require('@e-mc/db/pool');
|
|
10
10
|
class MSSQLPool extends DbPool {
|
|
11
|
-
getConnection() {
|
|
11
|
+
async getConnection() {
|
|
12
12
|
return new Promise((resolve, reject) => {
|
|
13
13
|
this.client.acquire((err, connection) => {
|
|
14
14
|
if (err) {
|
|
@@ -20,7 +20,7 @@ class MSSQLPool extends DbPool {
|
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
-
close() {
|
|
23
|
+
async close() {
|
|
24
24
|
return new Promise((resolve, reject) => {
|
|
25
25
|
try {
|
|
26
26
|
this.client.drain();
|
|
@@ -190,41 +190,41 @@ function setCredential(item) {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
const usePool = item.usePool;
|
|
193
|
-
if (usePool) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
193
|
+
if (!usePool) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
let pool;
|
|
197
|
+
password = undefined;
|
|
198
|
+
if (typeof usePool === 'string' && (username = authOptions.userName)) {
|
|
199
|
+
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
200
|
+
if (pool) {
|
|
201
|
+
pool.add(item, password);
|
|
202
|
+
return;
|
|
202
203
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (idle >= 0) {
|
|
216
|
-
poolConfig.idleTimeout ?? (poolConfig.idleTimeout = idle);
|
|
217
|
-
}
|
|
218
|
-
if (queue_idle >= 0) {
|
|
219
|
-
poolConfig.acquireTimeout ?? (poolConfig.acquireTimeout = queue_idle);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
new MSSQLPool(new TediousPool(poolConfig, credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
204
|
+
}
|
|
205
|
+
const poolKey = getPoolKey(credential);
|
|
206
|
+
if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
|
|
207
|
+
pool.add(item);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const config = this.getPoolConfig("mssql" /* STRINGS.MODULE_NAME */, password);
|
|
211
|
+
const poolConfig = (0, types_1.isPlainObject)(item.usePool) ? item.usePool : {};
|
|
212
|
+
if (config) {
|
|
213
|
+
const { min, max, idle, queue_idle } = config;
|
|
214
|
+
if (min >= 0) {
|
|
215
|
+
poolConfig.min ?? (poolConfig.min = min);
|
|
223
216
|
}
|
|
224
|
-
|
|
225
|
-
|
|
217
|
+
if (max > 0) {
|
|
218
|
+
poolConfig.max ?? (poolConfig.max = max);
|
|
219
|
+
}
|
|
220
|
+
if (idle >= 0) {
|
|
221
|
+
poolConfig.idleTimeout ?? (poolConfig.idleTimeout = idle);
|
|
222
|
+
}
|
|
223
|
+
if (queue_idle >= 0) {
|
|
224
|
+
poolConfig.acquireTimeout ?? (poolConfig.acquireTimeout = queue_idle);
|
|
226
225
|
}
|
|
227
226
|
}
|
|
227
|
+
new MSSQLPool(new TediousPool(poolConfig, credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
228
228
|
}
|
|
229
229
|
exports.setCredential = setCredential;
|
|
230
230
|
async function executeQuery(item, options) {
|
|
@@ -321,6 +321,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
321
321
|
item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
|
|
322
322
|
return client;
|
|
323
323
|
};
|
|
324
|
+
if (this.host?.username) {
|
|
325
|
+
this.applyCommand(...batch);
|
|
326
|
+
}
|
|
324
327
|
for (let i = 0; i < length; ++i) {
|
|
325
328
|
const item = batch[i];
|
|
326
329
|
const { source, query, ignoreCache } = item;
|
|
@@ -343,10 +346,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
343
346
|
}
|
|
344
347
|
item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
|
|
345
348
|
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mssql" /* STRINGS.MODULE_NAME */, 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
|
|
346
|
-
const
|
|
347
|
-
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
349
|
+
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
348
350
|
let params = item.params, queryString = '';
|
|
349
|
-
if (
|
|
351
|
+
if (caching && ignoreCache !== true && !streamRow) {
|
|
350
352
|
queryString = Db.asString(query, true) + '_' + Db.asString(params, true);
|
|
351
353
|
if (ignoreCache !== 1) {
|
|
352
354
|
const result = this.getQueryResult(source, credential, queryString, cacheValue);
|
|
@@ -498,7 +500,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
498
500
|
}, outResult);
|
|
499
501
|
}
|
|
500
502
|
exports.executeBatchQuery = executeBatchQuery;
|
|
501
|
-
function checkTimeout(value, limit = 0) {
|
|
503
|
+
async function checkTimeout(value, limit = 0) {
|
|
502
504
|
return DbPool.checkTimeout(POOL_STATE, value, limit);
|
|
503
505
|
}
|
|
504
506
|
exports.checkTimeout = checkTimeout;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mssql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "MSSQL 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.
|
|
25
|
-
"@e-mc/types": "^0.
|
|
24
|
+
"@e-mc/db": "^0.8.1",
|
|
25
|
+
"@e-mc/types": "^0.8.1",
|
|
26
26
|
"tedious": "^16.6.1",
|
|
27
27
|
"tedious-connection-pool2": "^2.1.0"
|
|
28
28
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
|
2
2
|
|
|
3
3
|
import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
4
|
|
|
5
|
+
// @ts-ignore
|
|
5
6
|
import type { ConnectionConfig, ParameterOptions, TediousType, TediousTypes } from 'tedious';
|
|
7
|
+
// @ts-ignore
|
|
6
8
|
import type { PoolConfig } from 'tedious-connection-pool';
|
|
7
9
|
|
|
8
10
|
export interface MSSQLDataSource extends DbDataSource<string, unknown, unknown, string | MSSQLCredential, string | PoolConfig>, ExecuteAction<MSSQLRequestParameters | MSSQLRequestWithOutputParameters> {
|