@pi-r/mssql 0.2.11 → 0.2.13
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 +6 -6
- package/README.md +4 -6
- package/client/index.d.ts +6 -6
- package/client/pool.js +63 -0
- package/package.json +29 -29
- package/types/index.d.ts +28 -28
- package/types/pool.d.ts +66 -68
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
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
package/client/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IDbSourceClient } from '@e-mc/db/types';
|
|
2
|
-
|
|
3
|
-
import type { MSSQLDataSource } from '../types';
|
|
4
|
-
|
|
5
|
-
declare const MSSQL: IDbSourceClient<MSSQLDataSource>;
|
|
6
|
-
|
|
1
|
+
import type { IDbSourceClient } from '@e-mc/db/types';
|
|
2
|
+
|
|
3
|
+
import type { MSSQLDataSource } from '../types';
|
|
4
|
+
|
|
5
|
+
declare const MSSQL: IDbSourceClient<MSSQLDataSource>;
|
|
6
|
+
|
|
7
7
|
export = MSSQL;
|
package/client/pool.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
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/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/mssql",
|
|
3
|
-
"version": "0.2.
|
|
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": "git+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.
|
|
25
|
-
"@e-mc/types": "^0.5.
|
|
26
|
-
"tedious": "^16.7.1",
|
|
27
|
-
"tedious-connection-pool2": "^2.1.0"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/mssql",
|
|
3
|
+
"version": "0.2.13",
|
|
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": "git+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.18",
|
|
25
|
+
"@e-mc/types": "^0.5.18",
|
|
26
|
+
"tedious": "^16.7.1",
|
|
27
|
+
"tedious-connection-pool2": "^2.1.0"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
2
|
-
|
|
3
|
-
import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import type { ConnectionConfig, ParameterOptions, TediousType, TediousTypes } from 'tedious';
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
import type { PoolConfig } from 'tedious-connection-pool';
|
|
9
|
-
|
|
10
|
-
export interface MSSQLDataSource extends DbDataSource<string, unknown, unknown, string | MSSQLCredential, string | PoolConfig>, ExecuteAction<MSSQLRequestParameters | MSSQLRequestWithOutputParameters> {
|
|
11
|
-
source: "mssql";
|
|
12
|
-
storedProc?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface MSSQLCredential extends ServerAuth, ConnectionConfig {}
|
|
16
|
-
|
|
17
|
-
export interface MSSQLRequestWithOutputParameters {
|
|
18
|
-
input?: MSSQLRequestParameters;
|
|
19
|
-
output?: MSSQLRequestParameters;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface MSSQLRequestParameterValue {
|
|
23
|
-
name?: string;
|
|
24
|
-
value?: unknown;
|
|
25
|
-
type?: keyof TediousTypes | TediousType;
|
|
26
|
-
options?: ParameterOptions;
|
|
27
|
-
}
|
|
28
|
-
|
|
1
|
+
import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
2
|
+
|
|
3
|
+
import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import type { ConnectionConfig, ParameterOptions, TediousType, TediousTypes } from 'tedious';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import type { PoolConfig } from 'tedious-connection-pool';
|
|
9
|
+
|
|
10
|
+
export interface MSSQLDataSource extends DbDataSource<string, unknown, unknown, string | MSSQLCredential, string | PoolConfig>, ExecuteAction<MSSQLRequestParameters | MSSQLRequestWithOutputParameters> {
|
|
11
|
+
source: "mssql";
|
|
12
|
+
storedProc?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface MSSQLCredential extends ServerAuth, ConnectionConfig {}
|
|
16
|
+
|
|
17
|
+
export interface MSSQLRequestWithOutputParameters {
|
|
18
|
+
input?: MSSQLRequestParameters;
|
|
19
|
+
output?: MSSQLRequestParameters;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface MSSQLRequestParameterValue {
|
|
23
|
+
name?: string;
|
|
24
|
+
value?: unknown;
|
|
25
|
+
type?: keyof TediousTypes | TediousType;
|
|
26
|
+
options?: ParameterOptions;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
29
|
export type MSSQLRequestParameters = Null<MSSQLRequestParameterValue[] | ObjectMap<Omit<MSSQLRequestParameterValue, "name">>>;
|
package/types/pool.d.ts
CHANGED
|
@@ -1,69 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
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
|
+
|
|
69
67
|
export = Pool;
|