修复filter解析值为空字符串或0异常的bug

master 3.0.4
宇天 2018-07-08 18:03:11 +08:00
parent 305e77c23a
commit 29d6b852d4
3 changed files with 25 additions and 9 deletions

View File

@ -1,3 +1,7 @@
# 3.0.4 / 2018-07-09
* 修复filter解析值为空字符串或0异常的bug
# 3.0.3 / 2018-06-21 # 3.0.3 / 2018-06-21
* 修复filter解析空条件异常的bug; * 修复filter解析空条件异常的bug;
* table方法支持 AS 别名。 * table方法支持 AS 别名。

View File

@ -86,20 +86,32 @@ function parse$opt(opt) {
break break
} }
// 比较 // 比较
if (tmp.$lt || tmp.$lte) { if (tmp.hasOwnProperty('$lt') || tmp.hasOwnProperty('$lte')) {
sql += ` ${k} <${tmp.$lte ? '=' : ''} ${tmp.$lt || tmp.$lte} ` let oc = tmp.hasOwnProperty('$lt') ? '<' : '<='
if (tmp.$gt || tmp.$gte) { let val = tmp.hasOwnProperty('$lt') ? tmp.$lt : tmp.$lte
sql += ` AND ${k} >${tmp.$gte ? '=' : ''} ${tmp.$gt || tmp.$gte} `
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 break
} }
if (tmp.$gt || tmp.$gte) { if (tmp.hasOwnProperty('$gt') || tmp.hasOwnProperty('$gte')) {
sql += ` ${k} >${tmp.$gte ? '=' : ''} ${tmp.$gt || tmp.$gte} ` let oc = tmp.hasOwnProperty('$gt') ? '>' : '>='
let val = tmp.hasOwnProperty('$gt') ? tmp.$gt : tmp.$gte
sql += ` ${k} >${oc} ${escape(val)} `
break break
} }
if (tmp.$eq) { if (tmp.hasOwnProperty('$eq')) {
sql += ` ${k} = ${tmp.$eq} ` sql += ` ${k} = ${escape(tmp.$eq)} `
break
}
if (tmp.hasOwnProperty('$ne')) {
sql += ` ${k} <> ${escape(tmp.$ne)} `
break break
} }
default: default:

View File

@ -1,6 +1,6 @@
{ {
"name": "mysqli", "name": "mysqli",
"version": "3.0.3", "version": "3.0.4",
"description": "MySQL tool", "description": "MySQL tool",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {