Skip to content

Commit cd63bea

Browse files
Merge pull request #1525 from tediousjs/dependabot/npm_and_yarn/tediousjs/connection-string-0.5.0
2 parents 8c018d4 + 71357e2 commit cd63bea

File tree

3 files changed

+21
-38
lines changed

3 files changed

+21
-38
lines changed

lib/msnodesqlv8/connection-pool.js

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,31 @@ const { IDS, INCREMENT } = require('../utils')
77
const shared = require('../shared')
88
const ConnectionError = require('../error/connection-error')
99
const { platform } = require('os')
10+
const { buildConnectionString } = require('@tediousjs/connection-string')
1011

1112
const CONNECTION_DRIVER = ['darwin', 'linux'].includes(platform()) ? 'ODBC Driver 17 for SQL Server' : 'SQL Server Native Client 11.0'
12-
const CONNECTION_STRING_PORT = `Driver=${CONNECTION_DRIVER};Server=#{server},#{port};Database=#{database};Uid=#{user};Pwd=#{password};Trusted_Connection=#{trusted};Encrypt=#{encrypt};`
13-
const CONNECTION_STRING_NAMED_INSTANCE = `Driver=${CONNECTION_DRIVER};Server=#{server}\\#{instance};Database=#{database};Uid=#{user};Pwd=#{password};Trusted_Connection=#{trusted};Encrypt=#{encrypt};`
1413

1514
class ConnectionPool extends BaseConnectionPool {
1615
_poolCreate () {
1716
return new shared.Promise((resolve, reject) => {
18-
let defaultConnectionString = CONNECTION_STRING_PORT
19-
20-
if (this.config.options.instanceName != null) {
21-
defaultConnectionString = CONNECTION_STRING_NAMED_INSTANCE
22-
}
23-
2417
this.config.requestTimeout = this.config.requestTimeout ?? this.config.timeout ?? 15000
2518

2619
const cfg = {
27-
conn_str: this.config.connectionString || defaultConnectionString,
20+
conn_str: this.config.connectionString,
2821
conn_timeout: (this.config.connectionTimeout ?? this.config.timeout ?? 15000) / 1000
2922
}
3023

31-
cfg.conn_str = cfg.conn_str.replace(/#{([^}]*)}/g, (p) => {
32-
const key = p.substr(2, p.length - 3)
33-
34-
switch (key) {
35-
case 'instance':
36-
return this.config.options.instanceName
37-
case 'trusted':
38-
return this.config.options.trustedConnection ? 'Yes' : 'No'
39-
case 'encrypt':
40-
return this.config.options.encrypt ? 'Yes' : 'No'
41-
default: {
42-
let val = this.config[key] || ''
43-
// quote strings that contain '{' or '}' but not ones that start and end with them (assume they are already quoted)
44-
if (val && typeof val === 'string' && !(val.startsWith('{') && val.endsWith('}')) && (val.indexOf('{') !== -1 || val.indexOf('}') !== -1)) {
45-
// quote values in `{}` and escape any existing `}` chars
46-
val = `{${val.replace(/}/g, '}}')}}`
47-
}
48-
return val
49-
}
50-
}
51-
})
24+
if (!this.config.connectionString) {
25+
cfg.conn_str = buildConnectionString({
26+
Driver: CONNECTION_DRIVER,
27+
Server: this.config.options.instanceName ? `${this.config.server}\\${this.config.instanceName}` : `${this.config.server},${this.config.port}`,
28+
Database: this.config.database,
29+
Uid: this.config.user,
30+
Pwd: this.config.password,
31+
Trusted_Connection: !!this.config.options.trustedConnection,
32+
Encrypt: !!this.config.options.encrypt
33+
})
34+
}
5235

5336
const connedtionId = INCREMENT.Connection++
5437
debug('pool(%d): connection #%d created', IDS.get(this), connedtionId)

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"repository": "github:tediousjs/node-mssql",
2727
"license": "MIT",
2828
"dependencies": {
29-
"@tediousjs/connection-string": "^0.4.1",
29+
"@tediousjs/connection-string": "^0.5.0",
3030
"commander": "^11.0.0",
3131
"debug": "^4.3.3",
3232
"rfdc": "^1.3.0",

0 commit comments

Comments
 (0)