gorm/clause/locking.go

49 lines
858 B
Go
Raw Normal View History

2020-02-07 18:45:35 +03:00
package clause
type For struct {
Lockings []Locking
}
type Locking struct {
Strength string
Table Table
Options string
}
// Name where clause name
func (f For) Name() string {
return "FOR"
}
// Build build where clause
func (f For) Build(builder Builder) {
for idx, locking := range f.Lockings {
if idx > 0 {
builder.WriteByte(' ')
}
2020-03-09 12:07:00 +03:00
builder.WriteString("FOR ")
builder.WriteString(locking.Strength)
2020-02-07 18:45:35 +03:00
if locking.Table.Name != "" {
2020-03-09 12:07:00 +03:00
builder.WriteString(" OF ")
2020-02-07 18:45:35 +03:00
builder.WriteQuoted(locking.Table)
}
if locking.Options != "" {
builder.WriteByte(' ')
2020-03-09 12:07:00 +03:00
builder.WriteString(locking.Options)
2020-02-07 18:45:35 +03:00
}
}
}
// MergeClause merge order by clauses
func (f For) MergeClause(clause *Clause) {
clause.Name = ""
if v, ok := clause.Expression.(For); ok {
f.Lockings = append(v.Lockings, f.Lockings...)
}
clause.Expression = f
}