Comparing version 0.3.2 to 0.3.3
@@ -75,2 +75,3 @@ var fs = require("fs"); | ||
//常用类的基类 | ||
["Cache", "Behavior", "Controller", "Session", "Model", "Db"].forEach(function(item){ | ||
@@ -77,0 +78,0 @@ global[item] = function(super_, obj){ |
@@ -10,2 +10,3 @@ /** | ||
global.THINK_LIB_PATH = THINK_PATH + "/Lib"; | ||
global.THINK_EXTEND_PATH = THINK_PATH + "/Extend"; | ||
//应用路径设置 | ||
@@ -85,7 +86,2 @@ var config = { | ||
}); | ||
var config_file = CONF_PATH + "/config.js"; | ||
if (!isFile(config_file)) { | ||
var data = 'module.exports = {\n\t//"配置项": "配置值"\n};' | ||
fs.writeFileSync(config_file, data); | ||
}; | ||
copyFiles(); | ||
@@ -106,3 +102,4 @@ }else{ | ||
THINK_PATH + "/Tpl/common.js", | ||
THINK_PATH + "/Tpl/ctrl.sh" | ||
THINK_PATH + "/Tpl/ctrl.sh", | ||
THINK_PATH + "/Tpl/config.js" | ||
]; | ||
@@ -113,3 +110,4 @@ var dstFiles = [ | ||
COMMON_PATH + "/common.js", | ||
APP_PATH + "/../ctrl.sh" | ||
APP_PATH + "/../ctrl.sh", | ||
CONF_PATH + "/config.js" | ||
]; | ||
@@ -116,0 +114,0 @@ dstFiles.forEach(function(file, i){ |
@@ -20,3 +20,5 @@ /** | ||
"Valid": THINK_LIB_PATH + "/Core/Valid.class.js", | ||
"View": THINK_LIB_PATH + "/Core/View.class.js" | ||
"View": THINK_LIB_PATH + "/Core/View.class.js", | ||
//高级模型 | ||
"AdvModel": THINK_EXTEND_PATH + "/Model/AdvModel.class.js" | ||
} |
@@ -17,3 +17,3 @@ /** | ||
var pathname = this.http.pathname; | ||
if (!pathname || !this.options.url_route_on) { | ||
if (!this.options.url_route_on) { | ||
return false; | ||
@@ -20,0 +20,0 @@ }; |
@@ -445,3 +445,3 @@ var util = require('util'); | ||
/** | ||
* 数据插入之前操作 | ||
* 数据插入之前操作,可以返回一个promise | ||
* @param {[type]} data [description] | ||
@@ -451,7 +451,7 @@ * @param {[type]} options [description] | ||
*/ | ||
_beforeInsert: function(data, options){ | ||
_beforeAdd: function(data, options){ | ||
return data; | ||
}, | ||
/** | ||
* 数据插入之后操作 | ||
* 数据插入之后操作,可以返回一个promise | ||
* @param {[type]} data [description] | ||
@@ -461,3 +461,3 @@ * @param {[type]} options [description] | ||
*/ | ||
_afterInsert: function(data, options){ | ||
_afterAdd: function(data, options){ | ||
return data; | ||
@@ -485,16 +485,23 @@ }, | ||
data = self.parseData(data); | ||
data = self._beforeInsert(data, options); | ||
//如果_beforeInsert返回false,则直接返回 | ||
if (data === false) { | ||
return getPromise("_beforeInsert return false", true); | ||
}; | ||
return self.db.insert(data, options, replace).then(function(){ | ||
//获取插入的ID | ||
var id = self.db.getLastInsertId(); | ||
if (id) { | ||
data[self.getPk()] = id; | ||
data = self._beforeAdd(data, options); | ||
return getPromise(data).then(function(data){ | ||
//如果_beforeAdd返回false,则直接返回 | ||
if (data === false) { | ||
return getPromise("_beforeAdd return false", true); | ||
}; | ||
data = self._afterInsert(data, options); | ||
return data[self.getPk()]; | ||
}); | ||
return self.db.insert(data, options, replace).then(function(){ | ||
//获取插入的ID | ||
var id = self.db.getLastInsertId(); | ||
if (id) { | ||
data[self.getPk()] = id; | ||
}; | ||
data = self._afterAdd(data, options); | ||
return getPromise(data).then(function(data){ | ||
if (data === false) { | ||
return getPromise("_afterAdd return false", true); | ||
}; | ||
return data[self.getPk()]; | ||
}) | ||
}); | ||
}) | ||
}); | ||
@@ -520,2 +527,9 @@ }, | ||
/** | ||
* 删除后续操作 | ||
* @return {[type]} [description] | ||
*/ | ||
_afterDelete: function(data, options){ | ||
return data; | ||
}, | ||
/** | ||
* 删除数据 | ||
@@ -527,8 +541,28 @@ * @return {[type]} [description] | ||
return this.parseOptions(options).then(function(options){ | ||
return self.db.delete(options); | ||
return self.db.delete(options).then(function(data){ | ||
data = self._afterDelete(data, options); | ||
return getPromise(data).then(function(data){ | ||
if (data === false) { | ||
return getPromise("_afterDelete return false", true); | ||
}; | ||
return data; | ||
}) | ||
}); | ||
}) | ||
}, | ||
/** | ||
* 更新前置操作 | ||
* @param {[type]} data [description] | ||
* @param {[type]} options [description] | ||
* @return {[type]} [description] | ||
*/ | ||
_beforeUpdate: function(data, options){ | ||
return data; | ||
}, | ||
/** | ||
* 更新后置操作 | ||
* @param {[type]} data [description] | ||
* @param {[type]} options [description] | ||
* @return {[type]} [description] | ||
*/ | ||
_afterUpdate: function(data, options){ | ||
@@ -555,29 +589,33 @@ return data; | ||
data = self._beforeUpdate(data, options); | ||
if ( data === false) { | ||
return getPromise("_beforeUpdate return false", true); | ||
}; | ||
var pkValue = ""; | ||
var pk = self.getPk(); | ||
if (isEmpty(self.options.where) && isEmpty(options.where)) { | ||
// 如果存在主键数据 则自动作为更新条件 | ||
if (!isEmpty(data[pk])) { | ||
var where = {}; | ||
where[pk] = data[pk]; | ||
options.where = where; | ||
pkValue = data[pk]; | ||
delete data[pk]; | ||
}else{ | ||
return getPromise(L("_OPERATION_WRONG_"), true); | ||
} | ||
}; | ||
return self.db.update(data, options).then(function(data){ | ||
if (data) { | ||
if (pkValue) { | ||
return getPromise(data).then(function(data){ | ||
if ( data === false) { | ||
return getPromise("_beforeUpdate return false", true); | ||
}; | ||
var pkValue = ""; | ||
var pk = self.getPk(); | ||
if (isEmpty(self.options.where) && isEmpty(options.where)) { | ||
// 如果存在主键数据 则自动作为更新条件 | ||
if (!isEmpty(data[pk])) { | ||
var where = {}; | ||
where[pk] = data[pk]; | ||
options.where = where; | ||
pkValue = data[pk]; | ||
delete data[pk]; | ||
}else{ | ||
return getPromise(L("_OPERATION_WRONG_"), true); | ||
} | ||
}; | ||
return self.db.update(data, options).then(function(data){ | ||
if (pkValue) { | ||
data[pk] = pkValue; | ||
}; | ||
data = self._afterUpdate(data, options); | ||
return data.affectedRows; | ||
}; | ||
return false; | ||
}) | ||
return getPromise(data).then(function(data){ | ||
if (data === false) { | ||
return getPromise("_afterUpdate return false", true); | ||
}; | ||
return data.affectedRows; | ||
}) | ||
}) | ||
}); | ||
}) | ||
@@ -637,2 +675,9 @@ }, | ||
/** | ||
* find查询后置操作 | ||
* @return {[type]} [description] | ||
*/ | ||
_afterFind: function(result, options){ | ||
return result; | ||
}, | ||
/** | ||
* 查询一条数据 | ||
@@ -647,6 +692,15 @@ * @return 返回一个promise | ||
return self.db.select(options).then(function(data){ | ||
return data ? data[0] : []; | ||
var result = data ? data[0] : []; | ||
return getPromise(self._afterFind(result, options)).then(function(result){ | ||
if (result === false) { | ||
return getPromise("_afterFind return false", true); | ||
}; | ||
return result; | ||
}) | ||
}) | ||
}); | ||
}, | ||
_afterSelect: function(result, options){ | ||
return result; | ||
}, | ||
/** | ||
@@ -659,3 +713,9 @@ * 查询数据 | ||
return this.parseOptions(options).then(function(options){ | ||
return self.db.select(options); | ||
var result = self.db.select(options); | ||
return getPromise(self._afterSelect(result, options)).then(function(result){ | ||
if (result === false) { | ||
return getPromise("_afterSelect return false", true); | ||
}; | ||
return result; | ||
}) | ||
}); | ||
@@ -716,2 +776,13 @@ }, | ||
/** | ||
* 根据某个字段值获取一条数据 | ||
* @param {[type]} name [description] | ||
* @param {[type]} value [description] | ||
* @return {[type]} [description] | ||
*/ | ||
getBy: function(name, value){ | ||
var where = {}; | ||
where[name] = value; | ||
return this.where(where).find(); | ||
}, | ||
/** | ||
* SQL查询 | ||
@@ -797,24 +868,3 @@ * @return {[type]} [description] | ||
//追加的方法 | ||
var methods = { | ||
initMethod: function(){ | ||
var self = this; | ||
this.promise.then(function(){ | ||
var field = self.fields["_field"]; | ||
(field || []).forEach(function(item){ | ||
var name = "getBy" + parseName(item, 1); | ||
self[name] = function(arg){ | ||
var where = {} | ||
where[item] = arg; | ||
return this.where(where).find(); | ||
} | ||
var fieldName = "getFieldBy" + parseName(item, 1); | ||
self[fieldName] = function(arg, arg1){ | ||
var where = {}; | ||
where[item] = arg; | ||
return this.where(where).getField(arg1); | ||
} | ||
}) | ||
}); | ||
} | ||
}; | ||
var methods = {}; | ||
// 链操作方法列表 | ||
@@ -821,0 +871,0 @@ var methodNameList = [ |
@@ -0,1 +1,3 @@ | ||
//自动加载进行识别的路径 | ||
var autoloadPaths = {} | ||
/** | ||
@@ -15,6 +17,8 @@ * [exports description] | ||
}; | ||
//加载文件 | ||
this.loadFiles(); | ||
//合并自动加载的路径 | ||
this.mergeAutoloadPath(); | ||
//thinkRequire的autoload | ||
registerAutoload(this.autoload); | ||
//加载文件 | ||
this.loadFiles(); | ||
//debug模式 | ||
@@ -152,3 +156,3 @@ if (APP_DEBUG) { | ||
log_process_pid: function(){ | ||
var isMaster = require('cluster').isMaster | ||
var isMaster = require('cluster').isMaster; | ||
if (C('log_process_pid') && isMaster) { | ||
@@ -167,10 +171,14 @@ var pidFile = DATA_PATH + "/app.pid"; | ||
}, | ||
//thinkRequire的自动加载 | ||
autoload: function(cls){ | ||
/** | ||
* 合并autoload的path | ||
* @return {[type]} [description] | ||
*/ | ||
mergeAutoloadPath: function(){ | ||
var cls = "__CLASS__"; | ||
var sysfile = cls + ".class.js"; | ||
var file = cls + C("class_file_suffix"); | ||
var sysCls = { | ||
var sysAutoloadPath = { | ||
"Behavior": [ | ||
THINK_LIB_PATH + "/Behavior/" + sysfile, | ||
LIB_PATH + "/Behavior/" + file | ||
LIB_PATH + "/Behavior/" + file, | ||
THINK_LIB_PATH + "/Behavior/" + sysfile | ||
], | ||
@@ -210,13 +218,25 @@ "Model": [ | ||
}; | ||
paths = paths.map(function(path){ | ||
return path.replace(/__CLASS__/g, cls); | ||
}); | ||
sysCls[type] = paths; | ||
var override = false; | ||
if (isBoolean(paths[0])) { | ||
override = paths[0]; | ||
paths.shift(); | ||
}; | ||
if (override) { | ||
sysAutoloadPath[type] = paths; | ||
}else{ | ||
paths.push.apply(paths, sysAutoloadPath[type]); | ||
sysAutoloadPath[type] = paths; | ||
} | ||
} | ||
for(var name in sysCls){ | ||
autoloadPaths = sysAutoloadPath; | ||
}, | ||
//thinkRequire的自动加载 | ||
autoload: function(cls){ | ||
for(var name in autoloadPaths){ | ||
var length = name.length; | ||
if (cls.substr(0 - length) === name) { | ||
var list = sysCls[name]; | ||
var list = autoloadPaths[name]; | ||
var filepath = ''; | ||
list.some(function(item){ | ||
item = item.replace(/__CLASS__/g, cls); | ||
if (isFile(item)) { | ||
@@ -223,0 +243,0 @@ filepath = item; |
@@ -59,2 +59,4 @@ /** | ||
return self.http.end(); | ||
}).catch(function(){ | ||
return self.http.end(); | ||
}) | ||
@@ -61,0 +63,0 @@ }, |
{ | ||
"name": "thinkjs", | ||
"description": "thinkphp web framework for nodejs", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"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
184538
55
5509