不要怂,就是干,撸起袖子干!

Commit 274beb7e by Joel Trost Committed by Matt Broadstone

Now supports separate connections for transactions

1 parent 54e12fcd
......@@ -13,7 +13,7 @@ ConnectionManager = function(dialect, sequelize) {
try {
this.lib = require(sequelize.config.dialectModulePath || 'mssql');
} catch (err) {
throw new Error('Please install mssql package manually');
throw new Error('Please install mssql package');
}
};
......@@ -43,9 +43,13 @@ ConnectionManager.prototype.connect = function(config, isTransaction) {
server: connectionConfig.host,
database: connectionConfig.database
};
var connection = {
config: config,
lib: self.lib
};
var conn;
if (isTransaction) {
var conn = new self.lib.Connection(config, function (err){
conn = new self.lib.Connection(config, function (err){
var trans = new self.lib.Transaction(conn);
self.lib._transaction = trans;
......@@ -54,12 +58,13 @@ ConnectionManager.prototype.connect = function(config, isTransaction) {
reject(err);
return;
}
resolve(self.lib);
connection.context = conn;
//connection.transaction = trans;
resolve(connection);
});
});
} else {
self.lib.connect(config, function(err) {
conn = new self.lib.Connection(config, function(err) {
// var request = new self.lib.Request();
// request.query('select 1 as number', function(err, recordset) {
// console.log('err2', err);
......@@ -71,7 +76,8 @@ ConnectionManager.prototype.connect = function(config, isTransaction) {
return;
}
resolve(self.lib);
connection.context = conn;
resolve(connection);
});
}
......
......@@ -2,7 +2,6 @@
var Utils = require('../../utils')
, AbstractQuery = require('../abstract/query')
, uuid = require('node-uuid')
, sequelizeErrors = require('../../errors.js');
module.exports = (function() {
......@@ -10,7 +9,6 @@ module.exports = (function() {
this.connection = connection;
this.callee = callee;
this.sequelize = sequelize;
this.uuid = uuid.v4();
this.options = Utils._.extend({
logging: console.log,
plain: false,
......@@ -32,12 +30,12 @@ module.exports = (function() {
this.sql = sql;
if (this.options.logging !== false) {
this.sequelize.log('Executing (' + this.connection.uuid + '): ' + this.sql);
this.sequelize.log('Executing (' + (this.connection.uuid || 'default') + '): ' + this.sql);
}
var promise = new Utils.Promise(function(resolve, reject) {
console.log(self.sql);
//console.log(self.sql);
// self
// .connection
......@@ -57,7 +55,7 @@ module.exports = (function() {
var request, transCommand;
if (self.connection._transaction) {
request = new self.connection.Request(self.connection._transaction);
request = new self.connection.lib.Request(self.connection.context._transaction);
if (self.sql === 'COMMIT TRANSACTION;') {
transCommand = 'commit';
......@@ -67,7 +65,7 @@ module.exports = (function() {
if (self.sql === 'COMMIT TRANSACTION;' ||
self.sql === 'ROLLBACK TRANSACTION;') {
self.connection._transaction[transCommand](function (err, result) {
self.connection.context._transaction[transCommand](function (err, result) {
if (err) {
console.log(err.message);
reject(self.formatError(err));
......@@ -78,7 +76,7 @@ module.exports = (function() {
return promise;
}
} else {
request = new self.connection.Request();
request = new self.connection.lib.Request(self.connection.context);
}
request.query(self.sql, function(err, recordset) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!