mirror of https://github.com/go-gorm/gorm.git
50 lines
911 B
Go
50 lines
911 B
Go
package clause
|
|
|
|
// SelectInterface select clause interface
|
|
type SelectInterface interface {
|
|
Selects() []Column
|
|
Omits() []Column
|
|
}
|
|
|
|
// Select select attrs when querying, updating, creating
|
|
type Select struct {
|
|
SelectColumns []Column
|
|
OmitColumns []Column
|
|
}
|
|
|
|
func (s Select) Name() string {
|
|
return "SELECT"
|
|
}
|
|
|
|
func (s Select) Selects() []Column {
|
|
return s.SelectColumns
|
|
}
|
|
|
|
func (s Select) Omits() []Column {
|
|
return s.OmitColumns
|
|
}
|
|
|
|
func (s Select) Build(builder Builder) {
|
|
if len(s.SelectColumns) > 0 {
|
|
for idx, column := range s.SelectColumns {
|
|
if idx > 0 {
|
|
builder.WriteByte(',')
|
|
}
|
|
builder.WriteQuoted(column)
|
|
}
|
|
} else {
|
|
builder.WriteByte('*')
|
|
}
|
|
}
|
|
|
|
func (s Select) MergeExpression(expr Expression) {
|
|
if v, ok := expr.(SelectInterface); ok {
|
|
if len(s.SelectColumns) == 0 {
|
|
s.SelectColumns = v.Selects()
|
|
}
|
|
if len(s.OmitColumns) == 0 {
|
|
s.OmitColumns = v.Omits()
|
|
}
|
|
}
|
|
}
|