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

Commit 195e8554 by Joel Trost Committed by Matt Broadstone

Fixed default select type

1 parent 8d9eb560
......@@ -114,38 +114,39 @@ module.exports = (function() {
*/
Query.prototype.formatResults = function(data) {
var result = this.callee;
if (this.isInsertQuery(data)) {
this.handleInsertQuery(data);
} else if (this.isShowTableQuery()) {
result = this.handleShowTableQuery(data);
} else if (this.isShowOrDescribeQuery()) {
result = data;
if (this.sql.toLowerCase().indexOf("select c.name, t.name as 'type', c.is_nullable as isnull") === 0) {
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()) {
if(data){
if (this.isInsertQuery(data)) {
this.handleInsertQuery(data);
} else if (this.isShowTableQuery()) {
result = this.handleShowTableQuery(data);
} else if (this.isShowOrDescribeQuery()) {
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 {
if(this.options.type && !this.options.raw){
if (this.sql.toLowerCase().indexOf("select c.name, t.name as 'type', c.is_nullable as isnull") === 0) {
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;
}
} 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);
}else{
result = data;
}
}else{
result = data;
}
return result;
};
......
......@@ -991,9 +991,9 @@ describe(Support.getTestDialectTeaser("Model"), function () {
it('properly handles disparate field lists', function(done) {
var self = this
, data = [{username: 'Peter', secretValue: '42' },
{username: 'Paul'},
{username: 'Steve'}]
, data = [{username: 'Peter', secretValue: '42', uniqueName:'1' },
{username: 'Paul', uniqueName:'2'},
{username: 'Steve', uniqueName:'3'}]
this.User.bulkCreate(data).success(function() {
self.User.findAll({where: {username: 'Paul'}}).success(function(users) {
......@@ -1007,10 +1007,10 @@ describe(Support.getTestDialectTeaser("Model"), function () {
it('inserts multiple values respecting the white list', function(done) {
var self = this
, data = [{ username: 'Peter', secretValue: '42' },
{ username: 'Paul', secretValue: '23'}]
, data = [{ username: 'Peter', secretValue: '42', uniqueName:'1' },
{ 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) {
expect(users.length).to.equal(2)
expect(users[0].username).to.equal("Peter")
......@@ -1024,8 +1024,8 @@ describe(Support.getTestDialectTeaser("Model"), function () {
it('should store all values if no whitelist is specified', function(done) {
var self = this
, data = [{ username: 'Peter', secretValue: '42' },
{ username: 'Paul', secretValue: '23'}]
, data = [{ username: 'Peter', secretValue: '42', uniqueName:'1' },
{ username: 'Paul', secretValue: '23', uniqueName:'2'}]
this.User.bulkCreate(data).success(function() {
self.User.findAll({order: 'id'}).success(function(users) {
......
......@@ -99,7 +99,6 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
self.queryInterface.showIndex('Group').complete(function(err, indexes) {
expect(err).to.be.null
console.log(indexes);
indexColumns = _.uniq(indexes.map(function(index) { return index.name }))
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!