Comparing version 0.1.18 to 0.1.19
@@ -105,3 +105,3 @@ var fs = require("fs"); | ||
*/ | ||
global.is_date = function(){ | ||
global.is_date = function(obj){ | ||
return Object.prototype.toString.call(obj) == '[object Date]'; | ||
@@ -108,0 +108,0 @@ } |
@@ -23,2 +23,2 @@ //该文件内容为原生对象的扩展 | ||
return count; | ||
} | ||
} |
@@ -236,3 +236,3 @@ /** | ||
json: function(data, jsonp){ | ||
this.header("Content-Type", C("json_content_type") + ";charset=" + C("charset")); | ||
this.header("Content-Type", C("json_content_type") + ";charset=" + C("encoding")); | ||
var callback = this.get(C("url_callback_name")); | ||
@@ -239,0 +239,0 @@ //过滤callback值里的非法字符 |
@@ -49,3 +49,3 @@ /** | ||
*/ | ||
ids: function(value){ | ||
ids: function(value, split){ | ||
if (is_number(value)) { | ||
@@ -59,3 +59,3 @@ value = this.id(value); | ||
if (is_string(value)) { | ||
value = value.split(","); | ||
value = value.split(split || ","); | ||
}; | ||
@@ -66,7 +66,5 @@ if (!is_array(value)) { | ||
return value.filter(function(item){ | ||
item = item.trim(); | ||
item = (item + "").trim(); | ||
item = parseInt(item, 10); | ||
if (item > 0) { | ||
return item; | ||
}; | ||
return item; | ||
}) | ||
@@ -84,3 +82,23 @@ }, | ||
}; | ||
return arr.indexOf(value) > -1; | ||
if(arr.indexOf(value) > -1){ | ||
return value; | ||
} | ||
return ""; | ||
}, | ||
/** | ||
* 将字符串切割为数组 | ||
* @param {[type]} value [description] | ||
* @param {[type]} split [description] | ||
* @return {[type]} [description] | ||
*/ | ||
strs: function(value, split){ | ||
if (is_string(value)) { | ||
value = value.split(split || ","); | ||
}; | ||
if (!is_array(value)) { | ||
return []; | ||
}; | ||
return value.filter(function(item){ | ||
return (item + "").trim(); | ||
}) | ||
} | ||
@@ -87,0 +105,0 @@ } |
@@ -201,4 +201,7 @@ var util = require('util'); | ||
return this.db.getFields(table).then(function(data){ | ||
if (data === false) { | ||
return []; | ||
}; | ||
var fields = { | ||
"_field": Object.keys(data), | ||
"_field": Object.keys(data || {}), | ||
"_autoinc": false | ||
@@ -372,5 +375,7 @@ }; | ||
*/ | ||
parseOptions: function(options){ | ||
parseOptions: function(options, extraOptions){ | ||
var self = this; | ||
options = this.parseWhereOptions(options); | ||
options = extend(this.options, options); | ||
options = extend(options, extraOptions); | ||
// 查询过后清空sql表达式组装 避免影响下次查询 | ||
@@ -384,5 +389,9 @@ this.options = {}; | ||
options.table = this.getTableName(); | ||
promise = this.promise.then(function(){ | ||
return self.fields["_field"]; | ||
}); | ||
if (is_empty(self.fields["_field"])) { | ||
promise = this.promise.then(function(){ | ||
return self.fields["_field"]; | ||
}); | ||
}else{ | ||
promise = get_promise(self.fields["_field"]); | ||
} | ||
} | ||
@@ -554,25 +563,2 @@ //数据表别名 | ||
delete: function(options){ | ||
if (is_empty(options) && is_empty(this.options.where)) { | ||
// 如果删除条件为空 则删除当前数据对象所对应的记录 | ||
if (!is_empty(this._data) && this._data[this.getPk()]) { | ||
return this.delete(this._data[this.getPk()]); | ||
}else{ | ||
return get_promise(false); | ||
} | ||
}; | ||
var pkValue = ""; | ||
if (is_number(options) || is_string(options)) { | ||
var pk = this.getPk(); | ||
options += ""; | ||
var where = {}; | ||
if (options.indexOf(',') > -1) { | ||
where[pk] = ["IN", options]; | ||
}else{ | ||
where[pk] = options; | ||
} | ||
pkValue = where[pk]; | ||
options = { | ||
"where": where | ||
} | ||
}; | ||
var self = this; | ||
@@ -612,3 +598,3 @@ return this.parseOptions(options).then(function(options){ | ||
var pk = self.getPk(); | ||
if (is_empty(self.options.where)) { | ||
if (is_empty(self.options.where) && is_empty(options.where)) { | ||
// 如果存在主键数据 则自动作为更新条件 | ||
@@ -670,6 +656,6 @@ if (!is_empty(data[pk])) { | ||
/** | ||
* 查询语句的options | ||
* 解析options中简洁的where条件 | ||
* @return {[type]} [description] | ||
*/ | ||
queryOptions: function(options){ | ||
parseWhereOptions: function(options){ | ||
if (is_number(options) || is_string(options)) { | ||
@@ -700,5 +686,5 @@ var pk = this.getPk(); | ||
var self = this; | ||
options = this.queryOptions(options); | ||
options.limit = 1; | ||
return this.parseOptions(options).then(function(options){ | ||
return this.parseOptions(options, { | ||
limit: 1 | ||
}).then(function(options){ | ||
return self.db.select(options).then(function(data){ | ||
@@ -715,3 +701,2 @@ return data ? data[0] : []; | ||
var self = this; | ||
options = this.queryOptions(options); | ||
return this.parseOptions(options).then(function(options){ | ||
@@ -754,3 +739,3 @@ return self.db.select(options); | ||
var length = field.split(",").length; | ||
var field = Object.keys(data[0]); | ||
var field = Object.keys(data[0] || {}); | ||
var key = field.shift(); | ||
@@ -772,3 +757,3 @@ var key2 = field.shift(); | ||
}; | ||
return Object.values(data[0])[0]; | ||
return Object.values(data[0] || {})[0]; | ||
} | ||
@@ -857,3 +842,3 @@ }); | ||
var field = self.fields["_field"]; | ||
field.forEach(function(item){ | ||
(field || []).forEach(function(item){ | ||
var name = "getBy" + parse_name(item, 1); | ||
@@ -860,0 +845,0 @@ self[name] = function(arg){ |
@@ -89,2 +89,5 @@ /** | ||
return this.query(sql).then(function(data){ | ||
if (data === false) { | ||
return false; | ||
}; | ||
var ret = {}; | ||
@@ -91,0 +94,0 @@ data.forEach(function(item){ |
@@ -32,12 +32,20 @@ /** | ||
var data = file_get_contents(this.file); | ||
data = JSON.parse(data || "{}"); | ||
data = JSON.parse(data || "{}") || {}; | ||
this.data = data; | ||
var self = this; | ||
process.nextTick(function(){ | ||
deferrd.resolve(self.data[name]); | ||
}) | ||
}; | ||
var self = this; | ||
process.nextTick(function(){ | ||
deferrd.resolve(self.data[name]); | ||
}) | ||
return deferrd.promise; | ||
}, | ||
/** | ||
* 设置session | ||
* @param {[type]} name [description] | ||
* @param {[type]} value [description] | ||
*/ | ||
set: function(name, value){ | ||
if (this.data === null) { | ||
this.data = {}; | ||
}; | ||
this.data[name] = value; | ||
@@ -53,3 +61,3 @@ }, | ||
flush: function(){ | ||
var data = JSON.stringify(this.data); | ||
var data = JSON.stringify(this.data || {}); | ||
file_put_contents(this.file, data); | ||
@@ -56,0 +64,0 @@ } |
{ | ||
"name": "thinkjs", | ||
"description": "thinkphp web framework for nodejs", | ||
"version": "0.1.18", | ||
"version": "0.1.19", | ||
"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
170568
5091