mirror of https://github.com/go-gorm/gorm.git
Making locking parameters more intuitive (#6719)
* Making locking parameters more intuitive * remove dedicated type
This commit is contained in:
parent
2fb4928aa8
commit
b9ebdb13c7
|
@ -1,5 +1,12 @@
|
||||||
package clause
|
package clause
|
||||||
|
|
||||||
|
const (
|
||||||
|
LockingStrengthUpdate = "UPDATE"
|
||||||
|
LockingStrengthShare = "SHARE"
|
||||||
|
LockingOptionsSkipLocked = "SKIP LOCKED"
|
||||||
|
LockingOptionsNoWait = "NOWAIT"
|
||||||
|
)
|
||||||
|
|
||||||
type Locking struct {
|
type Locking struct {
|
||||||
Strength string
|
Strength string
|
||||||
Table Table
|
Table Table
|
||||||
|
|
|
@ -14,17 +14,21 @@ func TestLocking(t *testing.T) {
|
||||||
Vars []interface{}
|
Vars []interface{}
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
[]clause.Interface{clause.Select{}, clause.From{}, clause.Locking{Strength: "UPDATE"}},
|
[]clause.Interface{clause.Select{}, clause.From{}, clause.Locking{Strength: clause.LockingStrengthUpdate}},
|
||||||
"SELECT * FROM `users` FOR UPDATE", nil,
|
"SELECT * FROM `users` FOR UPDATE", nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]clause.Interface{clause.Select{}, clause.From{}, clause.Locking{Strength: "SHARE", Table: clause.Table{Name: clause.CurrentTable}}},
|
[]clause.Interface{clause.Select{}, clause.From{}, clause.Locking{Strength: clause.LockingStrengthShare, Table: clause.Table{Name: clause.CurrentTable}}},
|
||||||
"SELECT * FROM `users` FOR SHARE OF `users`", nil,
|
"SELECT * FROM `users` FOR SHARE OF `users`", nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]clause.Interface{clause.Select{}, clause.From{}, clause.Locking{Strength: "UPDATE"}, clause.Locking{Strength: "UPDATE", Options: "NOWAIT"}},
|
[]clause.Interface{clause.Select{}, clause.From{}, clause.Locking{Strength: clause.LockingStrengthUpdate, Options: clause.LockingOptionsNoWait}},
|
||||||
"SELECT * FROM `users` FOR UPDATE NOWAIT", nil,
|
"SELECT * FROM `users` FOR UPDATE NOWAIT", nil,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
[]clause.Interface{clause.Select{}, clause.From{}, clause.Locking{Strength: clause.LockingStrengthUpdate, Options: clause.LockingOptionsSkipLocked}},
|
||||||
|
"SELECT * FROM `users` FOR UPDATE SKIP LOCKED", nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for idx, result := range results {
|
for idx, result := range results {
|
||||||
|
|
Loading…
Reference in New Issue