From 29d6b852d4450885549a5894f24bcdf0b4bad3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Sun, 8 Jul 2018 18:03:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dfilter=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=80=BC=E4=B8=BA=E7=A9=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=88=96?= =?UTF-8?q?0=E5=BC=82=E5=B8=B8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- History.md | 4 ++++ lib/utils.js | 28 ++++++++++++++++++++-------- package.json | 2 +- 3 files changed, 25 insertions(+), 9 deletions(-) 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": {