add a Brackets example on Where section in select-query-build.md

This commit is contained in:
Hoseung Lee 2018-04-25 11:21:49 +00:00
parent cd06738911
commit 1be9def5a4

View File

@ -317,6 +317,22 @@ Which will produce the following SQL query:
SELECT ... FROM users user WHERE user.firstName = 'Timber' OR user.lastName = 'Saw'
```
You can add a complex `WHERE` expression into an existing `WHERE` using `Brackets`
```typescript
createQueryBuilder("user")
.where("user.registered = :registered", { registered: true })
.andWhere(new Brackets(qb => {
qb.where("user.firstName = :firstName", { firstName: "Timber" })
.orWhere("user.lastName = :lastName", { lastName: "Saw" })
```
Which will produce the following SQL query:
```sql
SELECT ... FROM users user WHERE user.registered = true AND (user.firstName = 'Timber' OR user.lastName = 'Saw')
```
You can combine as many `AND` and `OR` expressions as you need.
If you use `.where` more than once you'll override all previous `WHERE` expressions.