Skip to content

Commit

Permalink
Support patched MSSQL lib (#2861)
Browse files Browse the repository at this point in the history
* PATCH Support patched MSSQL lib

* Add code coverage ignores to mssql monkey-patching

* Fix compatibility description
  • Loading branch information
dhensby authored and kibertoad committed Nov 23, 2018
1 parent 461868b commit b56ff04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"lint-staged": "^8.0.4",
"mocha": "^5.2.0",
"mock-fs": "^4.7.0",
"mssql": "4.1.0",
"mssql": "^5.0.0-alpha.1",
"mysql": "^2.16.0",
"mysql2": "^1.6.4",
"nyc": "^13.0.1",
Expand Down
24 changes: 15 additions & 9 deletions src/dialects/mssql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,31 @@ assign(Client_MSSQL.prototype, {

// TODO: remove mssql implementation all together and use tedious directly

/* istanbul ignore next */
const mssqlVersion = require('mssql/package.json').version;
if (mssqlVersion !== '4.1.0') {
throw new Error(
'This knex version does not support any other mssql version except 4.1.0 ' +
'(knex patches bug in its implementation)'
);
/* istanbul ignore next */
if (mssqlVersion === '4.1.0') {
mssqlTedious.ConnectionPool.prototype.release = release;
mssqlTedious.ConnectionPool.prototype._poolCreate = _poolCreate;
} else {
const [major] = mssqlVersion.split('.');
// if version is not ^5.0.0
if (major < 5) {
throw new Error(
'This knex version only supports mssql driver versions 4.1.0 and 5.0.0+'
);
}
}

mssqlTedious.ConnectionPool.prototype.release = release;
mssqlTedious.ConnectionPool.prototype._poolCreate = _poolCreate;

/* istanbul ignore next */
// in some rare situations release is called when stream is interrupted, but
// after pool is already destroyed
function release(connection) {
if (this.pool) {
this.pool.release(connection);
}
}

/* istanbul ignore next */
function _poolCreate() {
// implementation is copy-pasted from https://github.com/tediousjs/node-mssql/pull/614
return new base.Promise((resolve, reject) => {
Expand Down

0 comments on commit b56ff04

Please sign in to comment.