gorm/clause/locking.go

39 lines
773 B
Go
Raw Normal View History

2020-02-07 18:45:35 +03:00
package clause
const (
LockingStrengthUpdate = "UPDATE"
LockingStrengthShare = "SHARE"
LockingOptionsSkipLocked = "SKIP LOCKED"
LockingOptionsNoWait = "NOWAIT"
)
2020-02-07 18:45:35 +03:00
type Locking struct {
Strength string
Table Table
Options string
}
// Name where clause name
2020-06-06 16:35:28 +03:00
func (locking Locking) Name() string {
2020-02-07 18:45:35 +03:00
return "FOR"
}
// Build build where clause
2020-06-06 16:35:28 +03:00
func (locking Locking) Build(builder Builder) {
builder.WriteString(locking.Strength)
if locking.Table.Name != "" {
builder.WriteString(" OF ")
builder.WriteQuoted(locking.Table)
}
2020-02-07 18:45:35 +03:00
2020-06-06 16:35:28 +03:00
if locking.Options != "" {
builder.WriteByte(' ')
builder.WriteString(locking.Options)
2020-02-07 18:45:35 +03:00
}
}
// MergeClause merge order by clauses
2020-06-06 16:35:28 +03:00
func (locking Locking) MergeClause(clause *Clause) {
clause.Expression = locking
2020-02-07 18:45:35 +03:00
}