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

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