Comparing version 0.1.9 to 0.1.10
@@ -102,2 +102,10 @@ var fs = require("fs"); | ||
/** | ||
* 是否是个错误 | ||
* @param {[type]} obj [description] | ||
* @return {Boolean} [description] | ||
*/ | ||
global.is_error = function(obj){ | ||
return Object.prototype.toString.call(obj) == '[object Error]'; | ||
} | ||
/** | ||
* 判斷對象是否為空 | ||
@@ -166,4 +174,7 @@ * @param {[type]} obj | ||
global.is_number_string = function(obj){ | ||
obj = obj + ""; | ||
return ((parseFloat(obj, 10) || "")+"").length == obj.length; | ||
var parseValue = parseFloat(obj); | ||
if (isNaN(parseValue)) { | ||
return false; | ||
}; | ||
return (parseValue + "").length == (obj + "").length | ||
} | ||
@@ -214,4 +225,4 @@ /** | ||
var mode = stats.mode; | ||
var uid = process.getuid(); | ||
var gid = process.getgid(); | ||
var uid = process.getuid ? process.getuid() : 0; | ||
var gid = process.getgid ? process.getgid() : 0; | ||
var owner = uid == stats.uid; | ||
@@ -331,2 +342,2 @@ var group = gid == stats.gid; | ||
return deferred.promise; | ||
} | ||
} |
@@ -32,2 +32,3 @@ /** | ||
auto_send_content_type: true, //是否自动发送Content-Type,默认值为`tpl_content_type`配置值 | ||
empty_controller_callback: "", //controller不存在时调用的回调函数,可以在Common/common.js里定义全局函数 | ||
@@ -45,3 +46,2 @@ cookie_domain: "", //cookie有效域名 | ||
db_type: "mysql", // 数据库类型 | ||
@@ -86,2 +86,7 @@ db_host: "localhost",// 服务器地址 | ||
memcache_port: 11211, //memecache端口 | ||
html_cache_on: false, //HTML静态缓存 | ||
html_cache_time: 60, //缓存时间 | ||
html_cache_rules: {}, //缓存规则 | ||
html_cache_file_suffix: ".html", //缓存文件后缀名 | ||
}; |
@@ -8,3 +8,3 @@ /** | ||
options: { | ||
deny_ip: [] | ||
deny_ip: [] //阻止的ip列表 | ||
}, | ||
@@ -11,0 +11,0 @@ run: function(){ |
@@ -13,2 +13,7 @@ /** | ||
}, | ||
/** | ||
* 解析模版文件 | ||
* @param {[type]} templateFile [description] | ||
* @return {[type]} [description] | ||
*/ | ||
parseTemplateFile: function(templateFile){ | ||
@@ -15,0 +20,0 @@ templateFile = templateFile || ""; |
@@ -28,6 +28,13 @@ /** | ||
}catch(e){ | ||
console.log(e); | ||
//console.log(e); | ||
} | ||
} | ||
if (!controller) { | ||
var callback = C('empty_controller_callback'); | ||
if (callback && typeof global[callback] == 'function') { | ||
global[callback](this.http.controller, group, this.http); | ||
return true; | ||
}; | ||
}; | ||
if (!controller) { | ||
try{ | ||
@@ -34,0 +41,0 @@ controller = A(group + "/" + "Empty", this.http); |
@@ -175,5 +175,4 @@ /** | ||
redirect: function(url, code){ | ||
this.http.res.statusCode = code || 302; | ||
this.http.res.setHeader("Location", url); | ||
this.http.end(); | ||
this.http.redirect(url, code); | ||
return this; | ||
}, | ||
@@ -180,0 +179,0 @@ /** |
@@ -9,2 +9,6 @@ var url = require("url"); | ||
return { | ||
/** | ||
* where条件里的表达式 | ||
* @type {Object} | ||
*/ | ||
comparison: { | ||
@@ -22,3 +26,11 @@ 'eq': '=', | ||
}, | ||
/** | ||
* 用于查询的sql语句,所有select语句根据该语句解析 | ||
* @type {String} | ||
*/ | ||
selectSql: 'SELECT%DISTINCT% %FIELD% FROM %TABLE%%JOIN%%WHERE%%GROUP%%HAVING%%ORDER%%LIMIT% %UNION%%COMMENT%', | ||
/** | ||
* 初始化一些属性,不能直接放在原型上 | ||
* @return {[type]} [description] | ||
*/ | ||
initAttr: function(){ | ||
@@ -55,3 +67,9 @@ // 数据库类型 | ||
// 数据库表达式 | ||
// 当前错误信息 | ||
this.error = ""; | ||
}, | ||
/** | ||
* 初始化,类似于constrcut,类实例化时自动调用 | ||
* @return {[type]} [description] | ||
*/ | ||
init: function(){ | ||
@@ -86,3 +104,3 @@ this.initAttr(); | ||
/** | ||
* 解析字段名 | ||
* 解析字段名,具体的数据库里实现 | ||
* @param {[type]} key [description] | ||
@@ -297,2 +315,8 @@ * @return {[type]} [description] | ||
}, | ||
/** | ||
* 解析一些特殊的where条件 | ||
* @param {[type]} key [description] | ||
* @param {[type]} val [description] | ||
* @return {[type]} [description] | ||
*/ | ||
parseThinkWhere: function(key, val){ | ||
@@ -329,3 +353,3 @@ var whereStr = ""; | ||
/** | ||
* 解析limit | ||
* 解析limit,对非法的limit进行过滤 | ||
* @param {[type]} limit [description] | ||
@@ -335,2 +359,10 @@ * @return {[type]} [description] | ||
parseLimit: function(limit){ | ||
limit = (limit + "").split(",").slice(0, 2); | ||
var flag = limit.every(function(item){ | ||
return is_number_string(item); | ||
}); | ||
if (!flag) { | ||
return ""; | ||
}; | ||
limit = limit.join(","); | ||
return limit ? (" LIMIT " + limit) : ""; | ||
@@ -388,14 +420,39 @@ }, | ||
}, | ||
/** | ||
* 解析group | ||
* @param {[type]} group [description] | ||
* @return {[type]} [description] | ||
*/ | ||
parseGroup: function(group){ | ||
return group ? (" GROUP BY " + group) : ""; | ||
}, | ||
/** | ||
* 解析having | ||
* @param {[type]} having [description] | ||
* @return {[type]} [description] | ||
*/ | ||
parseHaving: function(having){ | ||
return having ? (" HAVING " + having) : ""; | ||
}, | ||
/** | ||
* 解析注释,一般情况下用不到 | ||
* @param {[type]} comment [description] | ||
* @return {[type]} [description] | ||
*/ | ||
parseComment: function(comment){ | ||
return comment ? (" /* " + comment + "*/") : ""; | ||
}, | ||
/** | ||
* 解析Distinct | ||
* @param {[type]} distinct [description] | ||
* @return {[type]} [description] | ||
*/ | ||
parseDistinct: function(distinct){ | ||
return distinct ? (" Distinct " + distinct) : ""; | ||
}, | ||
/** | ||
* 解析Union | ||
* @param {[type]} union [description] | ||
* @return {[type]} [description] | ||
*/ | ||
parseUnion: function(union){ | ||
@@ -420,2 +477,7 @@ if (!union) { | ||
}, | ||
/** | ||
* 解析Lock | ||
* @param {[type]} lock [description] | ||
* @return {[type]} [description] | ||
*/ | ||
parseLock: function(lock){ | ||
@@ -434,5 +496,6 @@ if (!lock) { | ||
options = options || {}; | ||
//根据page生成limit | ||
if ("page" in options) { | ||
// 根据页数计算limit | ||
var page = options.page || ""; | ||
var page = options.page + ""; | ||
var listRows = 0; | ||
@@ -445,26 +508,10 @@ if (page.indexOf(",") > -1) { | ||
page = parseInt(page, 10) || 1; | ||
listRows = listRows || options.limit || C('db_nums_per_page'); | ||
if (!listRows) { | ||
listRows = is_number_string(options.limit) ? options.limit : C('db_nums_per_page'); | ||
}; | ||
var offset = listRows * (page - 1); | ||
options.limit = offset + "," + listRows; | ||
}; | ||
// 由于缓存读取返回的是个promise,所以这里暂不支持 | ||
// | ||
// SQL创建缓存 | ||
// var key = ""; | ||
// if (C('db_sql_build_cache')) { | ||
// key = md5(JSON.stringify(options)); | ||
// //使用默认对象的缓存方式,这样是直接获取 | ||
// value = S(key, undefined, true); | ||
// if (value !== false) { | ||
// return value; | ||
// }; | ||
// }; | ||
var sql = this.parseSql(this.selectSql, options); | ||
sql += this.parseLock(options.lock); | ||
// if (key) { | ||
// S(key, sql, { | ||
// type: true, | ||
// expire: 0 | ||
// }); | ||
// }; | ||
return sql; | ||
@@ -655,7 +702,23 @@ }, | ||
}, | ||
setModel: function(model){ | ||
this.model = model; | ||
}, | ||
/** | ||
* 获取上次的sql语句 | ||
* @param {[type]} model [description] | ||
* @return {[type]} [description] | ||
*/ | ||
getLastSql: function(model){ | ||
return model ? this.modelSql[model] : this.queryStr; | ||
}, | ||
/** | ||
* 获取错误信息 | ||
* @return {[type]} [description] | ||
*/ | ||
getError: function(){ | ||
return this.error; | ||
}, | ||
/** | ||
* 设置模型 | ||
* @param {[type]} model [description] | ||
*/ | ||
setModel: function(model){ | ||
return this.model = model; | ||
} | ||
@@ -662,0 +725,0 @@ } |
@@ -90,5 +90,16 @@ /** | ||
var res = { | ||
/** | ||
* 发送header | ||
* @param {[type]} name [description] | ||
* @param {[type]} value [description] | ||
*/ | ||
setHeader: function(name, value){ | ||
this.res.setHeader(name, value); | ||
}, | ||
/** | ||
* 设置cookie | ||
* @param {[type]} name [description] | ||
* @param {[type]} value [description] | ||
* @param {[type]} options [description] | ||
*/ | ||
setCookie: function(name, value, options){ | ||
@@ -121,2 +132,17 @@ options = options || {}; | ||
}, | ||
/** | ||
* url跳转 | ||
* @param {[type]} url [description] | ||
* @param {[type]} code [description] | ||
* @return {[type]} [description] | ||
*/ | ||
redirect: function(url, code){ | ||
this.res.statusCode = code || 302; | ||
this.res.setHeader("Location", url); | ||
this.end(); | ||
}, | ||
/** | ||
* 结束URL | ||
* @return {[type]} [description] | ||
*/ | ||
end: function(){ | ||
@@ -123,0 +149,0 @@ tag("before_res_end", this); |
@@ -9,3 +9,3 @@ var util = require('util'); | ||
var _linkNum = []; | ||
var _db = {}; | ||
var _db = []; | ||
return { | ||
@@ -315,2 +315,7 @@ initAttr: function(){ | ||
}, | ||
/** | ||
* 联合查询 | ||
* @param {[type]} join [description] | ||
* @return {[type]} [description] | ||
*/ | ||
join: function(join){ | ||
@@ -327,2 +332,6 @@ if (is_array(join)) { | ||
}, | ||
/** | ||
* 获取错误信息 | ||
* @return {[type]} [description] | ||
*/ | ||
getError: function(){ | ||
@@ -332,2 +341,9 @@ return this.error; | ||
/** | ||
* 获取数据库错误信息 | ||
* @return {[type]} [description] | ||
*/ | ||
getDbError: function(){ | ||
return this.db.getError(); | ||
}, | ||
/** | ||
* 生成查询SQL 可用于子查询 | ||
@@ -334,0 +350,0 @@ * @param {[type]} options [description] |
@@ -13,3 +13,2 @@ /** | ||
}; | ||
this.errmsg = ""; | ||
}, | ||
@@ -49,6 +48,14 @@ /** | ||
var self = this; | ||
return this._linkID.query(str).otherwise(function(err){ | ||
self.errmsg = err; | ||
}); | ||
return this._linkID.query(str).then(function(data, err){ | ||
if (data === false) { | ||
self.error = err; | ||
}; | ||
return data; | ||
}) | ||
}, | ||
/** | ||
* 执行一条sql, 返回影响的行数 | ||
* @param {[type]} str [description] | ||
* @return {[type]} [description] | ||
*/ | ||
execute: function(str){ | ||
@@ -65,5 +72,7 @@ this.initConnect(false); | ||
var self = this; | ||
return this._linkID.query(str).otherwise(function(err){ | ||
self.errmsg = err; | ||
}).then(function(data){ | ||
return this._linkID.query(str).then(function(data, err){ | ||
if (data === false) { | ||
self.error = err; | ||
return false; | ||
}; | ||
return data ? data.affectedRows : false; | ||
@@ -113,9 +122,2 @@ }) | ||
/** | ||
* 获取错误信息 | ||
* @return {[type]} [description] | ||
*/ | ||
getError: function(){ | ||
return this.errmsg; | ||
}, | ||
/** | ||
* 关闭连接 | ||
@@ -122,0 +124,0 @@ * @return {[type]} [description] |
@@ -48,3 +48,3 @@ /** | ||
/** | ||
* 刷新数据,将数据写入到文件 | ||
* 刷新数据,将数据写入到文件,在request end的时候调用该方法 | ||
* @return {[type]} [description] | ||
@@ -51,0 +51,0 @@ */ |
@@ -28,3 +28,5 @@ /** | ||
query: function(sql){ | ||
console.log("SQL: " + sql); | ||
if (APP_DEBUG) { | ||
console.log(sql); | ||
}; | ||
var deferred = when.defer(); | ||
@@ -31,0 +33,0 @@ this.connect.query(sql, function(err, rows, fields){ |
{ | ||
"name": "thinkjs", | ||
"description": "thinkphp web framework for nodejs", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"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
161322
54
4784