docs: add Lock tables in Set Locking (#10921)

This commit is contained in:
YoungKi Lyu 2025-01-06 05:42:55 +09:00 committed by GitHub
parent 2844cbc7c8
commit c1ff5d3fa5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -983,6 +983,20 @@ const users = await dataSource
Optimistic locking works in conjunction with both `@Version` and `@UpdatedDate` decorators.
#### Lock tables
You can also lock tables using the following method:
```typescript
const users = await dataSource
.getRepository(Post)
.createQueryBuilder("post")
.leftJoin("post.author", "user")
.setLock("pessimistic_write", undefined, ["post"])
.getMany()
```
If the Lock Tables argument is provided, only the table that is locked in the FOR UPDATE OF clause is specified.
### setOnLocked
Allows you to control what happens when a row is locked. By default, the database will wait for the lock.
You can control that behavior by using `setOnLocked`