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

feat: query builder negating with "NotBrackets" for complex expressions #8476

Merged
merged 1 commit into from Jan 15, 2022
Merged

feat: query builder negating with "NotBrackets" for complex expressions #8476

merged 1 commit into from Jan 15, 2022

Conversation

christian-forgacs
Copy link
Contributor

@christian-forgacs christian-forgacs commented Dec 21, 2021

Query builder negating with "NotBrackets" for complex expressions

You can add a negated complex WHERE expression into an existing WHERE using NotBrackets

createQueryBuilder("user")
    .where("user.registered = :registered", { registered: true })
    .andWhere(new NotBrackets(qb => {
        qb.where("user.firstName = :firstName", { firstName: "Timber" })
          .orWhere("user.lastName = :lastName", { lastName: "Saw" })
    }))

Which will produce the following SQL query:

SELECT ... FROM users user WHERE user.registered = true AND NOT((user.firstName = 'Timber' OR user.lastName = 'Saw'))

Closes feature request #4442.

We can't use Not as class because it's already exported in src/find-options/operator/Not.ts.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run lint passes with this change
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

@christian-forgacs christian-forgacs changed the title feat: query builder negating with "Not" for complex expressions feat: query builder negating with "NotBrackets" for complex expressions Dec 21, 2021
@pleerock pleerock merged commit fe7f328 into typeorm:master Jan 15, 2022
@pleerock
Copy link
Member

Thank you for contribution! 🎉

@nalhusail
Copy link

is this released? I can't find it in latest version (v0.2.41)

@christian-forgacs
Copy link
Contributor Author

@nalhusail atm not. @pleerock will it released in 0.3.0?

@christian-forgacs
Copy link
Contributor Author

@nalhusail it is now released with the release 0.2.42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants