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

Commit b987a80f by Jan Aagaard Meier

Making the code climate a bit nice

1 parent 3f510d83
...@@ -366,10 +366,10 @@ module.exports = (function() { ...@@ -366,10 +366,10 @@ module.exports = (function() {
return Utils._.template(query, { return Utils._.template(query, {
tableName: tableName, tableName: tableName,
attributeNamesImport: Utils._.keys(attributes).map(function(attr) { attributeNamesImport: Utils._.keys(attributes).map(function(attr) {
return (attrNameAfter === attr) ? this.quoteIdentifier(attrNameBefore) + ' AS ' + this.quoteIdentifier(attr) : this.quoteIdentifier(attr); return (attrNameAfter === attr) ? this.quoteIdentifier(attrNameBefore) + ' AS ' + this.quoteIdentifier(attr) : this.quoteIdentifier(attr);
}.bind(this)).join(', '), }.bind(this)).join(', '),
attributeNamesExport: Utils._.keys(attributes).map(function(attr) { attributeNamesExport: Utils._.keys(attributes).map(function(attr) {
return this.quoteIdentifier(attr); return this.quoteIdentifier(attr);
}.bind(this)).join(', ') }.bind(this)).join(', ')
}); });
}, },
......
...@@ -127,11 +127,11 @@ module.exports = (function() { ...@@ -127,11 +127,11 @@ module.exports = (function() {
// inject the node-sql methods to the dao factory in order to // inject the node-sql methods to the dao factory in order to
// receive the syntax sugar ... // receive the syntax sugar ...
(function() { (function() {
var instance = sql.define({ name: 'dummy', columns: [] }); var instance = sql.define({ name: 'dummy', columns: [] });
for (var methodName in instance) { for (var methodName in instance) {
;(function(methodName) { ;(function(methodName) {
Model.prototype[methodName] = function() { Model.prototype[methodName] = function() {
var dataset = this.dataset() var dataset = this.dataset()
, result = dataset[methodName].apply(dataset, arguments) , result = dataset[methodName].apply(dataset, arguments)
...@@ -1083,7 +1083,7 @@ module.exports = (function() { ...@@ -1083,7 +1083,7 @@ module.exports = (function() {
options = Utils._.extend({ options = Utils._.extend({
transaction: null transaction: null
}, options ||  {}); }, options || {});
if (!(where instanceof Utils.or) && !(where instanceof Utils.and) && !Array.isArray(where)) { if (!(where instanceof Utils.or) && !(where instanceof Utils.and) && !Array.isArray(where)) {
for (var attrname in where) { for (var attrname in where) {
...@@ -1255,8 +1255,8 @@ module.exports = (function() { ...@@ -1255,8 +1255,8 @@ module.exports = (function() {
}); });
} }
}).then(function() { }).then(function() {
return daos; return daos;
}); });
}; };
/** /**
......
...@@ -227,7 +227,7 @@ module.exports = (function() { ...@@ -227,7 +227,7 @@ module.exports = (function() {
}); });
return Utils.Promise.all(promises).then(function() { return Utils.Promise.all(promises).then(function() {
return dropAllTables(tableNames); return dropAllTables(tableNames);
}); });
}); });
} }
......
...@@ -67,7 +67,7 @@ var Utils = module.exports = { ...@@ -67,7 +67,7 @@ var Utils = module.exports = {
return str.slice(0, index) + add + str.slice(index + count); return str.slice(0, index) + add + str.slice(index + count);
}, },
camelize: function(str){ camelize: function(str){
return str.trim().replace(/[-_\s]+(.)?/g, function(match, c){ return c.toUpperCase(); }); return str.trim().replace(/[-_\s]+(.)?/g, function(match, c){ return c.toUpperCase(); });
}, },
format: function(arr, dialect) { format: function(arr, dialect) {
var timeZone = null; var timeZone = null;
...@@ -339,23 +339,6 @@ var Utils = module.exports = { ...@@ -339,23 +339,6 @@ var Utils = module.exports = {
return ''; return '';
} }
}, },
hasChanged: function(attrValue, value) {
//If attribute value is Date, check value as a date
if (Utils._.isDate(attrValue) && !Utils._.isDate(value)) {
value = new Date(value);
}
if (Utils._.isDate(attrValue)) {
return attrValue.valueOf() !== value.valueOf();
}
//If both of them are empty, don't set as changed
if ((attrValue === undefined || attrValue === null || attrValue === '') && (value === undefined || value === null || value === '')) {
return false;
}
return attrValue !== value;
},
argsArePrimaryKeys: function(args, primaryKeys) { argsArePrimaryKeys: function(args, primaryKeys) {
var result = (args.length === Object.keys(primaryKeys).length); var result = (args.length === Object.keys(primaryKeys).length);
if (result) { if (result) {
...@@ -427,18 +410,6 @@ var Utils = module.exports = { ...@@ -427,18 +410,6 @@ var Utils = module.exports = {
return true; return true;
}, },
setAttributes: function(hash, identifier, instance, prefix) {
prefix = prefix || '';
if (this._.isPlainObject(identifier)) {
this._.each(identifier, function(elem, key) {
hash[prefix + key] = Utils._.isString(instance) ? instance : Utils._.isObject(instance) ? instance[elem.key || elem] : null;
});
} else {
hash[prefix + identifier] = Utils._.isString(instance) ? instance : Utils._.isObject(instance) ? instance.id : null;
}
return hash;
},
removeNullValuesFromHash: function(hash, omitNull, options) { removeNullValuesFromHash: function(hash, omitNull, options) {
var result = hash; var result = hash;
...@@ -461,14 +432,6 @@ var Utils = module.exports = { ...@@ -461,14 +432,6 @@ var Utils = module.exports = {
return result; return result;
}, },
firstValueOfHash: function(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key))
return obj[key];
}
return null;
},
inherit: function(SubClass, SuperClass) { inherit: function(SubClass, SuperClass) {
if (SuperClass.constructor === Function) { if (SuperClass.constructor === Function) {
// Normal Inheritance // Normal Inheritance
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!