初始化

This commit is contained in:
robin
2022-08-02 19:21:03 +08:00
parent 73c1343060
commit b7e5ee5fec
27 changed files with 564 additions and 156 deletions
+24 -4
View File
@@ -43,7 +43,11 @@ module.exports = class Api {
* @param {object} value 筛选条件对象.
*/
where(value) {
this.tableWhere = value
if (!this.tableWhere) {
this.tableWhere = value
} else {
Object.assign(this.tableWhere, value)
}
return this
}
@@ -84,12 +88,26 @@ module.exports = class Api {
return this
}
/**
* 模糊查询
* @param {string} value 关键字:你好.
* @param {array} fieldList 字段列表['createdAt'].
*/
search({value, fieldList}) {
if (!value|| !fieldList) return this
if (!this.tableWhere) this.tableWhere = {}
this.tableWhere['$or'] = fieldList.map(item => {
return {[item]: {'$like': `%${value || ''}%`}}
})
return this
}
/**
* 常用时间筛选
* @param {string|array|Number} value 时间内容:按时间段:['2000-1-1','2000-1-2'],按常用时间:day,按最近60分钟:60.
* @param {string} field 时间字段(默认createdAt字段)
*/
time(value, field) {
time({value, field}) {
if (!this.tableName) {
throw "请传表名"
}
@@ -251,7 +269,7 @@ module.exports = class Api {
* @param {number} min 字段减小后的值不能小于最小值
* @param {number} setValue 如果减小后的字段小于min,设置字段值为n
*/
async setDec(min, setValue) {
async setDec({min, setValue}) {
if (!this.tableName) {
throw "请传表名"
}
@@ -317,7 +335,7 @@ module.exports = class Api {
* @param {number} max 字段增加后的值不能大于最大值
* @param {number} setValue 如果增加后的字段大于max,设置字段值为n
*/
async setInc(max, setValue) {
async setInc({max, setValue}) {
if (!this.tableName) {
throw "请传表名"
}
@@ -494,6 +512,7 @@ module.exports = class Api {
...options
}
)
this.init()
return res
}
@@ -523,6 +542,7 @@ module.exports = class Api {
...options
}
)
this.init()
return res
}