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

Commit af294fb3 by Matt Broadstone

remove unused code in SqlGenerator

1 parent 9efcca74
Showing with 1 additions and 137 deletions
......@@ -534,140 +534,4 @@ module.exports = {
return attrString.join(', ');
},
getTopClause: function(limit){
return "TOP(" + limit + ")";
},
getCountClause: function(alias, columnName){
return [
"SELECT COUNT(",
columnName,
") AS", quoteIdentifier(alias)
].join(' ');
},
getSelectorClause: function(model, options){
var query = ['SELECT'];
//we have joins
if(options.limit && !options.offset){
query.push(this.getTopClause(options.limit));
}
//add join table
if(options.include){
query.push(loadFieldsWithName(options.attributes, model.name));
for(var i = 0; i < options.include.length; i++){
if(options.include[i].as) {
query.push(',' + joinFields(options.include[i].model.rawAttributes
, options.include[i].as));
}
}
}else{
query.push(loadFieldsWithName(options.attributes));
//query.push(loadFieldsWithName(model.rawAttributes));
}
return query.join(' ');
},
getFromClause: function(tableName, asValue){
var query = ["FROM",
quoteIdentifier(tableName)];
if(asValue){
query.push("AS");
query.push(quoteIdentifier(asValue));
}
return query.join(' ');
},
getJoinClause: function(model, include){
var query = [];
var primaryKey = quoteIdentifier(model.primaryKeyAttribute);
var joinType = include.required ? 'INNER JOIN' : 'LEFT OUTER JOIN';
var joinTable = include.as ? include.as : include.model.name;
var manyJoinTable = joinTable;
joinTable = quoteIdentifier(joinTable);
var tableName = quoteIdentifier(model.name);
var hasManyToMany = false;
query.push(joinType);
if(include.through){
hasManyToMany = true;
}
//this logic handles the join types
var associationType = include.association.associationType;
var rootKey,joinKey;
if(associationType === 'BelongsTo'){
rootKey = quoteIdentifier(include.association.foreignKey);
joinKey = primaryKey;
}else if (associationType === 'HasMany'){
rootKey = primaryKey;
joinKey = quoteIdentifier(include.association.identifier);
if(hasManyToMany){
//indicates many to many
manyJoinTable = quoteIdentifier(joinTable + '.' + include.through.as);
//console.log(include.through);
query = query.concat([
"(",
quoteIdentifier(include.through.model.name)
, "AS", manyJoinTable,
joinType,
joinTable, "AS", joinTable,
"ON", joinTable + '.' + quoteIdentifier(include.model.primaryKeyAttribute),
"=", manyJoinTable + '.' + quoteIdentifier(include.through.model.primaryKeyAttribute),
")"
]);
}
}else{
rootKey = primaryKey;
//console.log('dang mang',associationType);
joinKey = quoteIdentifier(include.association.foreignKey);
//console.log('asdfdsaf', rootKey);
}
if(!hasManyToMany){
query.push(quoteIdentifier(include.model.tableName));
query.push('AS');
query.push(joinTable);
}
query = query.concat([
'ON', tableName + '.' + rootKey,
'=', manyJoinTable + '.' + joinKey
]);
if(include.where){
query.push('AND');
query.push(this.formatWhereCondition(include.where, joinTable));
}
return query.join(' ');
},
formatWhereCondition: function(where, tableName){
var query = [];
for(var key in where){
var val = where[key];
var operator = '=';
if (!val) {
operator = 'IS';
}
if(tableName){
query.push(quoteIdentifier(tableName) + '.' + quoteIdentifier(key));
} else {
query.push(quoteIdentifier(key));
}
query.push(operator);
if(!val){
query.push('NULL');
}else if(typeof val === 'number'){
query.push(val);
}else{
query.push(wrapSingleQuote(val));
}
}
return query.join(' ');
},
getWhereClause: function(where, tableName){
return [
'WHERE',
this.formatWhereCondition(where, tableName)
].join(' ');
}};
};
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!