Skip to content

Commit 487c04f

Browse files
authored
add SelectBuilder methods ForUpdateNoWait and ForUpdateSkipLocked (#114)
1 parent 732195d commit 487c04f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

builder.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,16 @@ func (b *SelectBuilder) ForUpdate() *SelectBuilder {
453453
return b
454454
}
455455

456+
func (b *SelectBuilder) ForUpdateNoWait() *SelectBuilder {
457+
b.Select.Lock = " FOR UPDATE NOWAIT"
458+
return b
459+
}
460+
461+
func (b *SelectBuilder) ForUpdateSkipLocked() *SelectBuilder {
462+
b.Select.Lock = " FOR UPDATE SKIP LOCKED"
463+
return b
464+
}
465+
456466
// WithSharedLock sets the LOCK IN SHARE MODE tag on the statement
457467
// causing the result rows to be read locked (dependent on the
458468
// specific MySQL storage engine).

builder_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ func TestSelectBuilder(t *testing.T) {
491491
"SELECT DISTINCT * FROM `users`"},
492492
{users.Select("*").ForUpdate(),
493493
"SELECT * FROM `users` FOR UPDATE"},
494+
{users.Select("*").ForUpdateNoWait(),
495+
"SELECT * FROM `users` FOR UPDATE NOWAIT"},
496+
{users.Select("*").ForUpdateSkipLocked(),
497+
"SELECT * FROM `users` FOR UPDATE SKIP LOCKED"},
494498
{users.Select("*").WithSharedLock(),
495499
"SELECT * FROM `users` LOCK IN SHARE MODE"},
496500
{users.Select("*").Comments([]string{"quux", "quuz"}),

0 commit comments

Comments
 (0)