@pi-r/mssql 0.3.6 → 0.3.8

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 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 Pool(poolConfig, credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
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 db.Connection(mssqlCredential || credential);
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 db.Request(query, () => {
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['__recordset__'] = 0;
399
- output['__returnvalue__'] = true;
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, db.TYPES, params, false);
410
+ convertParameters.call(request, tedious.TYPES, params, false);
411
411
  if (paramsOutput) {
412
- convertParameters.call(request, db.TYPES, paramsOutput, true);
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['__recordset__'] = recordset);
426
+ items.forEach((col) => col.__recordset__ = recordset);
427
427
  rows.push(...items);
428
428
  }
429
429
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mssql",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
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.6.16",
25
- "@e-mc/types": "^0.6.16",
24
+ "@e-mc/db": "^0.6.19",
25
+ "@e-mc/types": "^0.6.19",
26
26
  "tedious": "^16.7.1",
27
27
  "tedious-connection-pool2": "^2.1.0"
28
28
  }
package/client/pool.js DELETED
@@ -1,63 +0,0 @@
1
- "use strict";
2
- const types_1 = require("@e-mc/types");
3
- const util_1 = require("@e-mc/db/util");
4
- const DbPool = require('@e-mc/db/pool');
5
- class MSSQLPool extends DbPool {
6
- static asString(credential) {
7
- const auth = credential.authentication?.options;
8
- if (!credential.server || !(auth?.userName && auth.password)) {
9
- return super.asString(credential);
10
- }
11
- const options = credential.options;
12
- let tls;
13
- if (options && (tls = options.cryptoCredentialsDetails)) {
14
- if (!(0, types_1.isObject)(tls)) {
15
- delete options.cryptoCredentialsDetails;
16
- }
17
- else if (tls.ca || tls.cert || tls.key) {
18
- credential = { ...credential };
19
- if ('uuidKey' in credential) {
20
- delete credential.uuidKey;
21
- }
22
- credential.options = { ...options };
23
- delete credential.options.cryptoCredentialsDetails;
24
- return JSON.stringify(credential) + '_tls';
25
- }
26
- }
27
- if ('uuidKey' in credential) {
28
- credential = { ...credential };
29
- delete credential.uuidKey;
30
- }
31
- return JSON.stringify(credential);
32
- }
33
- async getConnection() {
34
- return new Promise((resolve, reject) => {
35
- this.client.acquire((err, connection) => {
36
- if (err) {
37
- reject(err);
38
- }
39
- else {
40
- resolve(connection);
41
- }
42
- });
43
- });
44
- }
45
- async close() {
46
- return new Promise((resolve, reject) => {
47
- try {
48
- this.client.drain();
49
- resolve();
50
- }
51
- catch (err) {
52
- reject(err);
53
- }
54
- });
55
- }
56
- isEmpty() {
57
- return this.closed || (0, util_1.checkEmpty)(this.client.connections) && (0, util_1.checkEmpty)(this.client.waiting);
58
- }
59
- get closed() {
60
- return !!this.client.drained;
61
- }
62
- }
63
- module.exports = MSSQLPool;
package/types/pool.d.ts DELETED
@@ -1,67 +0,0 @@
1
- import type { Connection, ConnectionConfiguration } from 'tedious';
2
-
3
- import type * as EventEmitter from 'events';
4
-
5
- declare class Pool extends EventEmitter {
6
- /**
7
- * Connection Pool constructor
8
- * @param poolConfig the pool configuration
9
- * @param connectionConfig the connection configuration
10
- */
11
- constructor(poolConfig: Pool.PoolConfig, connectionConfig: ConnectionConfiguration);
12
-
13
- /**
14
- * acquires a connection from the pool
15
- * @param callback invoked when the connection is retrieved and ready
16
- */
17
- acquire(callback: (err: Error, connection: Pool.PooledConnection) => void): void;
18
-
19
- /**
20
- * closes opened connections
21
- */
22
- drain(): void;
23
- }
24
-
25
- declare namespace Pool {
26
-
27
- export class PooledConnection extends Connection {
28
- /**
29
- * If the connection is issued from a connection pool returns the connection to the pool.
30
- */
31
- release(): void;
32
- }
33
-
34
- export interface PoolConfig {
35
- /**
36
- * Minimum concurrent connections
37
- */
38
- min?: number | undefined;
39
-
40
- /**
41
- * Maximum concurrent connections
42
- */
43
- max?: number | undefined;
44
-
45
- /**
46
- * Defines if logging is activated
47
- */
48
- log?: boolean | undefined;
49
-
50
- /**
51
- * Idle timeout
52
- */
53
- idleTimeout?: number | undefined;
54
-
55
- /**
56
- * Retry delay
57
- */
58
- retryDelay?: number | undefined;
59
-
60
- /**
61
- * Acquire timeout
62
- */
63
- acquireTimeout?: number | undefined;
64
- }
65
- }
66
-
67
- export = Pool;