gorm/clause/select.go

33 lines
568 B
Go
Raw Normal View History

2020-02-02 09:40:44 +03:00
package clause
// Select select attrs when querying, updating, creating
type Select struct {
2020-02-16 08:45:27 +03:00
Columns []Column
Expression Expression
2020-02-02 09:40:44 +03:00
}
2020-02-04 03:56:15 +03:00
func (s Select) Name() string {
return "SELECT"
2020-02-02 09:40:44 +03:00
}
func (s Select) Build(builder Builder) {
2020-02-07 18:45:35 +03:00
if len(s.Columns) > 0 {
for idx, column := range s.Columns {
2020-02-02 09:40:44 +03:00
if idx > 0 {
builder.WriteByte(',')
}
builder.WriteQuoted(column)
}
} else {
builder.WriteByte('*')
}
}
2020-02-07 18:45:35 +03:00
func (s Select) MergeClause(clause *Clause) {
2020-02-16 08:45:27 +03:00
if s.Expression != nil {
clause.Expression = s.Expression
} else {
clause.Expression = s
2020-02-02 09:40:44 +03:00
}
}