From d8d3c56bae6de71a8b55356056cf6edc1fc50bd4 Mon Sep 17 00:00:00 2001 From: iammapping Date: Thu, 19 Jun 2014 13:40:12 +0800 Subject: [PATCH] add a "NOT LIKE" comparator --- lib/Comparators.js | 3 +++ lib/Where.js | 7 +++++++ test/integration/test-where.js | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/lib/Comparators.js b/lib/Comparators.js index 5f0e450..5ace73c 100644 --- a/lib/Comparators.js +++ b/lib/Comparators.js @@ -7,6 +7,9 @@ exports.not_between = function (a, b) { exports.like = function (expr) { return createSpecialObject({ expr: expr }, 'like'); }; +exports.not_like = function (expr) { + return createSpecialObject({ expr: expr }, 'not_like'); +}; exports.eq = function (v) { return createSpecialObject({ val: v }, 'eq'); diff --git a/lib/Where.js b/lib/Where.js index 37cab9a..513591a 100644 --- a/lib/Where.js +++ b/lib/Where.js @@ -107,6 +107,13 @@ function buildOrGroup(Dialect, where, opts) { Dialect.escapeVal(where.w[k].expr, opts.timezone) ); break; + case "not_like": + query.push( + buildComparisonKey(Dialect, where.t, k) + + " NOT LIKE " + + Dialect.escapeVal(where.w[k].expr, opts.timezone) + ); + break; case "eq": case "ne": case "gt": diff --git a/test/integration/test-where.js b/test/integration/test-where.js index 48a8694..d5c9259 100644 --- a/test/integration/test-where.js +++ b/test/integration/test-where.js @@ -155,6 +155,11 @@ assert.equal( "SELECT * FROM `table1` WHERE `col` LIKE 'abc'" ); +assert.equal( + common.Select().from('table1').where({ col: common.Query.not_like('abc') }).build(), + "SELECT * FROM `table1` WHERE `col` NOT LIKE 'abc'" +); + assert.equal( common.Select().from('table1').where({ col: common.Query.not_in([ 1, 2, 3 ]) }).build(), "SELECT * FROM `table1` WHERE `col` NOT IN (1, 2, 3)"