Comparing version 0.1.10 to 0.1.11
var fs = require("fs"); | ||
var path = require("path"); | ||
var os = require("os"); | ||
//EventEmitter | ||
var EventEmitterInstance = new (require('events').EventEmitter); | ||
@@ -260,2 +262,26 @@ | ||
/** | ||
* 自定义事件 | ||
* @param {[type]} name [description] | ||
* @param {Function} callback [description] | ||
*/ | ||
global.E = function(event, callback, remove){ | ||
var instance = EventEmitterInstance; | ||
if (remove === true) { | ||
return instance.removeListener(event, callback); | ||
}; | ||
if (typeof callback == 'function') { | ||
return instance.on(event, callback); | ||
}; | ||
if (callback === null) { | ||
return instance.removeAllListeners(event); | ||
}; | ||
if (callback === true) { | ||
return instance.listeners(event); | ||
}; | ||
var args = [].slice.call(arguments, 1); | ||
args.unshift(event); | ||
return instance.emit.apply(instance, args); | ||
} | ||
/** | ||
* 计数 | ||
@@ -262,0 +288,0 @@ */ |
@@ -32,3 +32,3 @@ /** | ||
auto_send_content_type: true, //是否自动发送Content-Type,默认值为`tpl_content_type`配置值 | ||
empty_controller_callback: "", //controller不存在时调用的回调函数,可以在Common/common.js里定义全局函数 | ||
empty_controller_event: "", //controller不存在时处理的自定义事件,可以在Common/common.js里通过E函数注册自定义事件 | ||
@@ -35,0 +35,0 @@ cookie_domain: "", //cookie有效域名 |
@@ -65,3 +65,3 @@ /** | ||
for(var i = 0,length = Math.ceil(pathname.length)/2; i < length; i++){ | ||
this.http.query[pathname[i * 2]] = pathname[i * 2 + 1] || ""; | ||
this.http.get[pathname[i * 2]] = pathname[i * 2 + 1] || ""; | ||
} | ||
@@ -102,3 +102,3 @@ }; | ||
if (urlInfo.query) { | ||
this.http.query = extend(this.http.query, urlInfo.query); | ||
this.http.get = extend(this.http.get, urlInfo.query); | ||
}; | ||
@@ -162,3 +162,3 @@ var pathname = urlInfo.pathname || ""; | ||
for(var i = 0,length = Math.ceil(pathname.length)/2; i < length; i++){ | ||
this.http.query[pathname[i * 2]] = pathname[i * 2 + 1] || ""; | ||
this.http.get[pathname[i * 2]] = pathname[i * 2 + 1] || ""; | ||
} | ||
@@ -165,0 +165,0 @@ }; |
@@ -32,5 +32,5 @@ /** | ||
if (!controller) { | ||
var callback = C('empty_controller_callback'); | ||
if (callback && typeof global[callback] == 'function') { | ||
global[callback](this.http.controller, group, this.http); | ||
var event = C('empty_controller_event'); | ||
if (event && E(event, true).length > 0) { | ||
E(event, this.http.controller, group, this.http); | ||
return true; | ||
@@ -81,3 +81,3 @@ }; | ||
match.forEach(function(item){ | ||
var value = self.http.post[item] || self.http.query[item] || ""; | ||
var value = self.http.post[item] || self.http.get[item] || ""; | ||
data.push(value); | ||
@@ -84,0 +84,0 @@ }); |
@@ -75,5 +75,5 @@ /** | ||
if (name === undefined) { | ||
return this.http.query; | ||
return this.http.get; | ||
}; | ||
return this.http.query[name] || ""; | ||
return this.http.get[name] || ""; | ||
}, | ||
@@ -80,0 +80,0 @@ /** |
@@ -54,3 +54,3 @@ var url = require("url"); | ||
for(var i = 0,length = Math.ceil(paths.length)/2; i < length; i++){ | ||
this.http.query[paths[i * 2]] = paths[i * 2 + 1] || ""; | ||
this.http.get[paths[i * 2]] = paths[i * 2 + 1] || ""; | ||
} | ||
@@ -57,0 +57,0 @@ }; |
@@ -81,5 +81,9 @@ /** | ||
this.http.pathname = urlInfo.pathname; | ||
//query只记录?后面的参数 | ||
this.http.query = urlInfo.query; | ||
this.http.get = urlInfo.query; | ||
//get包含路由解析追加的参数 | ||
this.http.get = extend({}, urlInfo.query); | ||
//主机名,带端口 | ||
this.http.host = urlInfo.host; | ||
//主机名,不带端口 | ||
this.http.hostname = urlInfo.hostname; | ||
@@ -86,0 +90,0 @@ |
@@ -723,42 +723,42 @@ var util = require('util'); | ||
field = field.trim(); | ||
var options = this.parseOptions({ | ||
var self = this; | ||
return this.parseOptions({ | ||
"field": field | ||
}); | ||
var multi = false; | ||
if (field.indexOf(",") > -1) { | ||
if (options.limit === undefined && is_number(sepa)) { | ||
options.limit = sepa; | ||
}; | ||
multi = true; | ||
}else{ | ||
options.limit = is_number(sepa) ? sepa : 1; | ||
} | ||
return this.db.select(options).then(function(data){ | ||
if (!data) { | ||
return {}; | ||
}; | ||
if (multi) { | ||
var length = field.split(",").length; | ||
var field = Object.keys(data[0]); | ||
var key = field.shift(); | ||
var key2 = field.shift(); | ||
var cols = {}; | ||
data.forEach(function(item){ | ||
var name = item[key]; | ||
if (length === 2) { | ||
cols[name] = item[key2]; | ||
}else{ | ||
cols[name] = is_string(sepa) ? item.join(sepa) : item; | ||
} | ||
}); | ||
return cols; | ||
}).then(function(options){ | ||
var multi = false; | ||
if (field.indexOf(",") > -1) { | ||
if (options.limit === undefined && is_number(sepa)) { | ||
options.limit = sepa; | ||
}; | ||
multi = true; | ||
}else{ | ||
if (sepa !== true && options.limit == 1) { | ||
return data[0]; | ||
options.limit = is_number(sepa) ? sepa : 1; | ||
} | ||
return self.db.select(options).then(function(data){ | ||
if (data === false) { | ||
return false; | ||
}; | ||
return data.forEach(function(val){ | ||
return val[field]; | ||
}) | ||
} | ||
}); | ||
if (multi) { | ||
var length = field.split(",").length; | ||
var field = Object.keys(data[0]); | ||
var key = field.shift(); | ||
var key2 = field.shift(); | ||
var cols = {}; | ||
data.forEach(function(item){ | ||
var name = item[key]; | ||
if (length === 2) { | ||
cols[name] = item[key2]; | ||
}else{ | ||
cols[name] = is_string(sepa) ? item.join(sepa) : item; | ||
} | ||
}); | ||
return cols; | ||
}else{ | ||
if (sepa !== true && options.limit == 1) { | ||
return data[0]; | ||
}; | ||
return Object.values(data[0])[0]; | ||
} | ||
}); | ||
}) | ||
}, | ||
@@ -875,3 +875,3 @@ /** | ||
var field = data || "*"; | ||
return this.getField(item.toUpperCase() + "(" + field + ") AS tp_" + item); | ||
return this.getField(item.toUpperCase() + "(" + field + ") AS thinkjs_" + item, true); | ||
} | ||
@@ -878,0 +878,0 @@ }); |
@@ -47,7 +47,8 @@ /** | ||
var self = this; | ||
return this._linkID.query(str).then(function(data, err){ | ||
if (data === false) { | ||
self.error = err; | ||
}; | ||
return data; | ||
return this._linkID.query(str).then(function(ret){ | ||
if (ret.errno > 0) { | ||
self.error = ret.errmsg; | ||
return false; | ||
} | ||
return ret.data; | ||
}) | ||
@@ -71,8 +72,8 @@ }, | ||
var self = this; | ||
return this._linkID.query(str).then(function(data, err){ | ||
if (data === false) { | ||
self.error = err; | ||
return this._linkID.query(str).then(function(ret){ | ||
if (ret.errno > 0) { | ||
self.error = ret.errmsg; | ||
return false; | ||
}; | ||
return data ? data.affectedRows : false; | ||
} | ||
return ret.data.affectedRows || 0; | ||
}) | ||
@@ -79,0 +80,0 @@ }, |
@@ -34,5 +34,13 @@ /** | ||
if (err) { | ||
return deferred.resolve(false, err); | ||
return deferred.resolve({ | ||
errno: 1, | ||
errmsg: err, | ||
fields: fields | ||
}); | ||
}; | ||
deferred.resolve(rows || [], fields); | ||
deferred.resolve({ | ||
errno: 0, | ||
data: rows || [], | ||
fields: fields | ||
}); | ||
}) | ||
@@ -39,0 +47,0 @@ return deferred.promise; |
{ | ||
"name": "thinkjs", | ||
"description": "thinkphp web framework for nodejs", | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "welefen", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
162639
4822