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

Commit 8dd3cb03 by Sascha Depold

Merge pull request #406 from watson/es5

Use ES5 native instead of Underscore.js when possible
2 parents 80b0cf67 e016b2ff
...@@ -15,7 +15,7 @@ module.exports = (function() { ...@@ -15,7 +15,7 @@ module.exports = (function() {
//fully qualify //fully qualify
where[self.__factory.connectorDAO.tableName+"."+self.__factory.identifier] = self.instance.id where[self.__factory.connectorDAO.tableName+"."+self.__factory.identifier] = self.instance.id
var primaryKeys = Utils._.keys(self.__factory.connectorDAO.rawAttributes) var primaryKeys = Object.keys(self.__factory.connectorDAO.rawAttributes)
, foreignKey = primaryKeys.filter(function(pk) { return pk != self.__factory.identifier })[0] , foreignKey = primaryKeys.filter(function(pk) { return pk != self.__factory.identifier })[0]
where[self.__factory.connectorDAO.tableName+"."+foreignKey] = {join: self.__factory.target.tableName+".id"} where[self.__factory.connectorDAO.tableName+"."+foreignKey] = {join: self.__factory.target.tableName+".id"}
...@@ -85,7 +85,7 @@ module.exports = (function() { ...@@ -85,7 +85,7 @@ module.exports = (function() {
obsoleteAssociations.forEach(function(associatedObject) { obsoleteAssociations.forEach(function(associatedObject) {
var where = {} var where = {}
, primaryKeys = Utils._.keys(self.__factory.connectorDAO.rawAttributes) , primaryKeys = Object.keys(self.__factory.connectorDAO.rawAttributes)
, foreignKey = primaryKeys.filter(function(pk) { return pk != self.__factory.identifier })[0] , foreignKey = primaryKeys.filter(function(pk) { return pk != self.__factory.identifier })[0]
, notFoundEmitters = [] , notFoundEmitters = []
......
...@@ -61,7 +61,7 @@ module.exports = (function() { ...@@ -61,7 +61,7 @@ module.exports = (function() {
} }
}) })
this.primaryKeyCount = Utils._.keys(this.primaryKeys).length; this.primaryKeyCount = Object.keys(this.primaryKeys).length;
this.options.hasPrimaryKeys = this.hasPrimaryKeys = this.primaryKeyCount > 0; this.options.hasPrimaryKeys = this.hasPrimaryKeys = this.primaryKeyCount > 0;
addDefaultAttributes.call(this) addDefaultAttributes.call(this)
...@@ -189,7 +189,7 @@ module.exports = (function() { ...@@ -189,7 +189,7 @@ module.exports = (function() {
} else if (Utils._.size(primaryKeys) && Utils.argsArePrimaryKeys(arguments, primaryKeys)) { } else if (Utils._.size(primaryKeys) && Utils.argsArePrimaryKeys(arguments, primaryKeys)) {
var where = {} var where = {}
, self = this , self = this
, keys = Utils._.keys(primaryKeys) , keys = Object.keys(primaryKeys)
Utils._.each(arguments, function(arg, i) { Utils._.each(arguments, function(arg, i) {
var key = keys[i] var key = keys[i]
......
...@@ -74,7 +74,7 @@ module.exports = (function() { ...@@ -74,7 +74,7 @@ module.exports = (function() {
Object.defineProperty(DAO.prototype, "identifiers", { Object.defineProperty(DAO.prototype, "identifiers", {
get: function() { get: function() {
var primaryKeys = Utils._.keys(this.__factory.primaryKeys) var primaryKeys = Object.keys(this.__factory.primaryKeys)
, result = {} , result = {}
, self = this , self = this
...@@ -164,7 +164,7 @@ module.exports = (function() { ...@@ -164,7 +164,7 @@ module.exports = (function() {
else { else {
// extra args // extra args
fn_args = details.hasOwnProperty("args") ? details.args : details fn_args = details.hasOwnProperty("args") ? details.args : details
if (!Utils._.isArray(fn_args)) if (!Array.isArray(fn_args))
fn_args = [fn_args] fn_args = [fn_args]
// error msg // error msg
fn_msg = details.hasOwnProperty("msg") ? details.msg : false fn_msg = details.hasOwnProperty("msg") ? details.msg : false
...@@ -207,7 +207,7 @@ module.exports = (function() { ...@@ -207,7 +207,7 @@ module.exports = (function() {
DAO.prototype.setAttributes = function(updates) { DAO.prototype.setAttributes = function(updates) {
var self = this var self = this
var readOnlyAttributes = Utils._.keys(this.__factory.primaryKeys) var readOnlyAttributes = Object.keys(this.__factory.primaryKeys)
readOnlyAttributes.push('id') readOnlyAttributes.push('id')
readOnlyAttributes.push('createdAt') readOnlyAttributes.push('createdAt')
......
...@@ -168,7 +168,7 @@ module.exports = (function() { ...@@ -168,7 +168,7 @@ module.exports = (function() {
var queryResultHasJoin = function(results) { var queryResultHasJoin = function(results) {
if (!!results[0]) { if (!!results[0]) {
var keys = Utils._.keys(results[0]) var keys = Object.keys(results[0])
for (var i = 0; i < keys.length; i++) { for (var i = 0; i < keys.length; i++) {
if (!!findTableNameInAttribute.call(this, keys[i])) { if (!!findTableNameInAttribute.call(this, keys[i])) {
......
...@@ -141,7 +141,7 @@ module.exports = (function() { ...@@ -141,7 +141,7 @@ module.exports = (function() {
, association = dao.getAssociation(daoFactory) , association = dao.getAssociation(daoFactory)
if (association.connectorDAO) { if (association.connectorDAO) {
var foreignIdentifier = Utils._.keys(association.connectorDAO.rawAttributes).filter(function(attrName) { var foreignIdentifier = Object.keys(association.connectorDAO.rawAttributes).filter(function(attrName) {
return (!!attrName.match(/.+Id$/) || !!attrName.match(/.+_id$/)) && (attrName !== association.identifier) return (!!attrName.match(/.+Id$/) || !!attrName.match(/.+_id$/)) && (attrName !== association.identifier)
})[0] })[0]
...@@ -165,7 +165,7 @@ module.exports = (function() { ...@@ -165,7 +165,7 @@ module.exports = (function() {
, aliasName = !!aliasAssoc ? Utils.addTicks(daoName) : _tableName , aliasName = !!aliasAssoc ? Utils.addTicks(daoName) : _tableName
optAttributes = optAttributes.concat( optAttributes = optAttributes.concat(
Utils._.keys(dao.attributes).map(function(attr) { Object.keys(dao.attributes).map(function(attr) {
return '' + return '' +
[_tableName, Utils.addTicks(attr)].join('.') + [_tableName, Utils.addTicks(attr)].join('.') +
' AS ' + ' AS ' +
...@@ -213,7 +213,7 @@ module.exports = (function() { ...@@ -213,7 +213,7 @@ module.exports = (function() {
var replacements = { var replacements = {
table: Utils.addTicks(tableName), table: Utils.addTicks(tableName),
attributes: Utils._.keys(attrValueHash).map(function(attr){return Utils.addTicks(attr)}).join(","), attributes: Object.keys(attrValueHash).map(function(attr){return Utils.addTicks(attr)}).join(","),
values: Utils._.values(attrValueHash).map(function(value){ values: Utils._.values(attrValueHash).map(function(value){
return Utils.escape((value instanceof Date) ? Utils.toSqlDate(value) : value) return Utils.escape((value instanceof Date) ? Utils.toSqlDate(value) : value)
}).join(",") }).join(",")
......
...@@ -216,7 +216,7 @@ module.exports = (function() { ...@@ -216,7 +216,7 @@ module.exports = (function() {
, association = dao.getAssociation(daoFactory) , association = dao.getAssociation(daoFactory)
if (association.connectorDAO) { if (association.connectorDAO) {
var foreignIdentifier = Utils._.keys(association.connectorDAO.rawAttributes).filter(function(attrName) { var foreignIdentifier = Object.keys(association.connectorDAO.rawAttributes).filter(function(attrName) {
return (!!attrName.match(/.+Id$/) || !!attrName.match(/.+_id$/)) && (attrName !== association.identifier) return (!!attrName.match(/.+Id$/) || !!attrName.match(/.+_id$/)) && (attrName !== association.identifier)
})[0] })[0]
...@@ -240,7 +240,7 @@ module.exports = (function() { ...@@ -240,7 +240,7 @@ module.exports = (function() {
, aliasName = !!aliasAssoc ? addQuotes(daoName) : _tableName , aliasName = !!aliasAssoc ? addQuotes(daoName) : _tableName
optAttributes = optAttributes.concat( optAttributes = optAttributes.concat(
Utils._.keys(dao.attributes).map(function(attr) { Object.keys(dao.attributes).map(function(attr) {
return '' + return '' +
[_tableName, addQuotes(attr)].join('.') + [_tableName, addQuotes(attr)].join('.') +
' AS "' + ' AS "' +
...@@ -302,7 +302,7 @@ module.exports = (function() { ...@@ -302,7 +302,7 @@ module.exports = (function() {
var replacements = { var replacements = {
table: addQuotes(tableName), table: addQuotes(tableName),
attributes: Utils._.keys(attrValueHash).map(function(attr){return addQuotes(attr)}).join(","), attributes: Object.keys(attrValueHash).map(function(attr){return addQuotes(attr)}).join(","),
values: Utils._.values(attrValueHash).map(function(value){ values: Utils._.values(attrValueHash).map(function(value){
return pgEscape(value) return pgEscape(value)
}).join(",") }).join(",")
......
...@@ -71,7 +71,7 @@ module.exports = (function() { ...@@ -71,7 +71,7 @@ module.exports = (function() {
var replacements = { var replacements = {
table: Utils.addTicks(tableName), table: Utils.addTicks(tableName),
attributes: Utils._.keys(attrValueHash).map(function(attr){return Utils.addTicks(attr)}).join(","), attributes: Object.keys(attrValueHash).map(function(attr){return Utils.addTicks(attr)}).join(","),
values: Utils._.values(attrValueHash).map(function(value){ values: Utils._.values(attrValueHash).map(function(value){
return escape((value instanceof Date) ? Utils.toSqlDate(value) : value) return escape((value instanceof Date) ? Utils.toSqlDate(value) : value)
}).join(",") }).join(",")
......
...@@ -50,7 +50,7 @@ var Utils = module.exports = { ...@@ -50,7 +50,7 @@ var Utils = module.exports = {
return connection.format.apply(connection, [arr.shift(), arr]) return connection.format.apply(connection, [arr.shift(), arr])
}, },
isHash: function(obj) { isHash: function(obj) {
return Utils._.isObject(obj) && !Utils._.isArray(obj); return Utils._.isObject(obj) && !Array.isArray(obj);
}, },
toSqlDate: function(date) { toSqlDate: function(date) {
return [ return [
...@@ -63,7 +63,7 @@ var Utils = module.exports = { ...@@ -63,7 +63,7 @@ var Utils = module.exports = {
].join(" ") ].join(" ")
}, },
argsArePrimaryKeys: function(args, primaryKeys) { argsArePrimaryKeys: function(args, primaryKeys) {
var result = (args.length == Utils._.keys(primaryKeys).length) var result = (args.length == Object.keys(primaryKeys).length)
if (result) { if (result) {
Utils._.each(args, function(arg) { Utils._.each(args, function(arg) {
if(result) { if(result) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!