Skip to content

Commit

Permalink
Removed a couple of places with transaction: null, added CLS as dev-d…
Browse files Browse the repository at this point in the history
…ependency and fixed cls test for sqlite
  • Loading branch information
janmeier committed Jan 14, 2015
1 parent 3dd80fd commit 7e06e0c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
8 changes: 4 additions & 4 deletions lib/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,9 @@ module.exports = (function() {
, where;

if (countOrOptions === undefined) {
countOrOptions = { by: 1, transaction: null };
countOrOptions = { by: 1 };
} else if (typeof countOrOptions === 'number') {
countOrOptions = { by: countOrOptions, transaction: null };
countOrOptions = { by: countOrOptions };
}

countOrOptions = Utils._.extend({
Expand Down Expand Up @@ -892,9 +892,9 @@ module.exports = (function() {
});

if (countOrOptions === undefined) {
countOrOptions = { by: 1, transaction: null };
countOrOptions = { by: 1 };
} else if (typeof countOrOptions === 'number') {
countOrOptions = { by: countOrOptions, transaction: null };
countOrOptions = { by: countOrOptions };
}

if (countOrOptions.by === undefined) {
Expand Down
2 changes: 0 additions & 2 deletions lib/query-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ module.exports = (function() {
var self = this;

options = Utils._.extend({
transaction: null,
raw: true
}, options || {});

Expand Down Expand Up @@ -285,7 +284,6 @@ module.exports = (function() {
QueryInterface.prototype.showAllTables = function(options) {
var self = this;
options = Utils._.extend({
transaction: null,
raw: true,
type: QueryTypes.SHOWTABLES
}, options || {});
Expand Down
30 changes: 14 additions & 16 deletions lib/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,25 +1075,23 @@ module.exports = (function() {
}

return new Promise(transactionResolver);
} else {
if (ns) {
var context = ns.createContext();
} else if (ns) {
var context = ns.createContext();

return ns.bind(function () {
var ret = transaction.prepareEnvironment().return(transaction);
return ns.bind(function () {
var ret = transaction.prepareEnvironment().return(transaction);

ret.then = function (didFulfill, didReject, didProgress) {
// We manually pass a context here, because the right context has to be available even though the .then callback is not strictly within the same callback chain
didFulfill = ns.bind(didFulfill, context);
ret.then = function (didFulfill, didReject, didProgress) {
// We manually pass a context here, because the right context has to be available even though the .then callback is not strictly within the same callback chain
didFulfill = ns.bind(didFulfill, context);

return Sequelize.Promise.prototype.then.call(this, didFulfill, didReject, didProgress);
};
return Sequelize.Promise.prototype.then.call(this, didFulfill, didReject, didProgress);
};

return ret;
}, context)();
} else {
return transaction.prepareEnvironment().return(transaction);
}
return ret;
}, context)();
} else {
return transaction.prepareEnvironment().return(transaction);
}
};

Expand All @@ -1104,7 +1102,7 @@ module.exports = (function() {

if (last && Utils._.isPlainObject(last) && last.hasOwnProperty('logging')) {
options = last;

// remove options from set of logged arguments
args.splice(args.length-1, 1);
} else {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"validator": "~3.22.1"
},
"devDependencies": {
"continuation-local-storage": "3.1.2",
"chai-as-promised": "^4.1.1",
"sqlite3": "~3.0.0",
"mysql": "~2.5.0",
Expand Down
6 changes: 4 additions & 2 deletions test/cls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ chai.config.includeStack = true;

describe(Support.getTestDialectTeaser("Continuation local storage"), function () {
before(function () {
this.sequelize = Support.createSequelizeInstance({
return Support.prepareTransactionTest(Support.createSequelizeInstance({
namespace: cls.createNamespace('sequelize')
})).bind(this).then(function (sequelize) {
this.sequelize = sequelize;
});
});

Expand Down Expand Up @@ -91,7 +93,7 @@ describe(Support.getTestDialectTeaser("Continuation local storage"), function ()
});
});

// Wait for 500 ms - should be enough time to get everything set up
// Wait for 400 ms - should be enough time to get everything set up
return Promise.delay(400).bind(this).then(function () {
expect(transactionSetup).to.be.ok;
expect(transactionEnded).not.to.be.ok;
Expand Down
Empty file.

0 comments on commit 7e06e0c

Please sign in to comment.