diff --git a/History.md b/History.md index cac06e2..52f5652 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,7 @@ +# 3.0.4 / 2018-07-09 +* 修复filter解析值为空字符串或0异常的bug + + # 3.0.3 / 2018-06-21 * 修复filter解析空条件异常的bug; * table方法支持 AS 别名。 diff --git a/lib/utils.js b/lib/utils.js index 0cb7806..65a71b1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -86,20 +86,32 @@ function parse$opt(opt) { break } // 比较 - if (tmp.$lt || tmp.$lte) { - sql += ` ${k} <${tmp.$lte ? '=' : ''} ${tmp.$lt || tmp.$lte} ` - if (tmp.$gt || tmp.$gte) { - sql += ` AND ${k} >${tmp.$gte ? '=' : ''} ${tmp.$gt || tmp.$gte} ` + if (tmp.hasOwnProperty('$lt') || tmp.hasOwnProperty('$lte')) { + let oc = tmp.hasOwnProperty('$lt') ? '<' : '<=' + let val = tmp.hasOwnProperty('$lt') ? tmp.$lt : tmp.$lte + + sql += ` ${k} ${oc} ${escape(val)} ` + + if (tmp.hasOwnProperty('$gt') || tmp.hasOwnProperty('$gte')) { + oc = tmp.hasOwnProperty('$gt') ? '>' : '>=' + val = tmp.hasOwnProperty('$gt') ? tmp.$gt : tmp.$gte + sql += ` AND ${k} ${oc} ${escape(val)} ` } break } - if (tmp.$gt || tmp.$gte) { - sql += ` ${k} >${tmp.$gte ? '=' : ''} ${tmp.$gt || tmp.$gte} ` + if (tmp.hasOwnProperty('$gt') || tmp.hasOwnProperty('$gte')) { + let oc = tmp.hasOwnProperty('$gt') ? '>' : '>=' + let val = tmp.hasOwnProperty('$gt') ? tmp.$gt : tmp.$gte + sql += ` ${k} >${oc} ${escape(val)} ` break } - if (tmp.$eq) { - sql += ` ${k} = ${tmp.$eq} ` + if (tmp.hasOwnProperty('$eq')) { + sql += ` ${k} = ${escape(tmp.$eq)} ` + break + } + if (tmp.hasOwnProperty('$ne')) { + sql += ` ${k} <> ${escape(tmp.$ne)} ` break } default: diff --git a/package.json b/package.json index 6bfbae5..b8d0868 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mysqli", - "version": "3.0.3", + "version": "3.0.4", "description": "MySQL tool", "main": "index.js", "dependencies": {