@pi-r/mssql 0.3.0 → 0.4.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/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
- Copyright 2023 An Pham
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
1
+ Copyright 2023 An Pham
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
7
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
- ### @pi-r/mssql
2
-
3
- ### LICENSE
4
-
1
+ ### @pi-r/mssql
2
+
3
+ ### LICENSE
4
+
5
5
  MIT
package/client/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { MSSQLDataSource } from '@e-mc/types/lib/db';
2
-
3
- import type { IDbSourceClient } from '@e-mc/db/types';
4
-
5
- declare const MSSQL: IDbSourceClient<MSSQLDataSource>;
6
-
1
+ import type { MSSQLDataSource } from '@e-mc/types/lib/db';
2
+
3
+ import type { IDbSourceClient } from '@e-mc/db/types';
4
+
5
+ declare const MSSQL: IDbSourceClient<MSSQLDataSource>;
6
+
7
7
  export = MSSQL;
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() {
@@ -132,9 +134,10 @@ function setCredential(item) {
132
134
  ({ username, password, hostname, port, database } = (0, util_1.parseServerAuth)(credential, true));
133
135
  }
134
136
  else {
137
+ const uri = item.uri;
135
138
  credential = {};
136
- if (item.uri) {
137
- const connection = (0, util_1.parseConnectionString)(item.uri);
139
+ if (uri) {
140
+ const connection = (0, util_1.parseConnectionString)(uri);
138
141
  if (connection) {
139
142
  ({ username, password, hostname, port, database } = connection);
140
143
  }
@@ -199,7 +202,6 @@ function setCredential(item) {
199
202
  }
200
203
  const poolKey = getPoolKey(credential);
201
204
  if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
202
- const Pool = require("tedious-connection-pool2" /* STRINGS.PACKAGE_POOL */);
203
205
  const config = this.getPoolConfig("mssql" /* STRINGS.MODULE_NAME */, password);
204
206
  const poolConfig = (0, types_1.isPlainObject)(item.usePool) ? item.usePool : {};
205
207
  if (config) {
@@ -217,7 +219,7 @@ function setCredential(item) {
217
219
  poolConfig.acquireTimeout ?? (poolConfig.acquireTimeout = queue_idle);
218
220
  }
219
221
  }
220
- new MSSQLPool(new Pool(poolConfig, credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
222
+ new MSSQLPool(new TediousPool(poolConfig, credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
221
223
  }
222
224
  else {
223
225
  pool.add(item);
@@ -234,7 +236,6 @@ async function executeBatchQuery(batch, options = '', outResult) {
234
236
  if (length === 0) {
235
237
  return [];
236
238
  }
237
- const db = require("tedious" /* STRINGS.PACKAGE_NAME */);
238
239
  let parallel, connectOnce, errorQuery, sessionKey, outCacheMiss;
239
240
  if ((0, types_1.isPlainObject)(options)) {
240
241
  ({ parallel, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
@@ -300,7 +301,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
300
301
  }
301
302
  if (!client) {
302
303
  clients.push(client = await new Promise((resolve, reject) => {
303
- const sql = new db.Connection(mssqlCredential || credential);
304
+ const sql = new tedious.Connection(mssqlCredential || credential);
304
305
  sql.connect(err => {
305
306
  if (err) {
306
307
  reject(err);
@@ -385,15 +386,15 @@ async function executeBatchQuery(batch, options = '', outResult) {
385
386
  const processRow = typeof streamRow === 'function' && streamRow;
386
387
  const rows = [];
387
388
  let recordset = 1, resume, output;
388
- const request = new db.Request(query, () => {
389
+ const request = new tedious.Request(query, () => {
389
390
  if (error && this.handleFail(error, item, { errorQuery, commandType })) {
390
391
  reject(error);
391
392
  }
392
393
  else {
393
394
  this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
394
395
  if (output) {
395
- output['__recordset__'] = 0;
396
- output['__returnvalue__'] = true;
396
+ output.__recordset__ = 0;
397
+ output.__returnvalue__ = true;
397
398
  rows.push([output]);
398
399
  }
399
400
  resolve(!error ? this.setQueryResult(source, credential, queryString, rows, cacheValue) : rows);
@@ -404,9 +405,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
404
405
  if (isOutputParameters(params)) {
405
406
  ({ input: params, output: paramsOutput } = params);
406
407
  }
407
- convertParameters.call(request, db.TYPES, params, false);
408
+ convertParameters.call(request, tedious.TYPES, params, false);
408
409
  if (paramsOutput) {
409
- convertParameters.call(request, db.TYPES, paramsOutput, true);
410
+ convertParameters.call(request, tedious.TYPES, paramsOutput, true);
410
411
  }
411
412
  }
412
413
  request
@@ -420,7 +421,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
420
421
  try {
421
422
  const items = JSON.parse(data.value);
422
423
  if ((0, types_1.isArray)(items)) {
423
- items.forEach((col) => col['__recordset__'] = recordset);
424
+ items.forEach((col) => col.__recordset__ = recordset);
424
425
  rows.push(...items);
425
426
  }
426
427
  }
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "@pi-r/mssql",
3
- "version": "0.3.0",
4
- "description": "MSSQL client driver for E-mc.",
5
- "main": "client/index.js",
6
- "types": "client/index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "https://github.com/anpham6/pi-r.git",
13
- "directory": "src/db/mssql"
14
- },
15
- "keywords": [
16
- "squared",
17
- "e-mc",
18
- "squared-functions"
19
- ],
20
- "author": "An Pham <anpham6@gmail.com>",
21
- "license": "MIT",
22
- "homepage": "https://github.com/anpham6/pi-r#readme",
23
- "dependencies": {
24
- "@e-mc/db": "^0.5.3",
25
- "@e-mc/types": "^0.5.3",
26
- "tedious": "^16.1.0",
27
- "tedious-connection-pool": "^1.0.5"
28
- }
29
- }
1
+ {
2
+ "name": "@pi-r/mssql",
3
+ "version": "0.4.0",
4
+ "description": "MSSQL client driver for E-mc.",
5
+ "main": "client/index.js",
6
+ "types": "client/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/anpham6/pi-r.git",
13
+ "directory": "src/db/mssql"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "e-mc",
18
+ "squared-functions"
19
+ ],
20
+ "author": "An Pham <anpham6@gmail.com>",
21
+ "license": "MIT",
22
+ "homepage": "https://github.com/anpham6/pi-r#readme",
23
+ "dependencies": {
24
+ "@e-mc/db": "^0.6.0",
25
+ "@e-mc/types": "^0.6.0",
26
+ "tedious": "^16.4.0",
27
+ "tedious-connection-pool2": "^2.1.0"
28
+ }
29
+ }
package/types/index.d.ts CHANGED
@@ -1,27 +1,27 @@
1
- import type { DbDataSource } from '@e-mc/types/lib/squared';
2
-
3
- import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
4
-
5
- import type { ConnectionConfig, ParameterOptions, TediousType, TediousTypes } from 'tedious';
6
- import type { PoolConfig } from 'tedious-connection-pool';
7
-
8
- export interface MSSQLDataSource extends DbDataSource<string, unknown, unknown, string | MSSQLCredential, string | PoolConfig>, ExecuteAction<MSSQLRequestParameters | MSSQLRequestWithOutputParameters> {
9
- source: "mssql";
10
- storedProc?: boolean;
11
- }
12
-
13
- export interface MSSQLCredential extends ServerAuth, ConnectionConfig {}
14
-
15
- export interface MSSQLRequestWithOutputParameters {
16
- input?: MSSQLRequestParameters;
17
- output?: MSSQLRequestParameters;
18
- }
19
-
20
- export interface MSSQLRequestParameterValue {
21
- name?: string;
22
- value?: unknown;
23
- type?: keyof TediousTypes | TediousType;
24
- options?: ParameterOptions;
25
- }
26
-
1
+ import type { DbDataSource } from '@e-mc/types/lib/squared';
2
+
3
+ import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
4
+
5
+ import type { ConnectionConfig, ParameterOptions, TediousType, TediousTypes } from 'tedious';
6
+ import type { PoolConfig } from 'tedious-connection-pool';
7
+
8
+ export interface MSSQLDataSource extends DbDataSource<string, unknown, unknown, string | MSSQLCredential, string | PoolConfig>, ExecuteAction<MSSQLRequestParameters | MSSQLRequestWithOutputParameters> {
9
+ source: "mssql";
10
+ storedProc?: boolean;
11
+ }
12
+
13
+ export interface MSSQLCredential extends ServerAuth, ConnectionConfig {}
14
+
15
+ export interface MSSQLRequestWithOutputParameters {
16
+ input?: MSSQLRequestParameters;
17
+ output?: MSSQLRequestParameters;
18
+ }
19
+
20
+ export interface MSSQLRequestParameterValue {
21
+ name?: string;
22
+ value?: unknown;
23
+ type?: keyof TediousTypes | TediousType;
24
+ options?: ParameterOptions;
25
+ }
26
+
27
27
  export type MSSQLRequestParameters = Null<MSSQLRequestParameterValue[] | ObjectMap<Omit<MSSQLRequestParameterValue, "name">>>;