@pi-r/mssql 0.3.6 → 0.3.7
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 +10 -10
- package/package.json +1 -1
package/client/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = void 0;
|
|
4
|
+
const tedious = require("tedious");
|
|
4
5
|
const types_1 = require("@e-mc/types");
|
|
5
6
|
const util_1 = require("@e-mc/db/util");
|
|
6
7
|
const Db = require("@e-mc/db");
|
|
8
|
+
const TediousPool = require('tedious-connection-pool2');
|
|
7
9
|
const DbPool = require('@e-mc/db/pool');
|
|
8
10
|
class MSSQLPool extends DbPool {
|
|
9
11
|
getConnection() {
|
|
@@ -202,7 +204,6 @@ function setCredential(item) {
|
|
|
202
204
|
}
|
|
203
205
|
const poolKey = getPoolKey(credential);
|
|
204
206
|
if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
|
|
205
|
-
const Pool = require("tedious-connection-pool2");
|
|
206
207
|
const config = this.getPoolConfig("mssql", password);
|
|
207
208
|
const poolConfig = (0, types_1.isPlainObject)(item.usePool) ? item.usePool : {};
|
|
208
209
|
if (config) {
|
|
@@ -220,7 +221,7 @@ function setCredential(item) {
|
|
|
220
221
|
(_d = poolConfig.acquireTimeout) !== null && _d !== void 0 ? _d : (poolConfig.acquireTimeout = queue_idle);
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
|
-
new MSSQLPool(new
|
|
224
|
+
new MSSQLPool(new TediousPool(poolConfig, credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
224
225
|
}
|
|
225
226
|
else {
|
|
226
227
|
pool.add(item);
|
|
@@ -237,7 +238,6 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
237
238
|
if (length === 0) {
|
|
238
239
|
return [];
|
|
239
240
|
}
|
|
240
|
-
const db = require("tedious");
|
|
241
241
|
let parallel, connectOnce, errorQuery, sessionKey, outCacheMiss;
|
|
242
242
|
if ((0, types_1.isPlainObject)(options)) {
|
|
243
243
|
({ parallel, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
|
|
@@ -303,7 +303,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
303
303
|
}
|
|
304
304
|
if (!client) {
|
|
305
305
|
clients.push(client = await new Promise((resolve, reject) => {
|
|
306
|
-
const sql = new
|
|
306
|
+
const sql = new tedious.Connection(mssqlCredential || credential);
|
|
307
307
|
sql.connect(err => {
|
|
308
308
|
if (err) {
|
|
309
309
|
reject(err);
|
|
@@ -388,15 +388,15 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
388
388
|
const processRow = typeof streamRow === 'function' && streamRow;
|
|
389
389
|
const rows = [];
|
|
390
390
|
let recordset = 1, resume, output;
|
|
391
|
-
const request = new
|
|
391
|
+
const request = new tedious.Request(query, () => {
|
|
392
392
|
if (error && this.handleFail(error, item, { errorQuery, commandType })) {
|
|
393
393
|
reject(error);
|
|
394
394
|
}
|
|
395
395
|
else {
|
|
396
396
|
this.add(item, 4);
|
|
397
397
|
if (output) {
|
|
398
|
-
output
|
|
399
|
-
output
|
|
398
|
+
output.__recordset__ = 0;
|
|
399
|
+
output.__returnvalue__ = true;
|
|
400
400
|
rows.push([output]);
|
|
401
401
|
}
|
|
402
402
|
resolve(!error ? this.setQueryResult(source, credential, queryString, rows, cacheValue) : rows);
|
|
@@ -407,9 +407,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
407
407
|
if (isOutputParameters(params)) {
|
|
408
408
|
({ input: params, output: paramsOutput } = params);
|
|
409
409
|
}
|
|
410
|
-
convertParameters.call(request,
|
|
410
|
+
convertParameters.call(request, tedious.TYPES, params, false);
|
|
411
411
|
if (paramsOutput) {
|
|
412
|
-
convertParameters.call(request,
|
|
412
|
+
convertParameters.call(request, tedious.TYPES, paramsOutput, true);
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
415
|
request
|
|
@@ -423,7 +423,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
423
423
|
try {
|
|
424
424
|
const items = JSON.parse(data.value);
|
|
425
425
|
if ((0, types_1.isArray)(items)) {
|
|
426
|
-
items.forEach((col) => col
|
|
426
|
+
items.forEach((col) => col.__recordset__ = recordset);
|
|
427
427
|
rows.push(...items);
|
|
428
428
|
}
|
|
429
429
|
}
|