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

Commit 195e8554 by Joel Trost Committed by Matt Broadstone

Fixed default select type

1 parent 8d9eb560
...@@ -114,38 +114,39 @@ module.exports = (function() { ...@@ -114,38 +114,39 @@ module.exports = (function() {
*/ */
Query.prototype.formatResults = function(data) { Query.prototype.formatResults = function(data) {
var result = this.callee; var result = this.callee;
if (this.isInsertQuery(data)) {
this.handleInsertQuery(data); if(data){
} else if (this.isShowTableQuery()) { if (this.isInsertQuery(data)) {
result = this.handleShowTableQuery(data); this.handleInsertQuery(data);
} else if (this.isShowOrDescribeQuery()) { } else if (this.isShowTableQuery()) {
result = data; result = this.handleShowTableQuery(data);
if (this.sql.toLowerCase().indexOf("select c.name, t.name as 'type', c.is_nullable as isnull") === 0) { } else if (this.isShowOrDescribeQuery()) {
result = {};
data.forEach(function(_result) {
if(_result.Default)
_result.Default = _result.Default.replace('(\'','').replace('\')','').replace(/'/g,'');
result[_result.Name] = {
type: _result.Type.toUpperCase(),
allowNull: _result.IsNull,
defaultValue: _result.Default
};
});
} else if (this.isShowIndexesQuery()) {
result = data; result = data;
} if (this.sql.toLowerCase().indexOf("select c.name, t.name as 'type', c.is_nullable as isnull") === 0) {
} else if (this.isSelectQuery()) { result = {};
result = this.handleSelectQuery(data); data.forEach(function(_result) {
} else if (this.isCallQuery()) { if(_result.Default)
result = data[0]; _result.Default = _result.Default.replace('(\'','').replace('\')','').replace(/'/g,'');
} else if (this.isBulkUpdateQuery() || this.isBulkDeleteQuery()) { result[_result.Name] = {
result = data.affectedRows; type: _result.Type.toUpperCase(),
}else { allowNull: _result.IsNull,
if(this.options.type && !this.options.raw){ defaultValue: _result.Default
};
});
} else if (this.isShowIndexesQuery()) {
result = data;
}
} else if (this.isSelectQuery()) {
result = this.handleSelectQuery(data);
} else if (this.isCallQuery()) {
result = data[0];
} else if (this.isBulkUpdateQuery() || this.isBulkDeleteQuery()) {
result = data.affectedRows;
}else {
result = this.handleSelectQuery(data); result = this.handleSelectQuery(data);
}else{
result = data;
} }
}else{
result = data;
} }
return result; return result;
}; };
......
...@@ -991,9 +991,9 @@ describe(Support.getTestDialectTeaser("Model"), function () { ...@@ -991,9 +991,9 @@ describe(Support.getTestDialectTeaser("Model"), function () {
it('properly handles disparate field lists', function(done) { it('properly handles disparate field lists', function(done) {
var self = this var self = this
, data = [{username: 'Peter', secretValue: '42' }, , data = [{username: 'Peter', secretValue: '42', uniqueName:'1' },
{username: 'Paul'}, {username: 'Paul', uniqueName:'2'},
{username: 'Steve'}] {username: 'Steve', uniqueName:'3'}]
this.User.bulkCreate(data).success(function() { this.User.bulkCreate(data).success(function() {
self.User.findAll({where: {username: 'Paul'}}).success(function(users) { self.User.findAll({where: {username: 'Paul'}}).success(function(users) {
...@@ -1007,10 +1007,10 @@ describe(Support.getTestDialectTeaser("Model"), function () { ...@@ -1007,10 +1007,10 @@ describe(Support.getTestDialectTeaser("Model"), function () {
it('inserts multiple values respecting the white list', function(done) { it('inserts multiple values respecting the white list', function(done) {
var self = this var self = this
, data = [{ username: 'Peter', secretValue: '42' }, , data = [{ username: 'Peter', secretValue: '42', uniqueName:'1' },
{ username: 'Paul', secretValue: '23'}] { username: 'Paul', secretValue: '23', uniqueName:'2'}]
this.User.bulkCreate(data, { fields: ['username'] }).success(function() { this.User.bulkCreate(data, { fields: ['username','uniqueName'] }).success(function() {
self.User.findAll({order: 'id'}).success(function(users) { self.User.findAll({order: 'id'}).success(function(users) {
expect(users.length).to.equal(2) expect(users.length).to.equal(2)
expect(users[0].username).to.equal("Peter") expect(users[0].username).to.equal("Peter")
...@@ -1024,8 +1024,8 @@ describe(Support.getTestDialectTeaser("Model"), function () { ...@@ -1024,8 +1024,8 @@ describe(Support.getTestDialectTeaser("Model"), function () {
it('should store all values if no whitelist is specified', function(done) { it('should store all values if no whitelist is specified', function(done) {
var self = this var self = this
, data = [{ username: 'Peter', secretValue: '42' }, , data = [{ username: 'Peter', secretValue: '42', uniqueName:'1' },
{ username: 'Paul', secretValue: '23'}] { username: 'Paul', secretValue: '23', uniqueName:'2'}]
this.User.bulkCreate(data).success(function() { this.User.bulkCreate(data).success(function() {
self.User.findAll({order: 'id'}).success(function(users) { self.User.findAll({order: 'id'}).success(function(users) {
......
...@@ -99,7 +99,6 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () { ...@@ -99,7 +99,6 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
self.queryInterface.showIndex('Group').complete(function(err, indexes) { self.queryInterface.showIndex('Group').complete(function(err, indexes) {
expect(err).to.be.null expect(err).to.be.null
console.log(indexes);
indexColumns = _.uniq(indexes.map(function(index) { return index.name })) indexColumns = _.uniq(indexes.map(function(index) { return index.name }))
expect(indexColumns).to.be.empty expect(indexColumns).to.be.empty
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!