@@ -8,6 +8,61 @@ const shared = require('../shared')
8
8
const ConnectionError = require ( '../error/connection-error' )
9
9
10
10
class ConnectionPool extends BaseConnectionPool {
11
+ _config ( ) {
12
+ const cfg = {
13
+ server : this . config . server ,
14
+ options : Object . assign ( {
15
+ encrypt : typeof this . config . encrypt === 'boolean' ? this . config . encrypt : true ,
16
+ trustServerCertificate : typeof this . config . trustServerCertificate === 'boolean' ? this . config . trustServerCertificate : false
17
+ } , this . config . options ) ,
18
+ authentication : Object . assign ( {
19
+ type : this . config . domain !== undefined ? 'ntlm' : this . config . authentication_type !== undefined ? this . config . authentication_type : 'default' ,
20
+ options : Object . entries ( {
21
+ userName : this . config . user ,
22
+ password : this . config . password ,
23
+ domain : this . config . domain ,
24
+ clientId : this . config . clientId ,
25
+ clientSecret : this . config . clientSecret ,
26
+ tenantId : this . config . tenantId ,
27
+ token : this . config . token ,
28
+ msiEndpoint : this . config . msiEndpoint ,
29
+ msiSecret : this . config . msiSecret
30
+ } ) . reduce ( ( acc , [ key , val ] ) => {
31
+ if ( typeof val !== 'undefined' ) {
32
+ return { ...acc , [ key ] : val }
33
+ }
34
+ return acc
35
+ } , { } )
36
+ } , this . config . authentication )
37
+ }
38
+
39
+ cfg . options . database = cfg . options . database || this . config . database
40
+ cfg . options . port = cfg . options . port || this . config . port
41
+ cfg . options . connectTimeout = cfg . options . connectTimeout ?? this . config . connectionTimeout ?? this . config . timeout ?? 15000
42
+ cfg . options . requestTimeout = cfg . options . requestTimeout ?? this . config . requestTimeout ?? this . config . timeout ?? 15000
43
+ cfg . options . tdsVersion = cfg . options . tdsVersion || '7_4'
44
+ cfg . options . rowCollectionOnDone = cfg . options . rowCollectionOnDone || false
45
+ cfg . options . rowCollectionOnRequestCompletion = cfg . options . rowCollectionOnRequestCompletion || false
46
+ cfg . options . useColumnNames = cfg . options . useColumnNames || false
47
+ cfg . options . appName = cfg . options . appName || 'node-mssql'
48
+
49
+ // tedious always connect via tcp when port is specified
50
+ if ( cfg . options . instanceName ) delete cfg . options . port
51
+
52
+ if ( isNaN ( cfg . options . requestTimeout ) ) cfg . options . requestTimeout = 15000
53
+ if ( cfg . options . requestTimeout === Infinity || cfg . options . requestTimeout < 0 ) cfg . options . requestTimeout = 0
54
+
55
+ if ( ! cfg . options . debug && this . config . debug ) {
56
+ cfg . options . debug = {
57
+ packet : true ,
58
+ token : true ,
59
+ data : true ,
60
+ payload : true
61
+ }
62
+ }
63
+ return cfg
64
+ }
65
+
11
66
_poolCreate ( ) {
12
67
return new shared . Promise ( ( resolve , reject ) => {
13
68
const resolveOnce = ( v ) => {
@@ -18,49 +73,9 @@ class ConnectionPool extends BaseConnectionPool {
18
73
reject ( e )
19
74
resolve = reject = ( ) => { }
20
75
}
21
- const cfg = {
22
- server : this . config . server ,
23
- options : Object . assign ( {
24
- encrypt : typeof this . config . encrypt === 'boolean' ? this . config . encrypt : true ,
25
- trustServerCertificate : typeof this . config . trustServerCertificate === 'boolean' ? this . config . trustServerCertificate : false
26
- } , this . config . options ) ,
27
- authentication : Object . assign ( {
28
- type : this . config . domain !== undefined ? 'ntlm' : 'default' ,
29
- options : {
30
- userName : this . config . user ,
31
- password : this . config . password ,
32
- domain : this . config . domain
33
- }
34
- } , this . config . authentication )
35
- }
36
-
37
- cfg . options . database = cfg . options . database || this . config . database
38
- cfg . options . port = cfg . options . port || this . config . port
39
- cfg . options . connectTimeout = cfg . options . connectTimeout ?? this . config . connectionTimeout ?? this . config . timeout ?? 15000
40
- cfg . options . requestTimeout = cfg . options . requestTimeout ?? this . config . requestTimeout ?? this . config . timeout ?? 15000
41
- cfg . options . tdsVersion = cfg . options . tdsVersion || '7_4'
42
- cfg . options . rowCollectionOnDone = cfg . options . rowCollectionOnDone || false
43
- cfg . options . rowCollectionOnRequestCompletion = cfg . options . rowCollectionOnRequestCompletion || false
44
- cfg . options . useColumnNames = cfg . options . useColumnNames || false
45
- cfg . options . appName = cfg . options . appName || 'node-mssql'
46
-
47
- // tedious always connect via tcp when port is specified
48
- if ( cfg . options . instanceName ) delete cfg . options . port
49
-
50
- if ( isNaN ( cfg . options . requestTimeout ) ) cfg . options . requestTimeout = 15000
51
- if ( cfg . options . requestTimeout === Infinity || cfg . options . requestTimeout < 0 ) cfg . options . requestTimeout = 0
52
-
53
- if ( ! cfg . options . debug && this . config . debug ) {
54
- cfg . options . debug = {
55
- packet : true ,
56
- token : true ,
57
- data : true ,
58
- payload : true
59
- }
60
- }
61
76
let tedious
62
77
try {
63
- tedious = new tds . Connection ( cfg )
78
+ tedious = new tds . Connection ( this . _config ( ) )
64
79
} catch ( err ) {
65
80
rejectOnce ( err )
66
81
return
0 commit comments