3

I'd like to achieve something like this:

WHERE ( statement1 OR statement2 ) AND statement3

How can I achieve this with query builder?

I have tried this before:

Entity.createQueryBuilder()
  .where(statement1)
  .orWhere(statement2)
  .andWhere(statement3);

But it produces following query:

WHERE statement1 OR statement2 AND statement3

2 Answers 2

4

I have figured it out myself, basically you should use Brackets from typeorm:

Entity.createQueryBuilder()
  .where(
    new Brackets((qb1) => {
      qb1.where(statement1).orWhere(statement2);
    })
  )
  .andWhere(statement3);
Sign up to request clarification or add additional context in comments.

Comments

1

I believe that if @sp Kruten answer doesn't suit you, you'll find something here.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.