From 71434be646067cd91e6e99e8556993619630b5e6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Aug 2023 21:10:33 +0000 Subject: [PATCH 1/2] chore(deps): bump @tediousjs/connection-string from 0.4.4 to 0.5.0 Bumps [@tediousjs/connection-string](https://github.com/tediousjs/connection-string) from 0.4.4 to 0.5.0. - [Release notes](https://github.com/tediousjs/connection-string/releases) - [Changelog](https://github.com/tediousjs/connection-string/blob/master/CHANGELOG.md) - [Commits](https://github.com/tediousjs/connection-string/compare/v0.4.4...v0.5.0) --- updated-dependencies: - dependency-name: "@tediousjs/connection-string" dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index f649113a..edd47ebd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "9.1.1", "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", @@ -1798,9 +1798,9 @@ } }, "node_modules/@tediousjs/connection-string": { - "version": "0.4.4", - "resolved": "https://registry.npmjs.org/@tediousjs/connection-string/-/connection-string-0.4.4.tgz", - "integrity": "sha512-Qssn7gmOILmqD0zkfA09YyFd52UajWYkLTTSi4Dx/XZaUuVcx4W4guv2rAVc5mm8wYRdonmG/HfFH3PS6izXAg==" + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/@tediousjs/connection-string/-/connection-string-0.5.0.tgz", + "integrity": "sha512-7qSgZbincDDDFyRweCIEvZULFAw5iz/DeunhvuxpL31nfntX3P4Yd4HkHBRg9H8CdqY1e5WFN1PZIz/REL9MVQ==" }, "node_modules/@tootallnate/once": { "version": "2.0.0", @@ -12806,9 +12806,9 @@ } }, "@tediousjs/connection-string": { - "version": "0.4.4", - "resolved": "https://registry.npmjs.org/@tediousjs/connection-string/-/connection-string-0.4.4.tgz", - "integrity": "sha512-Qssn7gmOILmqD0zkfA09YyFd52UajWYkLTTSi4Dx/XZaUuVcx4W4guv2rAVc5mm8wYRdonmG/HfFH3PS6izXAg==" + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/@tediousjs/connection-string/-/connection-string-0.5.0.tgz", + "integrity": "sha512-7qSgZbincDDDFyRweCIEvZULFAw5iz/DeunhvuxpL31nfntX3P4Yd4HkHBRg9H8CdqY1e5WFN1PZIz/REL9MVQ==" }, "@tootallnate/once": { "version": "2.0.0", diff --git a/package.json b/package.json index 56966449..5f046ed7 100644 --- a/package.json +++ b/package.json @@ -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", From 71357e2a45927695c3c3ebb7ed4a42d868976c75 Mon Sep 17 00:00:00 2001 From: Dan Hensby Date: Tue, 15 Aug 2023 22:09:30 +0200 Subject: [PATCH 2/2] feat: use @tediousjs/connection-string to build msnodesqlv8 connection string --- lib/msnodesqlv8/connection-pool.js | 43 +++++++++--------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/lib/msnodesqlv8/connection-pool.js b/lib/msnodesqlv8/connection-pool.js index 217781f4..7ffa7012 100644 --- a/lib/msnodesqlv8/connection-pool.js +++ b/lib/msnodesqlv8/connection-pool.js @@ -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)