mssql-cr-layer 3.0.14 → 3.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +15 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mssql-cr-layer",
3
- "version": "3.0.14",
3
+ "version": "3.0.15",
4
4
  "description": "A MS SQL Server interface layer for common requests",
5
5
  "repository": "andrglo/mssql-cr-layer",
6
6
  "author": {
package/src/index.js CHANGED
@@ -96,16 +96,8 @@ MssqlCrLayer.prototype.connect = function() {
96
96
  * @returns {Promise} With the return of the last promise executed
97
97
  */
98
98
  MssqlCrLayer.prototype.transaction = function(fn, options) {
99
- options = options || {}
100
- const isolationLevel = options.ISOLATION_LEVEL || this.ISOLATION_LEVEL
101
- return this.connect().then(function(connection) {
102
- const transaction = new mssql.Transaction(connection)
103
- rolledBack.set(transaction, false)
104
- transaction.on('rollback', function() {
105
- rolledBack.set(transaction, true)
106
- })
107
- return transaction
108
- .begin(mssql.ISOLATION_LEVEL[isolationLevel])
99
+ return this.beginTransaction(options).then(function(transaction) {
100
+ return Promise.resolve()
109
101
  .then(function() {
110
102
  return fn(transaction)
111
103
  })
@@ -293,18 +285,23 @@ MssqlCrLayer.prototype.query = function(statement, params, options) {
293
285
  // so it is no longer this statement's to unprepare on - another
294
286
  // request may be using it, and the sp_unprepare would collide
295
287
  // with it ("Requests can only be made in the LoggedIn state").
296
- if (transaction && rolledBack.get(transaction)) {
288
+ // `_aborted` is node-mssql's own flag, for a transaction this
289
+ // layer did not create.
290
+ if (
291
+ transaction &&
292
+ (rolledBack.get(transaction) || transaction._aborted === true)
293
+ ) {
297
294
  throw error
298
295
  }
299
296
  // Never let a failed unprepare replace the statement's own error
300
- return ps.unprepare().then(
301
- function() {
302
- throw error
303
- },
304
- function() {
297
+ return ps
298
+ .unprepare()
299
+ .catch(function(unprepareError) {
300
+ debug('unprepare failed %s %O', statement, unprepareError)
301
+ })
302
+ .then(function() {
305
303
  throw error
306
- }
307
- )
304
+ })
308
305
  })
309
306
  })
310
307
  .catch(err => {