修复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
* 修复filter解析空条件异常的bug;
* table方法支持 AS 别名。

View File

@ -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:

View File

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