Skip to content

Commit 53a0d69

Browse files
committed
fixed for old node
1 parent 268e1b5 commit 53a0d69

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,17 +453,19 @@ exports.db = function(config) {
453453
},
454454

455455
transaction: function (options, fn) {
456+
var self = this;
457+
456458
if (typeof options === 'function') {
457459
fn = options;
458460
options = undefined;
459461
}
460462

461-
return this.begin(options).then(() => {
463+
return this.begin(options).then(function() {
462464
return fn();
463-
}).then(r => {
464-
return this.commit().then(() => r);
465-
}, e => {
466-
return this.rollback().then(() => { throw e; });
465+
}).then(function(r) {
466+
return self.commit().then(function() { return r; });
467+
}, function(e) {
468+
return self.rollback().then(function() { throw e; });
467469
});
468470
},
469471

mssqlDriver.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,20 @@ module.exports = function() {
3737
},
3838

3939
commit: function() {
40+
var self = this;
41+
4042
debug('commit');
41-
return this.transaction.commit().then(() => {
42-
this.transaction = undefined;
43+
return this.transaction.commit().then(function() {
44+
self.transaction = undefined;
4345
});
4446
},
4547

4648
rollback: function() {
49+
var self = this;
50+
4751
debug('rollback');
48-
return this.transaction.rollback().then(() => {
49-
this.transaction = undefined;
52+
return this.transaction.rollback().then(function() {
53+
self.transaction = undefined;
5054
});
5155
},
5256

test/describeDatabase.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ module.exports = function(name, config, database, otherTests) {
211211
it('rolls back when rollback is called', function () {
212212
return db.begin().then(function () {
213213
var bob = person({ name: 'bob' });
214-
return bob.save().then(() => {
214+
return bob.save().then(function () {
215215
return db.query('select * from people');
216-
}).then(people => {
216+
}).then(function (people) {
217217
expect(people).to.eql([
218218
{
219219
id: bob.id,
@@ -222,11 +222,11 @@ module.exports = function(name, config, database, otherTests) {
222222
photo: null
223223
}
224224
]);
225-
}).then(() => {
225+
}).then(function() {
226226
return db.rollback();
227-
}).then(() => {
227+
}).then(function() {
228228
return db.query('select * from people');
229-
}).then(people => {
229+
}).then(function(people) {
230230
expect(people).to.eql([
231231
]);
232232
});
@@ -238,9 +238,9 @@ module.exports = function(name, config, database, otherTests) {
238238
it('rolls back if the transaction scope throws an exception', function () {
239239
return expect(db.transaction(function () {
240240
var bob = person({ name: 'bob' });
241-
return bob.save().then(() => {
241+
return bob.save().then(function() {
242242
return db.query('select * from people');
243-
}).then(people => {
243+
}).then(function(people) {
244244
expect(people).to.eql([
245245
{
246246
id: bob.id,
@@ -252,9 +252,9 @@ module.exports = function(name, config, database, otherTests) {
252252

253253
throw new Error('uh oh');
254254
});
255-
})).to.be.rejectedWith('uh oh').then(() => {
255+
})).to.be.rejectedWith('uh oh').then(function() {
256256
return db.query('select * from people');
257-
}).then(people => {
257+
}).then(function(people) {
258258
expect(people).to.eql([
259259
]);
260260
});
@@ -267,9 +267,9 @@ module.exports = function(name, config, database, otherTests) {
267267
it('makes changes after commit is called', function () {
268268
return db.begin().then(function () {
269269
var bob = person({ name: 'bob' });
270-
return bob.save().then(() => {
270+
return bob.save().then(function() {
271271
return db.query('select * from people');
272-
}).then(people => {
272+
}).then(function(people) {
273273
expect(people).to.eql([
274274
{
275275
id: bob.id,
@@ -278,11 +278,11 @@ module.exports = function(name, config, database, otherTests) {
278278
photo: null
279279
}
280280
]);
281-
}).then(() => {
281+
}).then(function() {
282282
return db.commit();
283-
}).then(() => {
283+
}).then(function() {
284284
return db.query('select * from people');
285-
}).then(people => {
285+
}).then(function(people) {
286286
expect(people).to.eql([
287287
{
288288
id: bob.id,
@@ -302,9 +302,9 @@ module.exports = function(name, config, database, otherTests) {
302302

303303
return db.transaction(function () {
304304
bob = person({ name: 'bob' });
305-
return bob.save().then(() => {
305+
return bob.save().then(function() {
306306
return db.query('select * from people');
307-
}).then(people => {
307+
}).then(function(people) {
308308
expect(people).to.eql([
309309
{
310310
id: bob.id,
@@ -314,9 +314,9 @@ module.exports = function(name, config, database, otherTests) {
314314
}
315315
]);
316316
});
317-
}).then(() => {
317+
}).then(function() {
318318
return db.query('select * from people');
319-
}).then(people => {
319+
}).then(function(people) {
320320
expect(people).to.eql([
321321
{
322322
id: bob.id,

0 commit comments

Comments
 (0)