Add LOCK statement wiki.
This commit is contained in:
parent
5e0e2f2908
commit
461911889a
3 changed files with 63 additions and 4 deletions
45
wiki/LOCK.md
Normal file
45
wiki/LOCK.md
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
|
||||||
|
LOCK statement obtains a table-level lock, waiting if necessary for any conflicting locks to be released.
|
||||||
|
More about LOCK statement in PostgreSQL: https://www.postgresql.org/docs/11/sql-lock.html
|
||||||
|
|
||||||
|
Following clauses are supported:
|
||||||
|
- IN(mode) - mode specifies which locks this lock conflicts with.
|
||||||
|
Mode can be:
|
||||||
|
- jet.LOCK_ACCESS_SHARE
|
||||||
|
- jet.LOCK_ROW_SHARE
|
||||||
|
- jet.LOCK_ROW_EXCLUSIVE
|
||||||
|
- jet.LOCK_SHARE_UPDATE_EXCLUSIVE
|
||||||
|
- jet.LOCK_SHARE
|
||||||
|
- jet.LOCK_SHARE_ROW_EXCLUSIVE
|
||||||
|
- jet.LOCK_EXCLUSIVE
|
||||||
|
- jet.LOCK_ACCESS_EXCLUSIVE
|
||||||
|
- NOWAIT() - locked table should not wait for any conflicting locks to be released. If the specified lock(s)
|
||||||
|
cannot be acquired immediately without waiting, the transaction is aborted.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
lockStmt := Address.
|
||||||
|
LOCK().
|
||||||
|
IN(jet.LOCK_ACCESS_SHARE).
|
||||||
|
NOWAIT()
|
||||||
|
```
|
||||||
|
|
||||||
|
Debug SQL of above statement:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
LOCK TABLE dvds.address IN ACCESS SHARE MODE NOWAIT;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Execute statement
|
||||||
|
|
||||||
|
To execute update statement and get sql.Result:
|
||||||
|
|
||||||
|
```
|
||||||
|
res, err := lockStmt.Exec(db)
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `ExecContext` to provide context object to execution.
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -123,15 +123,27 @@ SQL:
|
||||||
OFFSET 11
|
OFFSET 11
|
||||||
```
|
```
|
||||||
|
|
||||||
##### 9. FOR clause
|
##### 9. FOR clause
|
||||||
|
|
||||||
|
Lock mode can be:
|
||||||
|
- jet.UPDATE()
|
||||||
|
- jet.NO_KEY_UPDATE()
|
||||||
|
- jet.SHARE()
|
||||||
|
- jet.KEY_SHARE()
|
||||||
|
|
||||||
|
Lock mode has following clauses:
|
||||||
|
- NOWAIT()
|
||||||
|
- SKIP_LOCKED()
|
||||||
|
|
||||||
```
|
```
|
||||||
Go:
|
Go:
|
||||||
.FOR(jet.NO_KEY_UPDATE)
|
.FOR(jet.NO_KEY_UPDATE().SKIP_LOCKED())
|
||||||
|
|
||||||
SQL:
|
SQL:
|
||||||
FOR NO KEY UPDATE
|
FOR NO KEY UPDATE SKIP LOCKED
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Two forms of select statements in Jet
|
### Two forms of select statements in Jet
|
||||||
|
|
||||||
#### 1. Classical select statement
|
#### 1. Classical select statement
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
* [Installation](https://github.com/go-jet/jet/wiki/Installation)
|
* [Installation](https://github.com/go-jet/jet/wiki/Installation)
|
||||||
* [Generator](https://github.com/go-jet/jet/wiki/Generator)
|
* [Generator](https://github.com/go-jet/jet/wiki/Generator)
|
||||||
|
* [Model data](https://github.com/go-jet/jet/wiki/Model-data.md)
|
||||||
* [Writing SQL in Go]()
|
* [Writing SQL in Go]()
|
||||||
* [Expressions](https://github.com/go-jet/jet/wiki/Expressions)
|
* [Expressions](https://github.com/go-jet/jet/wiki/Expressions)
|
||||||
* [Statements](https://github.com/go-jet/jet/wiki/Statements)
|
* [Statements](https://github.com/go-jet/jet/wiki/Statements)
|
||||||
|
|
@ -8,4 +9,5 @@
|
||||||
* [INSERT](https://github.com/go-jet/jet/wiki/INSERT)
|
* [INSERT](https://github.com/go-jet/jet/wiki/INSERT)
|
||||||
* [UPDATE](https://github.com/go-jet/jet/wiki/UPDATE)
|
* [UPDATE](https://github.com/go-jet/jet/wiki/UPDATE)
|
||||||
* [DELETE](https://github.com/go-jet/jet/wiki/DELETE)
|
* [DELETE](https://github.com/go-jet/jet/wiki/DELETE)
|
||||||
* [LOCK](https://github.com/go-jet/jet/wiki/LOCK)
|
* [LOCK](https://github.com/go-jet/jet/wiki/LOCK)
|
||||||
|
* [Execution]()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue