Skip to content

Commit

Permalink
Fix overzealous warning on use of whereNot with "in" or "between" (#4780
Browse files Browse the repository at this point in the history
)
  • Loading branch information
willheslam committed Oct 31, 2021
1 parent b97d49b commit b7d9a5d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/query/querybuilder.js
Expand Up @@ -429,7 +429,7 @@ class Builder extends EventEmitter {

// Adds an `not where` clause to the query.
whereNot(column, ...args) {
if (args.length >= 1) {
if (args.length >= 2) {
if (args[0] === 'in' || args[0] === 'between') {
this.client.logger.warn(
'whereNot is not suitable for "in" and "between" type subqueries. You should use "not in" and "not between" instead.'
Expand Down
30 changes: 30 additions & 0 deletions test/unit/query/builder.js
Expand Up @@ -1084,6 +1084,36 @@ describe('QueryBuilder', () => {
}
});

it('where not should not throw warning when used with "in" or "between" as equality', function () {
testquery(
clientsWithCustomLoggerForTestWarnings.pg
.queryBuilder()
.select('*')
.from('users')
.whereNot('id', 'in'),
{
mysql: "select * from `users` where not `id` = 'in'",
pg: 'select * from "users" where not "id" = \'in\'',
'pg-redshift': 'select * from "users" where not "id" = \'in\'',
mssql: "select * from [users] where not [id] = 'in'",
}
);

testquery(
clientsWithCustomLoggerForTestWarnings.pg
.queryBuilder()
.select('*')
.from('users')
.whereNot('id', 'between'),
{
mysql: "select * from `users` where not `id` = 'between'",
pg: 'select * from "users" where not "id" = \'between\'',
'pg-redshift': 'select * from "users" where not "id" = \'between\'',
mssql: "select * from [users] where not [id] = 'between'",
}
);
});

it('where bool', () => {
testquery(qb().select('*').from('users').where(true), {
mysql: 'select * from `users` where 1 = 1',
Expand Down

0 comments on commit b7d9a5d

Please sign in to comment.