Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): bump @tediousjs/connection-string from 0.4.4 to 0.5.0 #1525

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 13 additions & 30 deletions lib/msnodesqlv8/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,31 @@ const { IDS, INCREMENT } = require('../utils')
const shared = require('../shared')
const ConnectionError = require('../error/connection-error')
const { platform } = require('os')
const { buildConnectionString } = require('@tediousjs/connection-string')

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

class ConnectionPool extends BaseConnectionPool {
_poolCreate () {
return new shared.Promise((resolve, reject) => {
let defaultConnectionString = CONNECTION_STRING_PORT

if (this.config.options.instanceName != null) {
defaultConnectionString = CONNECTION_STRING_NAMED_INSTANCE
}

this.config.requestTimeout = this.config.requestTimeout ?? this.config.timeout ?? 15000

const cfg = {
conn_str: this.config.connectionString || defaultConnectionString,
conn_str: this.config.connectionString,
conn_timeout: (this.config.connectionTimeout ?? this.config.timeout ?? 15000) / 1000
}

cfg.conn_str = cfg.conn_str.replace(/#{([^}]*)}/g, (p) => {
const key = p.substr(2, p.length - 3)

switch (key) {
case 'instance':
return this.config.options.instanceName
case 'trusted':
return this.config.options.trustedConnection ? 'Yes' : 'No'
case 'encrypt':
return this.config.options.encrypt ? 'Yes' : 'No'
default: {
let val = this.config[key] || ''
// quote strings that contain '{' or '}' but not ones that start and end with them (assume they are already quoted)
if (val && typeof val === 'string' && !(val.startsWith('{') && val.endsWith('}')) && (val.indexOf('{') !== -1 || val.indexOf('}') !== -1)) {
// quote values in `{}` and escape any existing `}` chars
val = `{${val.replace(/}/g, '}}')}}`
}
return val
}
}
})
if (!this.config.connectionString) {
cfg.conn_str = buildConnectionString({
Driver: CONNECTION_DRIVER,
Server: this.config.options.instanceName ? `${this.config.server}\\${this.config.instanceName}` : `${this.config.server},${this.config.port}`,
Database: this.config.database,
Uid: this.config.user,
Pwd: this.config.password,
Trusted_Connection: !!this.config.options.trustedConnection,
Encrypt: !!this.config.options.encrypt
})
}

const connedtionId = INCREMENT.Connection++
debug('pool(%d): connection #%d created', IDS.get(this), connedtionId)
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"repository": "github:tediousjs/node-mssql",
"license": "MIT",
"dependencies": {
"@tediousjs/connection-string": "^0.4.1",
"@tediousjs/connection-string": "^0.5.0",
"commander": "^11.0.0",
"debug": "^4.3.3",
"rfdc": "^1.3.0",
Expand Down