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

Commit da0eb3e6 by Sascha Depold

passing reference to event emitter to the function

1 parent 1ab0f56b
Showing with 11 additions and 11 deletions
......@@ -34,7 +34,7 @@ var Utils = module.exports = {
format: function(arr) {
var query = arr[0]
, replacements = Utils._.compact(arr.map(function(obj) { return obj != query ? obj : null}))
return client.format.apply(client, [query, replacements])
},
isHash: function(obj) {
......@@ -42,7 +42,7 @@ var Utils = module.exports = {
},
getDataTypeForValue: function(value) {
var DataTypes = require("./data-types")
switch(typeof value) {
case 'number':
return (value.toString().indexOf('.') > -1) ? DataTypes.FLOAT : DataTypes.INTEGER
......@@ -53,7 +53,7 @@ var Utils = module.exports = {
case 'object':
return (value.getMilliseconds) ? DataTypes.DATE : "WTF!"
break
default:
default:
return DataTypes.TEXT
break
}
......@@ -62,7 +62,7 @@ var Utils = module.exports = {
dataType = dataType || Utils.getDataTypeForValue(value)
var DataTypes = require("./data-types")
if((value == null)||(typeof value == 'undefined')||((dataType.indexOf(DataTypes.INTEGER) > -1) && isNaN(value)))
return "NULL"
......@@ -82,27 +82,27 @@ var Utils = module.exports = {
},
simplifyAttributes: function(attributes) {
var result = {}
Utils._.map(attributes, function(dataType, name) {
if(Utils.isHash(dataType)) {
var template = "<%= type %>"
, replacements = { type: dataType.type }
if(dataType.hasOwnProperty('allowNull') && (!dataType.allowNull)) template += " NOT NULL"
if(dataType.hasOwnProperty('allowNull') && (!dataType.allowNull)) template += " NOT NULL"
if(dataType.autoIncrement) template +=" auto_increment"
if(dataType.defaultValue != undefined) {
template += " DEFAULT <%= defaultValue %>"
replacements.defaultValue = Utils.escape(dataType.defaultValue)
}
}
if(dataType.unique) template += " UNIQUE"
if(dataType.primaryKey) template += " PRIMARY KEY"
result[name] = Utils._.template(template)(replacements)
} else {
result[name] = dataType
}
})
return result
},
toSqlDate: function(date) {
......@@ -131,7 +131,7 @@ var Utils = module.exports = {
combineTableNames: function(tableName1, tableName2) {
var chars1 = Utils._.chars(tableName1.toLowerCase())
, chars2 = Utils._.chars(tableName2.toLowerCase())
return (chars1[0] < chars2[0]) ? (tableName1 + tableName2) : (tableName2 + tableName1)
},
singularize: function(s) {
......@@ -156,7 +156,7 @@ Utils.addEventEmitter(CustomEventEmitter)
CustomEventEmitter.prototype.run = function() {
var self = this
setTimeout(function(){ self.fct() }, 5) // delay the function call and return the emitter
setTimeout(function(){ self.fct.call(self, self) }, 5) // delay the function call and return the emitter
return this
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!