@pi-r/mssql 0.4.0 → 0.6.0
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 +37 -34
- package/package.json +4 -4
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;
|
|
@@ -498,7 +501,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
498
501
|
}, outResult);
|
|
499
502
|
}
|
|
500
503
|
exports.executeBatchQuery = executeBatchQuery;
|
|
501
|
-
function checkTimeout(value, limit = 0) {
|
|
504
|
+
async function checkTimeout(value, limit = 0) {
|
|
502
505
|
return DbPool.checkTimeout(POOL_STATE, value, limit);
|
|
503
506
|
}
|
|
504
507
|
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.0",
|
|
4
4
|
"description": "MSSQL client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -21,9 +21,9 @@
|
|
|
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.
|
|
26
|
-
"tedious": "^16.
|
|
24
|
+
"@e-mc/db": "^0.8.0",
|
|
25
|
+
"@e-mc/types": "^0.8.0",
|
|
26
|
+
"tedious": "^16.6.1",
|
|
27
27
|
"tedious-connection-pool2": "^2.1.0"
|
|
28
28
|
}
|
|
29
29
|
}
|