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

Commit 8d9eb560 by Joel Trost Committed by Matt Broadstone

Fixed raw:true query

1 parent cada814f
......@@ -114,7 +114,6 @@ module.exports = (function() {
*/
Query.prototype.formatResults = function(data) {
var result = this.callee;
//console.log(data);
if (this.isInsertQuery(data)) {
this.handleInsertQuery(data);
} else if (this.isShowTableQuery()) {
......@@ -141,8 +140,13 @@ module.exports = (function() {
result = data[0];
} else if (this.isBulkUpdateQuery() || this.isBulkDeleteQuery()) {
result = data.affectedRows;
}else {
if(this.options.type && !this.options.raw){
result = this.handleSelectQuery(data);
}else{
result = data;
}
}
return result;
};
......
......@@ -276,7 +276,7 @@ module.exports = {
, emptyQuery = 'INSERT INTO <%= tableName %>';
valueQuery += ' OUTPUT <%= selFields %> VALUES (<%= values %>)';
emptyQuery += ' VALUES ()';
emptyQuery += ' OUTPUT <%= selFields %> DEFAULT VALUES';
valueHash = Utils.removeNullValuesFromHash(valueHash, _options.omitNull);
......@@ -288,7 +288,8 @@ module.exports = {
&& (valueHash[key] === 'DEFAULT'
|| valueHash[key] === null)){
delete valueHash[key];
}else if(modelAttributeMap[key].autoIncrement){
}else if(valueHash[key]
&& modelAttributeMap[key].autoIncrement){
insertKey = true;
}
}
......@@ -427,14 +428,6 @@ module.exports = {
return Utils._.template(sql)(values);
},
getEnumSql: function (attribute){
var template = 'VARCHAR(10) NOT NULL CHECK ("'
+ attribute.field + '" IN('
+ Utils._.map(attribute.values, function(value) {
return escape(value);
}.bind(this)).join(', ') + '))';
return template;
},
attributeToSQL: function(attribute, options) {
if (!Utils._.isPlainObject(attribute)) {
attribute = {
......@@ -445,7 +438,18 @@ module.exports = {
var template = [];
//special enum query
if (attribute.type.toString() === DataTypes.ENUM.toString()) {
template.push(this.getEnumSql(attribute));
template.push('VARCHAR(10)');
if(attribute.allowNull === false){
template.push(attributeMap.notNull);
//not nullable
}else{
template.push(attributeMap.allowNull);
}
template.push('CHECK ("'
+ attribute.field + '" IN('
+ Utils._.map(attribute.values, function(value) {
return escape(value);
}.bind(this)).join(', ') + '))');
} else {
//the everything else
template.push(attribute.type.toString());
......
......@@ -665,7 +665,7 @@ describe(Support.getTestDialectTeaser("Model"), function () {
})
})
it.only('should only store the values passed in the whitelist', function(done) {
it('should only store the values passed in the whitelist', function(done) {
var self = this
, data = { username: 'Peter', secretValue: '42' }
......@@ -727,7 +727,7 @@ describe(Support.getTestDialectTeaser("Model"), function () {
})
})
it.only('saves data with single quote', function(done) {
it('saves data with single quote', function(done) {
var quote = "single'quote"
, self = this
......@@ -1039,11 +1039,11 @@ describe(Support.getTestDialectTeaser("Model"), function () {
})
})
it.only('saves data with single quote', function(done) {
it('saves data with single quote', function(done) {
var self = this
, quote = "Single'Quote"
, data = [{ username: 'Peter', data: quote},
{ username: 'Paul', data: quote}]
, data = [{ username: 'Peter', data: quote, uniqueName: '1'},
{ username: 'Paul', data: quote, uniqueName: '2'}]
this.User.bulkCreate(data).success(function() {
self.User.findAll({order: 'id'}).success(function(users) {
......@@ -1060,8 +1060,8 @@ describe(Support.getTestDialectTeaser("Model"), function () {
it('saves data with double quote', function(done) {
var self = this
, quote = 'Double"Quote'
, data = [{ username: 'Peter', data: quote},
{ username: 'Paul', data: quote}]
, data = [{ username: 'Peter', data: quote, uniqueName: '1'},
{ username: 'Paul', data: quote, uniqueName: '2'}]
this.User.bulkCreate(data).success(function() {
self.User.findAll({order: 'id'}).success(function(users) {
......@@ -1078,8 +1078,8 @@ describe(Support.getTestDialectTeaser("Model"), function () {
it('saves stringified JSON data', function(done) {
var self = this
, json = JSON.stringify({ key: 'value' })
, data = [{ username: 'Peter', data: json},
{ username: 'Paul', data: json}]
, data = [{ username: 'Peter', data: json, uniqueName: '1'},
{ username: 'Paul', data: json, uniqueName: '2'}]
this.User.bulkCreate(data).success(function() {
self.User.findAll({order: 'id'}).success(function(users) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!