Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overzealous warning on use of whereNot with "in" or "between" #4780

Merged
merged 1 commit into from Oct 31, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -1050,6 +1050,36 @@ describe('QueryBuilder', () => {
}
});

it('where not should not throw warning when used with "in" or "between" as equality', function () {
testquery(
clientsWithCustomLoggerForTestWarnings.pg
OlivierCavadenti marked this conversation as resolved.
Show resolved Hide resolved
.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