Skip to content

Commit d8d3c56

Browse files
committed
add a "NOT LIKE" comparator
1 parent f958505 commit d8d3c56

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

lib/Comparators.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ exports.not_between = function (a, b) {
77
exports.like = function (expr) {
88
return createSpecialObject({ expr: expr }, 'like');
99
};
10+
exports.not_like = function (expr) {
11+
return createSpecialObject({ expr: expr }, 'not_like');
12+
};
1013

1114
exports.eq = function (v) {
1215
return createSpecialObject({ val: v }, 'eq');

lib/Where.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ function buildOrGroup(Dialect, where, opts) {
107107
Dialect.escapeVal(where.w[k].expr, opts.timezone)
108108
);
109109
break;
110+
case "not_like":
111+
query.push(
112+
buildComparisonKey(Dialect, where.t, k) +
113+
" NOT LIKE " +
114+
Dialect.escapeVal(where.w[k].expr, opts.timezone)
115+
);
116+
break;
110117
case "eq":
111118
case "ne":
112119
case "gt":

test/integration/test-where.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ assert.equal(
155155
"SELECT * FROM `table1` WHERE `col` LIKE 'abc'"
156156
);
157157

158+
assert.equal(
159+
common.Select().from('table1').where({ col: common.Query.not_like('abc') }).build(),
160+
"SELECT * FROM `table1` WHERE `col` NOT LIKE 'abc'"
161+
);
162+
158163
assert.equal(
159164
common.Select().from('table1').where({ col: common.Query.not_in([ 1, 2, 3 ]) }).build(),
160165
"SELECT * FROM `table1` WHERE `col` NOT IN (1, 2, 3)"

0 commit comments

Comments
 (0)