@pi-r/mssql 0.6.0 → 0.6.2

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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ### @pi-r/mssql
2
2
 
3
+ https://e-mc.readthedocs.io/en/latest/db/mssql.html
4
+
3
5
  ### LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -111,6 +111,10 @@ function convertType(sql, type, value, options) {
111
111
  }
112
112
  }
113
113
  function getPoolKey(credential) {
114
+ const auth = credential.authentication?.options;
115
+ if (!credential.server || !(auth?.userName && auth.password)) {
116
+ return;
117
+ }
114
118
  const tls = credential.options?.cryptoCredentialsDetails;
115
119
  if (tls) {
116
120
  if (!(0, types_1.isObject)(tls)) {
@@ -118,16 +122,21 @@ function getPoolKey(credential) {
118
122
  }
119
123
  else if (tls.ca || tls.cert || tls.key) {
120
124
  credential = { ...credential };
125
+ if ('uuidKey' in credential) {
126
+ delete credential.uuidKey;
127
+ }
121
128
  credential.options = { ...credential.options };
122
129
  delete credential.options.cryptoCredentialsDetails;
123
130
  return JSON.stringify(credential) + '_tls';
124
131
  }
125
132
  }
133
+ if ('uuidKey' in credential) {
134
+ credential = { ...credential };
135
+ delete credential.uuidKey;
136
+ }
126
137
  return JSON.stringify(credential);
127
138
  }
128
- function isOutputParameters(params) {
129
- return (0, types_1.isPlainObject)(params) && Object.keys(params).length === 2 && 'input' in params && 'output' in params;
130
- }
139
+ const isOutputParameters = (params) => (0, types_1.isPlainObject)(params) && Object.keys(params).length === 2 && 'input' in params && 'output' in params;
131
140
  function setCredential(item) {
132
141
  let credential = this.getCredential(item), hostname, username, password, port, database;
133
142
  if (credential) {
@@ -195,18 +204,19 @@ function setCredential(item) {
195
204
  }
196
205
  let pool;
197
206
  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);
207
+ if ((0, types_1.isString)(usePool)) {
208
+ if (username = authOptions.userName) {
209
+ [password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
210
+ if (pool) {
211
+ pool.add(item, password);
212
+ return;
213
+ }
214
+ }
215
+ if (!password) {
216
+ item.usePool = '';
202
217
  return;
203
218
  }
204
219
  }
205
- const poolKey = getPoolKey(credential);
206
- if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
207
- pool.add(item);
208
- return;
209
- }
210
220
  const config = this.getPoolConfig("mssql" /* STRINGS.MODULE_NAME */, password);
211
221
  const poolConfig = (0, types_1.isPlainObject)(item.usePool) ? item.usePool : {};
212
222
  if (config) {
@@ -224,6 +234,11 @@ function setCredential(item) {
224
234
  poolConfig.acquireTimeout ?? (poolConfig.acquireTimeout = queue_idle);
225
235
  }
226
236
  }
237
+ const poolKey = getPoolKey(credential);
238
+ if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
239
+ pool.add(item);
240
+ return;
241
+ }
227
242
  new MSSQLPool(new TediousPool(poolConfig, credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
228
243
  }
229
244
  exports.setCredential = setCredential;
@@ -346,10 +361,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
346
361
  }
347
362
  item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
348
363
  const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mssql" /* STRINGS.MODULE_NAME */, 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
349
- const renewCache = ignoreCache === 0;
350
- const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
364
+ const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
351
365
  let params = item.params, queryString = '';
352
- if ((caching && ignoreCache !== true || ignoreCache === false || ignoreCache === 1 || renewCache) && !streamRow) {
366
+ if (caching && ignoreCache !== true && !streamRow) {
353
367
  queryString = Db.asString(query, true) + '_' + Db.asString(params, true);
354
368
  if (ignoreCache !== 1) {
355
369
  const result = this.getQueryResult(source, credential, queryString, cacheValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mssql",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
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.8.0",
25
- "@e-mc/types": "^0.8.0",
24
+ "@e-mc/db": "^0.8.2",
25
+ "@e-mc/types": "^0.8.2",
26
26
  "tedious": "^16.6.1",
27
27
  "tedious-connection-pool2": "^2.1.0"
28
28
  }
package/types/index.d.ts CHANGED
@@ -24,4 +24,4 @@ export interface MSSQLRequestParameterValue {
24
24
  options?: ParameterOptions;
25
25
  }
26
26
 
27
- export type MSSQLRequestParameters = Null<MSSQLRequestParameterValue[] | ObjectMap<Omit<MSSQLRequestParameterValue, "name">>>;
27
+ export type MSSQLRequestParameters = MSSQLRequestParameterValue[] | Record<string, Omit<MSSQLRequestParameterValue, "name">> | null;