mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
add a Brackets example on Where section in select-query-build.md
This commit is contained in:
parent
cd06738911
commit
1be9def5a4
@ -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.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user