From 127ee1f6d2938bb6ab7d1d7089e2d7a60a4df691 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 9 Apr 2018 00:02:06 +0530 Subject: [PATCH] Add ifnull to filterConditions --- backends/database.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backends/database.js b/backends/database.js index 277622c2..5281aeb6 100644 --- a/backends/database.js +++ b/backends/database.js @@ -395,17 +395,18 @@ module.exports = class Database extends Observable { for (let key in filters) { const value = filters[key]; if (value instanceof Array) { + const condition = value[0]; // if its like, we should add the wildcard "%" if the user has not added - if (value[0].toLowerCase()==='includes') { - value[0] = 'like'; + if (condition.toLowerCase()==='includes') { + condition = 'like'; } - if (['like', 'includes'].includes(value[0].toLowerCase()) && !value[1].includes('%')) { + if (['like', 'includes'].includes(condition.toLowerCase()) && !value[1].includes('%')) { value[1] = `%${value[1]}%`; } - conditions.push(`${key} ${value[0]} ?`); + conditions.push(`ifnull(${key}, '') ${condition} ?`); values.push(value[1]); } else { - conditions.push(`${key} = ?`); + conditions.push(`ifnull(${key}, '') = ?`); values.push(value); } }