forked from mirror/gorm
38 lines
644 B
Go
38 lines
644 B
Go
package clause
|
|
|
|
// Select select attrs when querying, updating, creating
|
|
type Select struct {
|
|
Distinct bool
|
|
Columns []Column
|
|
Expression Expression
|
|
}
|
|
|
|
func (s Select) Name() string {
|
|
return "SELECT"
|
|
}
|
|
|
|
func (s Select) Build(builder Builder) {
|
|
if len(s.Columns) > 0 {
|
|
if s.Distinct {
|
|
builder.WriteString("DISTINCT ")
|
|
}
|
|
|
|
for idx, column := range s.Columns {
|
|
if idx > 0 {
|
|
builder.WriteByte(',')
|
|
}
|
|
builder.WriteQuoted(column)
|
|
}
|
|
} else {
|
|
builder.WriteByte('*')
|
|
}
|
|
}
|
|
|
|
func (s Select) MergeClause(clause *Clause) {
|
|
if s.Expression != nil {
|
|
clause.Expression = s.Expression
|
|
} else {
|
|
clause.Expression = s
|
|
}
|
|
}
|