Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/Comparators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
7 changes: 7 additions & 0 deletions lib/Where.js
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
5 changes: 5 additions & 0 deletions test/integration/test-where.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down