@pi-r/mssql 0.5.0 → 0.5.3
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 +1 -1
- package/README.md +4 -2
- package/client/index.d.ts +2 -2
- package/client/index.js +11 -11
- package/package.json +5 -5
- package/types/index.d.ts +2 -0
- package/types/pool.d.ts +69 -0
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Haruhi Suzumiya
|
|
2
2
|
|
|
3
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
4
|
|
package/README.md
CHANGED
package/client/index.d.ts
CHANGED
package/client/index.js
CHANGED
|
@@ -172,7 +172,7 @@ function setCredential(item) {
|
|
|
172
172
|
errors.push('authentication.options.password');
|
|
173
173
|
}
|
|
174
174
|
if (errors.length) {
|
|
175
|
-
throw (0, types_1.errorMessage)("mssql"
|
|
175
|
+
throw (0, types_1.errorMessage)("mssql", 'Not defined - ' + errors.join(' | '));
|
|
176
176
|
}
|
|
177
177
|
const options = credential.options;
|
|
178
178
|
if (options) {
|
|
@@ -202,7 +202,7 @@ function setCredential(item) {
|
|
|
202
202
|
}
|
|
203
203
|
const poolKey = getPoolKey(credential);
|
|
204
204
|
if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
|
|
205
|
-
const config = this.getPoolConfig("mssql"
|
|
205
|
+
const config = this.getPoolConfig("mssql", password);
|
|
206
206
|
const poolConfig = (0, types_1.isPlainObject)(item.usePool) ? item.usePool : {};
|
|
207
207
|
if (config) {
|
|
208
208
|
const { min, max, idle, queue_idle } = config;
|
|
@@ -256,17 +256,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
256
256
|
if (!parallel) {
|
|
257
257
|
outResult || (outResult = new Array(length));
|
|
258
258
|
}
|
|
259
|
-
const caching = this.hasCache("mssql"
|
|
259
|
+
const caching = this.hasCache("mssql", sessionKey);
|
|
260
260
|
const tasks = new Array(length);
|
|
261
261
|
const clients = [];
|
|
262
262
|
const pools = [];
|
|
263
263
|
let mssqlPool, mssqlClient, mssqlCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
|
|
264
264
|
const getConnection = async (item, credential) => {
|
|
265
|
-
item.transactionState = 64
|
|
265
|
+
item.transactionState = 64;
|
|
266
266
|
let client;
|
|
267
267
|
if (mssqlPool) {
|
|
268
268
|
pools.push(client = await mssqlPool.getConnection());
|
|
269
|
-
item.transactionState &= ~64
|
|
269
|
+
item.transactionState &= ~64;
|
|
270
270
|
return client;
|
|
271
271
|
}
|
|
272
272
|
const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
|
|
@@ -318,14 +318,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
318
318
|
}
|
|
319
319
|
mssqlCredential = credential;
|
|
320
320
|
}
|
|
321
|
-
item.transactionState &= ~64
|
|
321
|
+
item.transactionState &= ~64;
|
|
322
322
|
return client;
|
|
323
323
|
};
|
|
324
324
|
for (let i = 0; i < length; ++i) {
|
|
325
325
|
const item = batch[i];
|
|
326
326
|
const { source, query, ignoreCache } = item;
|
|
327
327
|
let credential = mssqlCredential || onceCredential, error;
|
|
328
|
-
if (!credential && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials"
|
|
328
|
+
if (!credential && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials")) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query"))) {
|
|
329
329
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
330
330
|
if (!parallel) {
|
|
331
331
|
tasks.length = 0;
|
|
@@ -341,8 +341,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
341
341
|
}
|
|
342
342
|
continue;
|
|
343
343
|
}
|
|
344
|
-
item.transactionState = 1
|
|
345
|
-
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mssql"
|
|
344
|
+
item.transactionState = 1;
|
|
345
|
+
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mssql", 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
|
|
346
346
|
const renewCache = ignoreCache === 0;
|
|
347
347
|
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
348
348
|
let params = item.params, queryString = '';
|
|
@@ -357,7 +357,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
357
357
|
else {
|
|
358
358
|
outResult[i] = result;
|
|
359
359
|
}
|
|
360
|
-
this.add(item, 4
|
|
360
|
+
this.add(item, 4 | 128);
|
|
361
361
|
continue;
|
|
362
362
|
}
|
|
363
363
|
if (!ignoreCache && outCacheMiss) {
|
|
@@ -391,7 +391,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
391
391
|
reject(error);
|
|
392
392
|
}
|
|
393
393
|
else {
|
|
394
|
-
this.add(item, 4
|
|
394
|
+
this.add(item, 4);
|
|
395
395
|
if (output) {
|
|
396
396
|
output.__recordset__ = 0;
|
|
397
397
|
output.__returnvalue__ = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mssql",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "MSSQL client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
13
|
"directory": "src/db/mssql"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -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.7.
|
|
25
|
-
"@e-mc/types": "^0.7.
|
|
26
|
-
"tedious": "^16.
|
|
24
|
+
"@e-mc/db": "^0.7.3",
|
|
25
|
+
"@e-mc/types": "^0.7.3",
|
|
26
|
+
"tedious": "^16.7.1",
|
|
27
27
|
"tedious-connection-pool2": "^2.1.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
|
2
2
|
|
|
3
3
|
import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
4
|
|
|
5
|
+
// @ts-ignore
|
|
5
6
|
import type { ConnectionConfig, ParameterOptions, TediousType, TediousTypes } from 'tedious';
|
|
7
|
+
// @ts-ignore
|
|
6
8
|
import type { PoolConfig } from 'tedious-connection-pool';
|
|
7
9
|
|
|
8
10
|
export interface MSSQLDataSource extends DbDataSource<string, unknown, unknown, string | MSSQLCredential, string | PoolConfig>, ExecuteAction<MSSQLRequestParameters | MSSQLRequestWithOutputParameters> {
|
package/types/pool.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/consistent-type-imports: "off" */
|
|
2
|
+
|
|
3
|
+
import type { Connection, ConnectionConfiguration } from 'tedious';
|
|
4
|
+
|
|
5
|
+
import type * as EventEmitter from 'events';
|
|
6
|
+
|
|
7
|
+
declare class Pool extends EventEmitter {
|
|
8
|
+
/**
|
|
9
|
+
* Connection Pool constructor
|
|
10
|
+
* @param poolConfig the pool configuration
|
|
11
|
+
* @param connectionConfig the connection configuration
|
|
12
|
+
*/
|
|
13
|
+
constructor(poolConfig: Pool.PoolConfig, connectionConfig: ConnectionConfiguration);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* acquires a connection from the pool
|
|
17
|
+
* @param callback invoked when the connection is retrieved and ready
|
|
18
|
+
*/
|
|
19
|
+
acquire(callback: (err: Error, connection: Pool.PooledConnection) => void): void;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* closes opened connections
|
|
23
|
+
*/
|
|
24
|
+
drain(): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare namespace Pool {
|
|
28
|
+
|
|
29
|
+
export class PooledConnection extends Connection {
|
|
30
|
+
/**
|
|
31
|
+
* If the connection is issued from a connection pool returns the connection to the pool.
|
|
32
|
+
*/
|
|
33
|
+
release(): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface PoolConfig {
|
|
37
|
+
/**
|
|
38
|
+
* Minimum concurrent connections
|
|
39
|
+
*/
|
|
40
|
+
min?: number | undefined;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Maximum concurrent connections
|
|
44
|
+
*/
|
|
45
|
+
max?: number | undefined;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Defines if logging is activated
|
|
49
|
+
*/
|
|
50
|
+
log?: boolean | undefined;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Idle timeout
|
|
54
|
+
*/
|
|
55
|
+
idleTimeout?: number | undefined;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Retry delay
|
|
59
|
+
*/
|
|
60
|
+
retryDelay?: number | undefined;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Acquire timeout
|
|
64
|
+
*/
|
|
65
|
+
acquireTimeout?: number | undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export = Pool;
|